From 4e89257a527328e37523c209b34ee40b828262c6 Mon Sep 17 00:00:00 2001 From: Mikhail Nasyrov Date: Thu, 30 May 2024 01:37:42 +0300 Subject: [PATCH] refactor: Removed explicit support for Deno --- .github/workflows/main.yml | 18 - README.md | 8 - mod.ts | 2 - package.json | 1 - packages/ditox/README.md | 8 - packages/ditox/lib-deno/index.d.ts | 503 ------------------------- packages/ditox/lib-deno/index.js | 450 ---------------------- packages/ditox/lib-deno/index.js.map | 1 - packages/ditox/package.json | 1 - packages/ditox/rollup.config.mjs | 15 +- packages/ditox/test-deno/deno.test.ts | 213 ----------- packages/ditox/test-deno/tsconfig.json | 13 - packages/ditox/tsconfig.json | 3 +- 13 files changed, 2 insertions(+), 1234 deletions(-) delete mode 100644 mod.ts delete mode 100644 packages/ditox/lib-deno/index.d.ts delete mode 100644 packages/ditox/lib-deno/index.js delete mode 100644 packages/ditox/lib-deno/index.js.map delete mode 100644 packages/ditox/test-deno/deno.test.ts delete mode 100644 packages/ditox/test-deno/tsconfig.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4bcfff3..58eeea1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,21 +22,3 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} - name: Build run: npm run build - - test-deno: - needs: test - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: '16' - - uses: denolib/setup-deno@v2 - with: - deno-version: v1.x - - name: Install dependencies - run: npm ci - - name: Build - run: npm run build - - name: Deno Test - run: npm run test-deno diff --git a/README.md b/README.md index 6972ac3..b82abe0 100644 --- a/README.md +++ b/README.md @@ -65,14 +65,6 @@ Packages can be used as [UMD](https://github.com/umdjs/umd) modules. Use ``` -`ditox` package is available for Deno environment: - -```typescript -import {createContainer} from 'https://deno.land/x/ditox/mod.ts'; - -const container = createContainer(); -``` - ### Basic concepts - **Token** specifies a future injection of an "internal" implementation with a diff --git a/mod.ts b/mod.ts deleted file mode 100644 index e67da49..0000000 --- a/mod.ts +++ /dev/null @@ -1,2 +0,0 @@ -// @deno-types="./packages/ditox/lib-deno/index.d.ts" -export * from './packages/ditox/lib-deno/index.js'; diff --git a/package.json b/package.json index 9ee17e8..d18c7af 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "lint:eslint": "eslint \"packages/*/{src,test*}/**\"", "lint:tsc": "tsc --noEmit --jsx react", "test": "jest", - "test-deno": "npm run -w ditox test-deno", "build": "npm run -ws build", "build-docs": "npm run build && typedoc", "pack": "npm run build && mkdir -p dist && npm exec -ws -c 'npm pack --pack-destination ../../dist'", diff --git a/packages/ditox/README.md b/packages/ditox/README.md index ef30e01..810a80a 100644 --- a/packages/ditox/README.md +++ b/packages/ditox/README.md @@ -31,14 +31,6 @@ The package can be used as [UMD](https://github.com/umdjs/umd) module. Use ``` -Using in Deno environment: - -```ts -import {createContainer} from 'https://deno.land/x/ditox/mod.ts'; - -const container = createContainer(); -``` - ## General description DI pattern in general allows to declare and construct a code graph of an diff --git a/packages/ditox/lib-deno/index.d.ts b/packages/ditox/lib-deno/index.d.ts deleted file mode 100644 index 6b9bbd3..0000000 --- a/packages/ditox/lib-deno/index.d.ts +++ /dev/null @@ -1,503 +0,0 @@ -/** - * @ignore - * Binding token for mandatory value - */ -type RequiredToken = { - symbol: symbol; - type?: T; - isOptional?: false; -}; -/** - * @ignore - * Binding token for optional value - */ -type OptionalToken = { - symbol: symbol; - type?: T; - isOptional: true; - optionalValue: T; -}; -/** - * Binding token - */ -type Token = RequiredToken | OptionalToken; -/** - * Token options - */ -type TokenOptions = - | { - /** - * Key for token's symbol. It allows to create shareable tokens. - */ - key: string; - /** @ignore */ - description?: undefined; - } - | { - /** Description for better error messages */ - description?: string; - /** @ignore */ - key?: undefined; - }; -/** - * Creates a new binding token. - * @param description - Token description for better error messages. - */ -declare function token(description?: string): Token; -/** - * Creates a new binding token. - * @param options - Token description for better error messages. - */ declare function token(options?: TokenOptions): Token; -/** - * Decorate a token with an optional value. - * This value is be used as default value in case a container does not have registered token. - * @param token - Existed token. - * @param optionalValue - Default value for the resolver. - */ -declare function optional( - token: Token, - optionalValue: T, -): OptionalToken; -declare function optional(token: Token): OptionalToken; - -/** - * ResolverError is thrown by the resolver when a token is not found in a container. - */ -declare class ResolverError extends Error { - constructor(message: string); -} -/** - * @see https://github.com/mnasyrov/ditox#factory-lifetimes - */ -type FactoryScope = 'scoped' | 'singleton' | 'transient'; -/** - * Options for factory binding. - * - * `scope` types: - * - `singleton` - **This is the default**. The value is created and cached by the container which registered the factory. - * - `scoped` - The value is created and cached by the container which starts resolving. - * - `transient` - The value is created every time it is resolved. - * - * `scoped` and `singleton` scopes can have `onRemoved` callback. It is called when a token is removed from the container. - */ -type FactoryOptions = - | { - scope?: 'scoped' | 'singleton'; - onRemoved?: (value: T) => void; - } - | { - scope: 'transient'; - }; -/** - * Dependency container. - */ -type Container = { - /** - * Binds a value for the token - */ - bindValue(token: Token, value: T): void; - /** - * Binds a factory for the token. - */ - bindFactory( - token: Token, - factory: (container: Container) => T, - options?: FactoryOptions, - ): void; - /** - * Checks if the token is registered in the container hierarchy. - */ - hasToken(token: Token): boolean; - /** - * Returns a resolved value by the token, or returns `undefined` in case the token is not found. - */ - get(token: Token): T | undefined; - /** - * Returns a resolved value by the token, or throws `ResolverError` in case the token is not found. - */ - resolve(token: Token): T; - /** - * Removes a binding for the token. - */ - remove(token: Token): void; - /** - * Removes all bindings in the container. - */ - removeAll(): void; -}; -/** - * Creates a new dependency container. - * - * Container can have an optional parent to chain token resolution. The parent is used in case the current container does not have a registered token. - * - * @param parentContainer - Optional parent container. - */ -declare function createContainer(parentContainer?: Container): Container; - -type ValuesProps = { - [key: string]: unknown; -}; -type TokenProps = { - [K in keyof Props]: Token; -}; -/** - * Checks if a value is the token - */ -declare function isToken(value: unknown): value is Token; -/** - * Rebinds the array by the token with added new value. - * @param container - Dependency container. - * @param token - Token for an array of values. - * @param value - New value which is added to the end of the array. - */ -declare function bindMultiValue( - container: Container, - token: Token>, - value: T, -): void; -/** - * Tries to resolve a value by the provided token. - * - * If an argument is an object which has tokens as its properties, - * then returns an object containing resolved values as properties. - - * If a token is not found, then `undefined` value is used. - * - * @example - * ```ts - * const value = tryResolveValue(container, tokenA); - * console.log(value); // 1 - * - * const props = tryResolveValue(container, {a: tokenA, b: tokenB}); - * console.log(props); // {a: 1, b: 2} - * ``` - */ -declare function tryResolveValue< - Tokens extends - | Token - | { - [key: string]: Token; - }, - Values extends Tokens extends Token - ? V | undefined - : Tokens extends TokenProps - ? Partial - : never, ->(container: Container, token: Tokens): Values; -/** - * Returns an array of resolved values or objects with resolved values. - * - * If an item of the array is an object which has tokens as its properties, - * then returns an object containing resolved values as properties. - - * If a token is not found, then `undefined` value is used. - * - * @example - * ```ts - * const items1 = tryResolveValues(container, tokenA); - * console.log(items1); // [1] - * - * const items2 = tryResolveValues(container, tokenA, {a: tokenA, b: tokenB}); - * console.log(items2); // [1, {a: 1, b: 2}] - * ``` - */ -declare function tryResolveValues< - Tokens extends ( - | Token - | { - [key: string]: Token; - } - )[], - Values extends { - [K in keyof Tokens]: Tokens[K] extends Token - ? V | undefined - : Tokens[K] extends TokenProps - ? Partial - : never; - }, ->(container: Container, ...tokens: Tokens): Values; -/** - * Resolves a value by the provided token. - * - * If an argument is an object which has tokens as its properties, - * then returns an object containing resolved values as properties. - - * If a value is not found by the token, then `ResolverError` is thrown. - * - * @example - * ```ts - * const value = resolveValue(container, tokenA); - * console.log(value); // 1 - * - * const props = resolveValue(container, {a: tokenA, b: tokenB}); - * console.log(props); // {a: 1, b: 2} - * ``` - */ -declare function resolveValue< - Tokens extends - | Token - | { - [key: string]: Token; - }, - Values extends Tokens extends Token - ? V - : Tokens extends TokenProps - ? Props - : never, ->(container: Container, token: Tokens): Values; -/** - * Returns an array of resolved values or objects with resolved values. - * - * If an item of the array is an object which has tokens as its properties, - * then returns an object containing resolved values as properties. - - * If a token is not found, then `ResolverError` is thrown. - * - * @example - * ```ts - * const items1 = resolveValues(container, tokenA); - * console.log(items1); // [1] - * - * const items2 = resolveValues(container, tokenA, {a: tokenA, b: tokenB}); - * console.log(items2); // [1, {a: 1, b: 2}] - * ``` - */ -declare function resolveValues< - Tokens extends ( - | Token - | { - [key: string]: Token; - } - )[], - Values extends { - [K in keyof Tokens]: Tokens[K] extends Token - ? V - : Tokens[K] extends TokenProps - ? Props - : never; - }, ->(container: Container, ...tokens: Tokens): Values; -/** - * Decorates a factory by passing resolved values as factory arguments. - * - * If an argument is an object which has tokens as its properties, - * then returns an object containing resolved values as properties. - * - * @param factory - A factory. - * @param tokens - Tokens which correspond to factory arguments. - * - * @return Decorated factory which takes a dependency container as a single argument. - */ -declare function injectable< - Tokens extends ( - | Token - | { - [key: string]: Token; - } - )[], - Values extends { - [K in keyof Tokens]: Tokens[K] extends Token - ? V - : Tokens[K] extends TokenProps - ? Props - : never; - }, - Result, ->( - this: unknown, - factory: (...params: Values) => Result, - ...tokens: Tokens -): (container: Container) => Result; -/** - * Decorates a class by passing resolved values as arguments to its constructor. - * - * If an argument is an object which has tokens as its properties, - * then returns an object containing resolved values as properties. - * - * @param constructor - Constructor of a class - * @param tokens - Tokens which correspond to constructor arguments - * - * @return A factory function which takes a dependency container as a single argument - * and returns a new created class. - */ -declare function injectableClass< - Tokens extends ( - | Token - | { - [key: string]: Token; - } - )[], - Values extends { - [K in keyof Tokens]: Tokens[K] extends Token - ? V - : Tokens[K] extends TokenProps - ? Props - : never; - }, - Result, ->( - this: unknown, - constructor: new (...params: Values) => Result, - ...tokens: Tokens -): (container: Container) => Result; - -type AnyObject = Record; -type EmptyObject = Record; -type ModuleController = { - /** Dispose the module and clean its resources */ - destroy?: () => void; -}; -/** - * Dependency module - * - * @example - * ```ts - * type LoggerModule = Module<{ - * logger: Logger; - * }>; - * ``` - */ -type Module = ModuleController & - ModuleProps; -type GetModuleProps = T extends Module ? Props : never; -/** - * Description how to bind the module in declarative way. - * - * @example - * ```ts - * const LOGGER_MODULE: ModuleDeclaration = { - * token: LOGGER_MODULE_TOKEN, - * factory: (container) => { - * const transport = container.resolve(TRANSPORT_TOKEN).open(); - * return { - * logger: { log: (message) => transport.write(message) }, - * destroy: () => transport.close(), - * } - * }, - * exports: { - * logger: LOGGER_TOKEN, - * }, - * }; - * ``` - */ -type ModuleDeclaration> = { - /** Token for the module */ - token: Token; - /** Modules for binding */ - imports?: ReadonlyArray; - /** Factory of the module */ - factory: (container: Container) => T; - /** Dictionary of module properties which are bound to tokens. */ - exports?: { - [K in keyof GetModuleProps]?: Token[K]>; - }; - /** Callback could be used to prepare an environment. It is called before binding the module. */ - beforeBinding?: (container: Container) => void; - /** Callback could be used to export complex dependencies from the module. It is called after binding the module. */ - afterBinding?: (container: Container) => void; -}; -/** - * Options for module binding. - * - * `scope` types: - * - `singleton` - **This is the default**. The module is created and cached by the container which registered the factory. - * - `scoped` - The module is created and cached by the container which starts resolving. - */ -type BindModuleOptions = { - scope?: 'scoped' | 'singleton'; -}; -type ModuleBindingEntry = - | ModuleDeclaration - | { - module: ModuleDeclaration; - options: BindModuleOptions; - }; -/** - * Binds the dependency module to the container - * @param container - Dependency container. - * @param moduleDeclaration - Declaration of the dependency module. - * @param options - Options for module binding. - * - * @example - * ```ts - * bindModule(container, LOGGER_MODULE); - * ``` - */ -declare function bindModule>( - container: Container, - moduleDeclaration: ModuleDeclaration, - options?: BindModuleOptions, -): void; -/** - * Binds dependency modules to the container - * - * @param container - Dependency container for binding - * @param modules - Array of module binding entries: module declaration or `{module: ModuleDeclaration, options: BindModuleOptions}` objects. - */ -declare function bindModules( - container: Container, - modules: ReadonlyArray, -): void; -/** - * Declares a module binding - * - * @param declaration - a module declaration - * @param declaration.token - optional field - * - * @example - * ```ts - * const LOGGER_MODULE = declareModule({ - * factory: (container) => { - * const transport = container.resolve(TRANSPORT_TOKEN).open(); - * return { - * logger: { log: (message) => transport.write(message) }, - * destroy: () => transport.close(), - * } - * }, - * exports: { - * logger: LOGGER_TOKEN, - * }, - * }); - * ``` - */ -declare function declareModule>( - declaration: Omit, 'token'> & - Partial, 'token'>>, -): ModuleDeclaration; -/** - * Declares bindings of several modules - * - * @param modules - module declaration entries - */ -declare function declareModuleBindings( - modules: ReadonlyArray, -): ModuleDeclaration; - -export { - BindModuleOptions, - Container, - FactoryOptions, - FactoryScope, - Module, - ModuleBindingEntry, - ModuleDeclaration, - OptionalToken, - RequiredToken, - ResolverError, - Token, - bindModule, - bindModules, - bindMultiValue, - createContainer, - declareModule, - declareModuleBindings, - injectable, - injectableClass, - isToken, - optional, - resolveValue, - resolveValues, - token, - tryResolveValue, - tryResolveValues, -}; diff --git a/packages/ditox/lib-deno/index.js b/packages/ditox/lib-deno/index.js deleted file mode 100644 index e0e3665..0000000 --- a/packages/ditox/lib-deno/index.js +++ /dev/null @@ -1,450 +0,0 @@ -function token(options) { - const normalized = typeof options === 'string' ? { description: options } : options; - const symbol = (normalized === null || normalized === void 0 ? void 0 : normalized.key) - ? Symbol.for(normalized.key) - : Symbol(normalized === null || normalized === void 0 ? void 0 : normalized.description); - return { symbol }; -} -function optional(token, optionalValue) { - return { - symbol: token.symbol, - isOptional: true, - optionalValue, - }; -} - -/** - * ResolverError is thrown by the resolver when a token is not found in a container. - */ -class ResolverError extends Error { - constructor(message) { - super(message); - Object.setPrototypeOf(this, new.target.prototype); - this.name = 'ResolverError'; - } -} -/** @internal */ -const CONTAINER = token('ditox.Container'); -/** @internal */ -const PARENT_CONTAINER = token('ditox.ParentContainer'); -/** @internal */ -const RESOLVER = token('ditox.Resolver'); -/** @internal */ -const NOT_FOUND = Symbol(); -/** @internal */ -const FAKE_FACTORY = () => { - throw new Error('FAKE_FACTORY'); -}; -/** @internal */ -const DEFAULT_SCOPE = 'singleton'; -/** @internal */ -const FACTORIES_MAP = token('ditox.FactoriesMap'); -/** @internal */ -function getScope(options) { - var _a; - return (_a = options === null || options === void 0 ? void 0 : options.scope) !== null && _a !== void 0 ? _a : DEFAULT_SCOPE; -} -/** @internal */ -function getOnRemoved(options) { - return options.scope === undefined || - options.scope === 'scoped' || - options.scope === 'singleton' - ? options.onRemoved - : undefined; -} -/** @internal */ -function isInternalToken(token) { - return (token.symbol === CONTAINER.symbol || - token.symbol === PARENT_CONTAINER.symbol || - token.symbol === RESOLVER.symbol); -} -/** - * Creates a new dependency container. - * - * Container can have an optional parent to chain token resolution. The parent is used in case the current container does not have a registered token. - * - * @param parentContainer - Optional parent container. - */ -function createContainer(parentContainer) { - const values = new Map(); - const factories = new Map(); - const container = { - bindValue(token, value) { - if (isInternalToken(token)) { - return; - } - values.set(token.symbol, value); - }, - bindFactory(token, factory, options) { - if (isInternalToken(token)) { - return; - } - factories.set(token.symbol, { factory, options }); - }, - remove(token) { - var _a; - if (isInternalToken(token)) { - return; - } - const options = (_a = factories.get(token.symbol)) === null || _a === void 0 ? void 0 : _a.options; - if (options) { - executeOnRemoved(token.symbol, options); - } - values.delete(token.symbol); - factories.delete(token.symbol); - }, - removeAll() { - factories.forEach((context, tokenSymbol) => { - if (context.options) { - executeOnRemoved(tokenSymbol, context.options); - } - }); - values.clear(); - factories.clear(); - bindInternalTokens(); - }, - hasToken(token) { - var _a; - return (values.has(token.symbol) || - factories.has(token.symbol) || - ((_a = parentContainer === null || parentContainer === void 0 ? void 0 : parentContainer.hasToken(token)) !== null && _a !== void 0 ? _a : false)); - }, - get(token) { - const value = resolver(token, container); - if (value !== NOT_FOUND) { - return value; - } - if (token.isOptional) { - return token.optionalValue; - } - return undefined; - }, - resolve(token) { - var _a; - const value = resolver(token, container); - if (value !== NOT_FOUND) { - return value; - } - if (token.isOptional) { - return token.optionalValue; - } - throw new ResolverError(`Token "${(_a = token.symbol.description) !== null && _a !== void 0 ? _a : ''}" is not provided`); - }, - }; - function resolver(token, origin) { - const value = values.get(token.symbol); - const hasValue = value !== undefined || values.has(token.symbol); - if (hasValue && origin === container) { - return value; - } - const factoryContext = factories.get(token.symbol); - if (factoryContext && factoryContext.factory !== FAKE_FACTORY) { - const scope = getScope(factoryContext.options); - switch (scope) { - case 'singleton': { - if (hasValue) { - return value; - } - else if (parentContainer === null || parentContainer === void 0 ? void 0 : parentContainer.hasToken(token)) { - break; - } - else { - // Cache the value in the same container where the factory is registered. - const value = factoryContext.factory(container); - container.bindValue(token, value); - return value; - } - } - case 'scoped': { - // Create a value within the origin container and cache it. - const value = factoryContext.factory(origin); - origin.bindValue(token, value); - if (origin !== container) { - // Bind a fake factory with actual options to make onRemoved() works. - origin.bindFactory(token, FAKE_FACTORY, factoryContext.options); - } - return value; - } - case 'transient': { - // Create a value within the origin container and don't cache it. - return factoryContext.factory(origin); - } - } - } - if (hasValue) { - return value; - } - const parentResolver = parentContainer === null || parentContainer === void 0 ? void 0 : parentContainer.get(RESOLVER); - if (parentResolver) { - return parentResolver(token, origin); - } - return NOT_FOUND; - } - function executeOnRemoved(tokenSymbol, options) { - const onRemoved = getOnRemoved(options); - if (onRemoved) { - const value = values.get(tokenSymbol); - if (value !== undefined || values.has(tokenSymbol)) { - onRemoved(value); - } - } - } - function bindInternalTokens() { - values.set(CONTAINER.symbol, container); - values.set(RESOLVER.symbol, resolver); - values.set(FACTORIES_MAP.symbol, factories); - if (parentContainer) { - values.set(PARENT_CONTAINER.symbol, parentContainer); - } - } - bindInternalTokens(); - return container; -} - -/** - * Checks if a value is the token - */ -function isToken(value) { - return (value !== undefined && - value !== null && - typeof value === 'object' && - 'symbol' in value && - typeof value.symbol === 'symbol'); -} -/** - * Rebinds the array by the token with added new value. - * @param container - Dependency container. - * @param token - Token for an array of values. - * @param value - New value which is added to the end of the array. - */ -function bindMultiValue(container, token, value) { - var _a; - const prevValues = (_a = container.get(token)) !== null && _a !== void 0 ? _a : []; - const nextValues = [...prevValues, value]; - container.bindValue(token, nextValues); -} -/** - * Tries to resolve a value by the provided token. - * - * If an argument is an object which has tokens as its properties, - * then returns an object containing resolved values as properties. - - * If a token is not found, then `undefined` value is used. - * - * @example - * ```ts - * const value = tryResolveValue(container, tokenA); - * console.log(value); // 1 - * - * const props = tryResolveValue(container, {a: tokenA, b: tokenB}); - * console.log(props); // {a: 1, b: 2} - * ``` - */ -function tryResolveValue(container, token) { - if (isToken(token)) { - return container.get(token); - } - const obj = {}; - Object.keys(token).forEach((key) => (obj[key] = container.get(token[key]))); - return obj; -} -/** - * Returns an array of resolved values or objects with resolved values. - * - * If an item of the array is an object which has tokens as its properties, - * then returns an object containing resolved values as properties. - - * If a token is not found, then `undefined` value is used. - * - * @example - * ```ts - * const items1 = tryResolveValues(container, tokenA); - * console.log(items1); // [1] - * - * const items2 = tryResolveValues(container, tokenA, {a: tokenA, b: tokenB}); - * console.log(items2); // [1, {a: 1, b: 2}] - * ``` - */ -function tryResolveValues(container, ...tokens) { - return tokens.map((item) => tryResolveValue(container, item)); -} -/** - * Resolves a value by the provided token. - * - * If an argument is an object which has tokens as its properties, - * then returns an object containing resolved values as properties. - - * If a value is not found by the token, then `ResolverError` is thrown. - * - * @example - * ```ts - * const value = resolveValue(container, tokenA); - * console.log(value); // 1 - * - * const props = resolveValue(container, {a: tokenA, b: tokenB}); - * console.log(props); // {a: 1, b: 2} - * ``` - */ -function resolveValue(container, token) { - if (isToken(token)) { - return container.resolve(token); - } - const obj = {}; - Object.keys(token).forEach((key) => (obj[key] = container.resolve(token[key]))); - return obj; -} -/** - * Returns an array of resolved values or objects with resolved values. - * - * If an item of the array is an object which has tokens as its properties, - * then returns an object containing resolved values as properties. - - * If a token is not found, then `ResolverError` is thrown. - * - * @example - * ```ts - * const items1 = resolveValues(container, tokenA); - * console.log(items1); // [1] - * - * const items2 = resolveValues(container, tokenA, {a: tokenA, b: tokenB}); - * console.log(items2); // [1, {a: 1, b: 2}] - * ``` - */ -function resolveValues(container, ...tokens) { - return tokens.map((item) => resolveValue(container, item)); -} -/** - * Decorates a factory by passing resolved values as factory arguments. - * - * If an argument is an object which has tokens as its properties, - * then returns an object containing resolved values as properties. - * - * @param factory - A factory. - * @param tokens - Tokens which correspond to factory arguments. - * - * @return Decorated factory which takes a dependency container as a single argument. - */ -function injectable(factory, ...tokens) { - return (container) => { - const values = resolveValues(container, ...tokens); - return factory.apply(this, values); - }; -} -/** - * Decorates a class by passing resolved values as arguments to its constructor. - * - * If an argument is an object which has tokens as its properties, - * then returns an object containing resolved values as properties. - * - * @param constructor - Constructor of a class - * @param tokens - Tokens which correspond to constructor arguments - * - * @return A factory function which takes a dependency container as a single argument - * and returns a new created class. - */ -function injectableClass(constructor, ...tokens) { - return injectable((...values) => new constructor(...values), ...tokens); -} - -/** - * Binds the dependency module to the container - * @param container - Dependency container. - * @param moduleDeclaration - Declaration of the dependency module. - * @param options - Options for module binding. - * - * @example - * ```ts - * bindModule(container, LOGGER_MODULE); - * ``` - */ -function bindModule(container, moduleDeclaration, options) { - const { token, imports, factory, beforeBinding, afterBinding } = moduleDeclaration; - const exports = moduleDeclaration.exports; - const scope = options === null || options === void 0 ? void 0 : options.scope; - if (beforeBinding) { - beforeBinding(container); - } - if (imports) { - bindModules(container, imports); - } - const exportedValueTokens = new Set(); - if (exports) { - const keys = Object.keys(exports); - keys.forEach((valueKey) => { - const valueToken = exports[valueKey]; - if (valueToken) { - exportedValueTokens.add(valueToken); - container.bindFactory(valueToken, injectable((module) => module[valueKey], token), { scope }); - } - }); - } - container.bindFactory(token, factory, { - scope, - onRemoved: (module) => { - if (module.destroy) { - module.destroy(); - } - exportedValueTokens.forEach((valueToken) => container.remove(valueToken)); - exportedValueTokens.clear(); - }, - }); - if (afterBinding) { - afterBinding(container); - } -} -/** - * Binds dependency modules to the container - * - * @param container - Dependency container for binding - * @param modules - Array of module binding entries: module declaration or `{module: ModuleDeclaration, options: BindModuleOptions}` objects. - */ -function bindModules(container, modules) { - modules.forEach((entry) => { - if ('module' in entry) { - bindModule(container, entry.module, entry.options); - } - else { - bindModule(container, entry); - } - }); -} -/** - * Declares a module binding - * - * @param declaration - a module declaration - * @param declaration.token - optional field - * - * @example - * ```ts - * const LOGGER_MODULE = declareModule({ - * factory: (container) => { - * const transport = container.resolve(TRANSPORT_TOKEN).open(); - * return { - * logger: { log: (message) => transport.write(message) }, - * destroy: () => transport.close(), - * } - * }, - * exports: { - * logger: LOGGER_TOKEN, - * }, - * }); - * ``` - */ -function declareModule(declaration) { - var _a; - return { ...declaration, token: (_a = declaration.token) !== null && _a !== void 0 ? _a : token() }; -} -/** - * Declares bindings of several modules - * - * @param modules - module declaration entries - */ -function declareModuleBindings(modules) { - return declareModule({ - factory: () => ({}), - imports: modules, - }); -} - -export { ResolverError, bindModule, bindModules, bindMultiValue, createContainer, declareModule, declareModuleBindings, injectable, injectableClass, isToken, optional, resolveValue, resolveValues, token, tryResolveValue, tryResolveValues }; -//# sourceMappingURL=index.js.map diff --git a/packages/ditox/lib-deno/index.js.map b/packages/ditox/lib-deno/index.js.map deleted file mode 100644 index 7651e18..0000000 --- a/packages/ditox/lib-deno/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../src/tokens.ts","../src/container.ts","../src/utils.ts","../src/modules.ts"],"sourcesContent":[null,null,null,null],"names":[],"mappings":"AAwDM,SAAU,KAAK,CAAI,OAA+B,EAAA;AACtD,IAAA,MAAM,UAAU,GACd,OAAO,OAAO,KAAK,QAAQ,GAAG,EAAC,WAAW,EAAE,OAAO,EAAC,GAAG,OAAO,CAAC;IAEjE,MAAM,MAAM,GAAW,CAAA,UAAU,aAAV,UAAU,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAV,UAAU,CAAE,GAAG;UAClC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;UAC1B,MAAM,CAAC,UAAU,KAAA,IAAA,IAAV,UAAU,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAV,UAAU,CAAE,WAAW,CAAC,CAAC;IAEpC,OAAO,EAAC,MAAM,EAAC,CAAC;AAClB,CAAC;AAae,SAAA,QAAQ,CACtB,KAAe,EACf,aAAiB,EAAA;IAEjB,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,MAAM;AACpB,QAAA,UAAU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;;;;;;;;;;;;;;;;;;AAqBG;AACG,SAAU,aAAa,CAC3B,WAC8C,EAAA;;AAE9C,IAAA,OAAO,EAAC,GAAG,WAAW,EAAE,KAAK,EAAE,CAAA,EAAA,GAAA,WAAW,CAAC,KAAK,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAI,KAAK,EAAE,EAAC,CAAC;AAC/D,CAAC;AAED;;;;AAIG;AACG,SAAU,qBAAqB,CACnC,OAA0C,EAAA;AAE1C,IAAA,OAAO,aAAa,CAAC;AACnB,QAAA,OAAO,EAAE,OAAO,EAAE,CAAC;AACnB,QAAA,OAAO,EAAE,OAAO;AACjB,KAAA,CAAC,CAAC;AACL;;;;"} \ No newline at end of file diff --git a/packages/ditox/package.json b/packages/ditox/package.json index fa55f24..e1d4d7b 100644 --- a/packages/ditox/package.json +++ b/packages/ditox/package.json @@ -45,7 +45,6 @@ ], "scripts": { "clean": "shx rm -rf dist lib", - "test-deno": "npm run build:rollup && deno test test-deno", "build": "npm run build:cjs && npm run build:esm && npm run build:rollup", "build:cjs": "tsc -p tsconfig.build.json --outDir dist/cjs --module commonjs", "build:esm": "tsc -p tsconfig.build.json --outDir dist/esm --module es2015", diff --git a/packages/ditox/rollup.config.mjs b/packages/ditox/rollup.config.mjs index 1afc607..294551d 100644 --- a/packages/ditox/rollup.config.mjs +++ b/packages/ditox/rollup.config.mjs @@ -8,22 +8,9 @@ const UMD_LIB_NAME = 'Ditox'; export default [ { input: 'src/index.ts', - output: [ - {file: 'lib-deno/index.d.ts'}, - {file: 'dist/browser/index.d.ts'}, - {file: 'dist/umd/index.d.ts'}, - ], + output: [{file: 'dist/browser/index.d.ts'}, {file: 'dist/umd/index.d.ts'}], plugins: [dts()], }, - { - input: 'src/index.ts', - output: [{file: 'lib-deno/index.js', format: 'es', sourcemap: true}], - plugins: [ - typescript({ - declaration: false, - }), - ], - }, { input: 'src/index.ts', output: [ diff --git a/packages/ditox/test-deno/deno.test.ts b/packages/ditox/test-deno/deno.test.ts deleted file mode 100644 index ffa167f..0000000 --- a/packages/ditox/test-deno/deno.test.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* eslint-disable @typescript-eslint/ban-ts-comment */ -// @ts-nocheck -declare const Deno: any; - -import { - assertEquals, - assertStrictEquals, - assertThrows, -} from 'https://deno.land/std@0.79.0/testing/asserts.ts'; -import { - bindMultiValue, - Container, - createContainer, - tryResolveValues, - injectable, - optional, - ResolverError, - resolveValues, - token, -} from '../../../mod.ts'; - -const NUMBER = token('number'); -const STRING = token('string'); -const NUMBERS = token>('numbers'); - -Deno.test('should bind a value to the container', () => { - const container = createContainer(); - container.bindValue(NUMBER, 1); - assertStrictEquals(container.get(NUMBER), 1); -}); - -Deno.test('should bind a factory to the container', () => { - const container = createContainer(); - - let containerArg; - const factory = (arg: Container) => { - containerArg = arg; - return 1; - }; - container.bindFactory(NUMBER, factory); - - assertStrictEquals(container.get(NUMBER), 1); - assertStrictEquals(containerArg, container); -}); - -Deno.test('should bind a factory with "singleton" scope', () => { - const parent = createContainer(); - const container = createContainer(parent); - - const START = token(); - parent.bindValue(START, 10); - container.bindValue(START, 20); - - let counter = 0; - const factory = (start: number) => start + ++counter; - parent.bindFactory(NUMBER, injectable(factory, START), { - scope: 'singleton', - }); - - assertStrictEquals(container.get(NUMBER), 11); - assertStrictEquals(container.get(NUMBER), 11); - assertStrictEquals(parent.get(NUMBER), 11); - assertStrictEquals(container.get(NUMBER), 11); -}); - -Deno.test('should bind a factory with "scoped" scope', () => { - const parent = createContainer(); - const container = createContainer(parent); - - const START = token(); - parent.bindValue(START, 10); - container.bindValue(START, 20); - - let counter = 0; - const factory = (start: number) => start + ++counter; - parent.bindFactory(NUMBER, injectable(factory, START), { - scope: 'scoped', - }); - - assertStrictEquals(container.get(NUMBER), 21); - assertStrictEquals(container.get(NUMBER), 21); - assertStrictEquals(parent.get(NUMBER), 12); - assertStrictEquals(container.get(NUMBER), 21); -}); - -Deno.test('should bind a factory with "transient" scope', () => { - const parent = createContainer(); - const container = createContainer(parent); - - const START = token(); - parent.bindValue(START, 10); - container.bindValue(START, 20); - - let counter = 0; - const factory = (start: number) => start + ++counter; - parent.bindFactory(NUMBER, injectable(factory, START), { - scope: 'transient', - }); - - assertStrictEquals(container.get(NUMBER), 21); - assertStrictEquals(container.get(NUMBER), 22); - assertStrictEquals(parent.get(NUMBER), 13); - assertStrictEquals(container.get(NUMBER), 24); -}); - -Deno.test('should bind a factory with "onRemoved" callback', () => { - const container = createContainer(); - - let flag = false; - const factory = () => 1; - const callback = () => (flag = true); - container.bindFactory(NUMBER, factory, {onRemoved: callback}); - - assertStrictEquals(container.get(NUMBER), 1); - container.remove(NUMBER); - assertStrictEquals(flag, true); -}); - -Deno.test('should return a provided value', () => { - const container = createContainer(); - container.bindValue(NUMBER, 1); - assertStrictEquals(container.get(NUMBER), 1); -}); - -Deno.test('should resolve a provided value', () => { - const container = createContainer(); - container.bindValue(NUMBER, 1); - assertStrictEquals(container.resolve(NUMBER), 1); -}); - -Deno.test('should throw ResolverError in case a value is not provided', () => { - const container = createContainer(); - assertThrows(() => container.resolve(NUMBER), ResolverError); -}); - -Deno.test('should return a value from the parent container', () => { - const parent = createContainer(); - const container = createContainer(parent); - parent.bindValue(NUMBER, 1); - assertStrictEquals(container.get(NUMBER), 1); -}); - -Deno.test('should remove all values and factories', () => { - const container = createContainer(); - - container.bindValue(NUMBER, 1); - container.bindFactory(STRING, () => '2'); - assertStrictEquals(container.get(NUMBER), 1); - assertStrictEquals(container.get(STRING), '2'); - - container.removeAll(); - assertStrictEquals(container.get(NUMBER), undefined); - assertStrictEquals(container.get(STRING), undefined); -}); - -Deno.test( - 'should resolve an optional value in case the optional token is not provided', - () => { - const parent = createContainer(); - const container = createContainer(parent); - - const optionalNumber = optional(NUMBER, 1); - - assertStrictEquals(parent.resolve(optionalNumber), 1); - assertStrictEquals(container.resolve(optionalNumber), 1); - }, -); - -Deno.test('should return values for the tokens', () => { - const container = createContainer(); - container.bindValue(NUMBER, 1); - container.bindValue(STRING, 'abc'); - - const values: [number, string] = tryResolveValues(container, NUMBER, STRING); - assertEquals(values, [1, 'abc']); -}); - -Deno.test('should resolve tokens from the container', () => { - const container = createContainer(); - container.bindValue(NUMBER, 1); - container.bindValue(STRING, 'abc'); - - const values: [number, string] = resolveValues(container, NUMBER, STRING); - assertEquals(values, [1, 'abc']); -}); - -Deno.test( - 'should inject values from Container as arguments of the factory', - () => { - const container = createContainer(); - container.bindValue(NUMBER, 1); - container.bindValue(STRING, '2'); - - const decoratedFactory = injectable( - (a: number, b: string) => a + b, - NUMBER, - STRING, - ); - - const result = decoratedFactory(container); - assertStrictEquals(result, '12'); - }, -); - -Deno.test('should append a value to an array declared by a token', () => { - const container = createContainer(); - - bindMultiValue(container, NUMBERS, 1); - bindMultiValue(container, NUMBERS, 2); - - const values: Array = container.resolve(NUMBERS); - assertEquals(values, [1, 2]); -}); diff --git a/packages/ditox/test-deno/tsconfig.json b/packages/ditox/test-deno/tsconfig.json deleted file mode 100644 index f6b97a8..0000000 --- a/packages/ditox/test-deno/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - // This is based on https://deno.land/manual/getting_started/typescript#custom-typescript-compiler-options - // then the defaults are removed. - - "$schema": "https://json.schemastore.org/tsconfig", - "display": "Deno", - - "compilerOptions": { - "lib": [], - "resolveJsonModule": true, - "strict": true - } -} diff --git a/packages/ditox/tsconfig.json b/packages/ditox/tsconfig.json index 013d121..4082f16 100644 --- a/packages/ditox/tsconfig.json +++ b/packages/ditox/tsconfig.json @@ -1,4 +1,3 @@ { - "extends": "../../tsconfig.json", - "exclude": ["test-deno"] + "extends": "../../tsconfig.json" }