@stemy/backend 5.1.1 → 5.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stemy/backend",
3
- "version": "5.1.1",
3
+ "version": "5.2.1",
4
4
  "license": "MIT",
5
5
  "repository": "git@github.com:stemyke/node-backend.git",
6
6
  "builders": "builders.json",
package/public_api.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { IBackendConfig, IDependencyContainer, IRequest, IUser, Provider } from "./common-types";
2
2
  export { FilterPredicate, isNullOrUndefined, isDefined, getType, isObject, isArray, isBuffer, isBoolean, isDate, isPrimitive, isString, isFunction, isConstructor, isType, isInterface, ucFirst, lcFirst, isObjectId, firstItem, lastItem, regroup, uniqueItems, getValue, groupBy, convertValue, toImage, bufferToStream, streamToBuffer, copyStream, mkdirRecursive, deleteFile, readFile, readAndDeleteFile, writeFile, valueToPromise, promiseTimeout, getConstructorName, getFunctionParams, getFileName, getExtension, createIdString, idToString, createTransformer, broadcast, rand, random, multiSubscription, observableFromFunction, padLeft, padRight, camelCaseToDash, gzipPromised, gunzipPromised, deleteFromBucket, filter, copy, assign, md5, runCommand, ConsoleColor, IJsonColors, colorize, jsonHighlight, replaceSpecialChars, regexEscape, flatten, wrapError, getDirName, prepareUrl, prepareUrlSlash, prepareUrlEmpty, fileTypeFromBuffer, fileTypeFromStream } from "./utils";
3
3
  export { IsFile, IsObjectId } from "./validators";
4
- export { FIXTURE, JOB, TERMINAL_COMMAND, EXPRESS, HTTP_SERVER, SOCKET_SERVER, SOCKET_CONTROLLERS, PARAMETER, DI_CONTAINER, OPENAPI_VALIDATION, Type, FactoryProvider, IDependencyContainer, ClassBasedProvider, ValueBasedProvider, FactoryBasedProvider, TokenBasedProvider, SyringeProvider, Provider, Constructor, InferGeneric, PickMatching, OmitFirstArg, IMatchField, IProjectOptions, IUnwindOptions, IFixture, IFixtureOutput, SchemaConverter, OpenApiValidation, ParamResolver, Parameter, SocketParam, SocketParams, ISocketMessage, IMessageBridge, IJob, IJobTask, JobParams, JobScheduleRange, JobScheduleTime, ITerminalFile, ITerminal, ITerminalCommand, IProgress, IAssetCropInfo, IAssetMeta, IAssetImageParams, IAsset, ILazyAsset, IUser, IClientSocket, IRequestBase, IRequest, IGalleryImage, IGallerySize, IGalleryImageHandler, ITranslations, IPaginationMeta, IPaginationBase, IPagination, IPaginationParams, FontFormat, IFileType, RoutingOptions, SocketOptions, IBackendConfig } from "./common-types";
4
+ export { FIXTURE, JOB, TERMINAL_COMMAND, EXPRESS, HTTP_SERVER, SOCKET_SERVER, SOCKET_CONTROLLERS, PARAMETER, DI_CONTAINER, OPENAPI_VALIDATION, Type, FactoryProvider, IDependencyContainer, ClassBasedProvider, ValueBasedProvider, FactoryBasedProvider, TokenBasedProvider, SyringeProvider, Provider, Constructor, InferGeneric, PickMatching, OmitFirstArg, IMatchField, IProjectOptions, IUnwindOptions, IFixture, IFixtureOutput, SchemaConverter, OpenApiValidation, ParamResolver, Parameter, SocketParam, SocketParams, ISocketMessage, IMessageBridge, IJob, IJobTask, JobParams, JobScheduleRange, JobScheduleTime, ITerminalFile, ITerminal, ITerminalCommand, IProgress, IAssetCropInfo, IImageMeta, IAssetMeta, IAssetImageParams, IAsset, IAssetUploadStream, IAssetUploadOpts, IAssetDriver, ILazyAsset, IUser, IClientSocket, IRequestBase, IRequest, IGalleryImage, IGallerySize, IGalleryImageHandler, ITranslations, IPaginationMeta, IPaginationBase, IPagination, IPaginationParams, FontFormat, IFileType, RoutingOptions, SocketOptions, IBackendConfig } from "./common-types";
5
+ export { AssetLocalDriver } from "./services/drivers/asset-local.driver";
6
+ export { AssetGridDriver } from "./services/drivers/asset-grid.driver";
5
7
  export { AssetProcessor } from "./services/asset-processor";
6
8
  export { AssetResolver } from "./services/asset-resolver";
7
9
  export { Assets } from "./services/assets";
@@ -6,6 +6,7 @@ import { IAsset } from "../common-types";
6
6
  import { Assets } from "../services/assets";
7
7
  import { AssetResolver } from "../services/asset-resolver";
8
8
  import { AssetImageParams } from "../requests/asset-image-params";
9
+ type AssetReqType = 'Image' | 'Asset';
9
10
  export declare class AssetsController {
10
11
  readonly assets: Assets;
11
12
  readonly assetResolver: AssetResolver;
@@ -18,7 +19,9 @@ export declare class AssetsController {
18
19
  getImage(id: string, params: AssetImageParams, res: Response): Promise<Readable>;
19
20
  getFileByName(name: string, res: Response): Promise<Readable>;
20
21
  getImageByName(name: string, params: AssetImageParams, res: Response): Promise<Readable>;
21
- protected setAssetHeaders(type: string, asset: IAsset, res: Response): void;
22
- protected getAsset(type: string, id: string, lazy: boolean, res: Response): Promise<IAsset>;
23
- protected getAssetByName(type: string, filename: string, res: Response): Promise<IAsset>;
22
+ protected setAssetHeaders(asset: IAsset, res: Response): void;
23
+ protected getAsset(type: AssetReqType, id: string, lazy: boolean, res: Response): Promise<IAsset>;
24
+ protected getAssetByName(type: AssetReqType, filename: string, res: Response): Promise<IAsset>;
25
+ protected resolveFinalAsset(type: AssetReqType, asset: IAsset): Promise<IAsset>;
24
26
  }
27
+ export {};
@@ -1,3 +1,4 @@
1
+ import { ObjectId } from "bson";
1
2
  import { IAsset } from "../common-types";
2
3
  import { Assets } from "./assets";
3
4
  import { LazyAssets } from "./lazy-assets";
@@ -5,5 +6,5 @@ export declare class AssetResolver {
5
6
  readonly assets: Assets;
6
7
  readonly lazyAssets: LazyAssets;
7
8
  constructor(assets: Assets, lazyAssets: LazyAssets);
8
- resolve(id: string, lazy?: boolean): Promise<IAsset>;
9
+ resolve(id: string | ObjectId, lazy?: boolean): Promise<IAsset>;
9
10
  }
@@ -1,22 +1,23 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import { Readable } from "stream";
4
- import { Collection, GridFSBucket } from "mongodb";
4
+ import { ObjectId } from "bson";
5
+ import { Collection } from "mongodb";
5
6
  import { FilterQuery } from "mongoose";
6
- import { IAsset, IAssetMeta, IFileType } from "../common-types";
7
+ import { IAsset, IAssetDriver, IAssetMeta, IFileType } from "../common-types";
7
8
  import { MongoConnector } from "./mongo-connector";
8
9
  import { AssetProcessor } from "./asset-processor";
9
10
  export declare class Assets {
10
11
  readonly connector: MongoConnector;
11
12
  readonly assetProcessor: AssetProcessor;
12
- readonly bucket: GridFSBucket;
13
+ readonly driver: IAssetDriver;
13
14
  readonly collection: Collection<Partial<IAsset>>;
14
- constructor(connector: MongoConnector, assetProcessor: AssetProcessor);
15
+ constructor(connector: MongoConnector, assetProcessor: AssetProcessor, driver: IAssetDriver);
15
16
  write(stream: Readable, contentType?: string, metadata?: IAssetMeta): Promise<IAsset>;
16
17
  writeBuffer(buffer: Buffer, metadata?: IAssetMeta, contentType?: string): Promise<IAsset>;
17
18
  writeUrl(url: string, metadata?: IAssetMeta): Promise<IAsset>;
18
19
  download(url: string, contentType?: string): Promise<IAsset>;
19
- read(id: string): Promise<IAsset>;
20
+ read(id: string | ObjectId): Promise<IAsset>;
20
21
  find(where: FilterQuery<IAsset>): Promise<IAsset>;
21
22
  findMany(where: FilterQuery<IAsset>): Promise<ReadonlyArray<IAsset>>;
22
23
  deleteMany(where: FilterQuery<IAsset>): Promise<ReadonlyArray<string>>;
@@ -0,0 +1,11 @@
1
+ import { GridFSBucket, ObjectId } from 'mongodb';
2
+ import { IAssetDriver, IAssetUploadOpts } from '../../common-types';
3
+ import { MongoConnector } from "../mongo-connector";
4
+ export declare class AssetGridDriver implements IAssetDriver {
5
+ readonly metaCollection: string;
6
+ protected bucket: GridFSBucket;
7
+ constructor(connector: MongoConnector);
8
+ openUploadStream(filename: string, opts?: IAssetUploadOpts): import("mongodb").GridFSBucketWriteStream;
9
+ openDownloadStream(id: ObjectId): import("mongodb").GridFSBucketReadStream;
10
+ delete(id: ObjectId): Promise<void>;
11
+ }
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" />
2
+ import type { ObjectId } from 'mongodb';
3
+ import { IAssetDriver, IAssetUploadOpts, IAssetUploadStream } from '../../common-types';
4
+ export declare class AssetLocalDriver implements IAssetDriver {
5
+ protected dir: string;
6
+ readonly metaCollection: string;
7
+ constructor(dir: string);
8
+ openUploadStream(filename: string, opts?: IAssetUploadOpts): IAssetUploadStream;
9
+ openDownloadStream(id: ObjectId): import("fs").ReadStream;
10
+ delete(id: ObjectId): Promise<void>;
11
+ }
@@ -1,17 +1,17 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import { Readable } from "stream";
4
- import { Collection, GridFSBucket } from "mongodb";
4
+ import { Collection } from "mongodb";
5
5
  import { ObjectId } from "bson";
6
- import { IAsset, IAssetImageParams, IAssetMeta } from "../../common-types";
6
+ import { IAsset, IAssetDriver, IAssetImageParams, IAssetMeta } from "../../common-types";
7
7
  import { BaseEntity } from "./base-entity";
8
8
  export declare class Asset extends BaseEntity<IAsset> implements IAsset {
9
- protected bucket: GridFSBucket;
9
+ protected driver: IAssetDriver;
10
10
  get filename(): string;
11
11
  get contentType(): string;
12
12
  get metadata(): IAssetMeta;
13
13
  get stream(): Readable;
14
- constructor(id: ObjectId, data: Partial<IAsset>, collection: Collection, bucket: GridFSBucket);
14
+ constructor(id: ObjectId, data: Partial<IAsset>, collection: Collection, driver: IAssetDriver);
15
15
  unlink(): Promise<string>;
16
16
  setMeta(metadata: Partial<IAssetMeta>): Promise<any>;
17
17
  getBuffer(): Promise<Buffer>;
@@ -1,12 +1,12 @@
1
1
  import { Collection } from "mongodb";
2
2
  import { ObjectId } from "bson";
3
3
  export declare class BaseEntity<T> {
4
- readonly mId: ObjectId;
4
+ readonly oid: ObjectId;
5
5
  protected data: Partial<T>;
6
6
  protected collection: Collection<any>;
7
7
  get id(): string;
8
8
  protected deleted: boolean;
9
- constructor(mId: ObjectId, data: Partial<T>, collection: Collection<any>);
9
+ constructor(oid: ObjectId, data: Partial<T>, collection: Collection<any>);
10
10
  save(): Promise<any>;
11
11
  load(): Promise<this>;
12
12
  toJSON(): any;
@@ -1,3 +1,4 @@
1
+ import { ObjectId } from "bson";
1
2
  import { Collection } from "mongodb";
2
3
  import { FilterQuery } from "mongoose";
3
4
  import { IJob, ILazyAsset, JobParams, Type } from "../common-types";
@@ -15,7 +16,7 @@ export declare class LazyAssets {
15
16
  protected collection: Collection<Partial<ILazyAsset>>;
16
17
  constructor(connector: MongoConnector, assets: Assets, progresses: Progresses, logger: Logger, jobMan: JobManager);
17
18
  create(jobType: Type<IJob>, jobParamsObj?: JobParams, jobQue?: string): Promise<ILazyAsset>;
18
- read(id: string): Promise<ILazyAsset>;
19
+ read(id: string | ObjectId): Promise<ILazyAsset>;
19
20
  find(where: FilterQuery<ILazyAsset>): Promise<ILazyAsset>;
20
21
  unlink(id: string): Promise<any>;
21
22
  }
@@ -1,14 +1,12 @@
1
- import { Db, GridFSBucket } from "mongodb";
1
+ import { Db } from "mongodb";
2
2
  import mongoose from "mongoose";
3
3
  import { Configuration } from "./configuration";
4
4
  export declare class MongoConnector {
5
5
  readonly configuration: Configuration;
6
6
  get connection(): mongoose.Connection;
7
7
  get database(): Db;
8
- get bucket(): GridFSBucket;
9
8
  protected conn: mongoose.Connection;
10
9
  protected db: Db;
11
- protected fsBucket: GridFSBucket;
12
10
  constructor(configuration: Configuration);
13
11
  connect(): Promise<Db>;
14
12
  }