fix(core): update

This commit is contained in:
Philipp Kunz 2023-11-24 20:08:48 +01:00
parent 8170877c55
commit c8ab607959
8 changed files with 2618 additions and 1684 deletions

View File

@ -9,24 +9,24 @@
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"build": "(tsbuild)", "build": "(tsbuild --allowimplicitany)",
"buildDocs": "tsdoc" "buildDocs": "tsdoc"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@git.zone/tsbuild": "^2.1.66",
"@gitzone/tsrun": "^1.2.39", "@git.zone/tsrun": "^1.2.44",
"@gitzone/tstest": "^1.0.15", "@git.zone/tstest": "^1.0.77",
"@pushrocks/tapbundle": "^5.0.4", "@push.rocks/tapbundle": "^5.0.8",
"@types/node": "^18.11.18" "@types/node": "^20.10.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/levelcache": "^3.0.3", "@push.rocks/levelcache": "^3.0.3",
"@pushrocks/smartfile": "^10.0.7", "@push.rocks/smartfile": "^11.0.4",
"@pushrocks/smarthash": "^3.0.1", "@push.rocks/smarthash": "^3.0.4",
"@pushrocks/smartpath": "^5.0.5", "@push.rocks/smartpath": "^5.0.5",
"@pushrocks/smartrequest": "^2.0.11", "@push.rocks/smartrequest": "^2.0.15",
"@types/sharp": "^0.31.1", "@types/sharp": "^0.32.0",
"sharp": "^0.31.3" "sharp": "^0.32.6"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
# @pushrocks/smartjimp # @push.rocks/smartjimp
a tool fr working with images in TypeScript a tool fr working with images in TypeScript
## Availabililty and Links ## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartjimp) * [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartjimp)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartjimp) * [gitlab.com (source)](https://gitlab.com/pushrocks/smartjimp)
* [github.com (source mirror)](https://github.com/pushrocks/smartjimp) * [github.com (source mirror)](https://github.com/pushrocks/smartjimp)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartjimp/) * [docs (typedoc)](https://pushrocks.gitlab.io/smartjimp/)
@ -13,14 +13,14 @@ Status Category | Status Badge
-- | -- -- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartjimp/badges/master/pipeline.svg)](https://lossless.cloud) GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartjimp/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartjimp/badges/master/coverage.svg)](https://lossless.cloud) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartjimp/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartjimp)](https://lossless.cloud) npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartjimp)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartjimp)](https://lossless.cloud) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartjimp)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud) TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud) Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartjimp)](https://lossless.cloud) PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smartjimp)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartjimp)](https://lossless.cloud) PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartjimp)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartjimp)](https://lossless.cloud) BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartjimp)](https://lossless.cloud)
## Usage ## Usage

View File

@ -1,6 +1,6 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@push.rocks/tapbundle';
import * as smartjimp from '../ts/index.js'; import * as smartjimp from '../ts/index.js';
import * as smartfile from '@pushrocks/smartfile'; import * as smartfile from '@push.rocks/smartfile';
let testSmartJimp: smartjimp.SmartJimp; let testSmartJimp: smartjimp.SmartJimp;
@ -10,8 +10,9 @@ tap.test('first test', async () => {
}); });
tap.test('should be able to create a master', async () => { tap.test('should be able to create a master', async () => {
const convertedAsset = await testSmartJimp.getFromUrl('https://images.unsplash.com/photo-1673276628202-737bf3020ac2?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3774&q=80', {width: 200}); const smartfileInstance = await smartfile.SmartFile.fromUrl('https://images.unsplash.com/photo-1673276628202-737bf3020ac2?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3774&q=80')
(await smartfile.Smartfile.fromBuffer('.nogit/result.jpeg', convertedAsset)).write(); const convertedAsset = await testSmartJimp.getFromSmartfile(smartfileInstance, {width: 500});
(await smartfile.SmartFile.fromBuffer('.nogit/result.avif', convertedAsset)).write();
}); });
tap.start(); tap.start();

View File

@ -2,7 +2,7 @@
* autocreated commitinfo by @pushrocks/commitinfo * autocreated commitinfo by @pushrocks/commitinfo
*/ */
export const commitinfo = { export const commitinfo = {
name: '@pushrocks/smartjimp', name: '@push.rocks/smartjimp',
version: '1.0.5', version: '1.0.6',
description: 'a tool fr working with images in TypeScript' description: 'a tool fr working with images in TypeScript'
} }

View File

@ -16,7 +16,7 @@ export class SmartJimp {
* get a key that is unique for a wanted asset variation * get a key that is unique for a wanted asset variation
*/ */
private getCacheKey( private getCacheKey(
sourceTypeArg: 'path' | 'url' | 'smartfile', sourceTypeArg: 'streamfile' | 'smartfile',
sourceIdArg: string, sourceIdArg: string,
wantedDimensionsArg?: IDimensions wantedDimensionsArg?: IDimensions
) { ) {
@ -33,47 +33,15 @@ export class SmartJimp {
} }
let sharpImage = plugins.sharp(assetBuffer); let sharpImage = plugins.sharp(assetBuffer);
sharpImage = sharpImage.resize(wantedDimensions.width, wantedDimensions.height); sharpImage = sharpImage.resize(wantedDimensions.width, wantedDimensions.height);
const result = await sharpImage.resize(wantedDimensions.width, wantedDimensions.height).jpeg().toBuffer(); const result = await sharpImage.resize(wantedDimensions.width, wantedDimensions.height).avif().toBuffer();
return result; return result;
} }
public async getFromPath(pathArg: string, wantedDimensionsArg?: IDimensions) {
const cacheKey = this.getCacheKey('path', pathArg, wantedDimensionsArg);
const existingCacheEntry = await this.levelCache.retrieveCacheEntryByKey(cacheKey);
if (existingCacheEntry) {
return existingCacheEntry.contents;
} else {
const originalAssetSmartfile = await plugins.smartfile.Smartfile.fromFilePath(pathArg);
const computedAssetBuffer = await this.computeAssetVariation(originalAssetSmartfile.contentBuffer, wantedDimensionsArg);
this.levelCache.storeCacheEntryByKey(cacheKey, new plugins.levelcache.CacheEntry({
contents: computedAssetBuffer,
ttl: 600000
}));
return computedAssetBuffer;
}
}
public async getFromUrl(urlArg: string, wantedDimensionsArg?: IDimensions) {
const cacheKey = this.getCacheKey('url', urlArg, wantedDimensionsArg);
const existingCacheEntry = await this.levelCache.retrieveCacheEntryByKey(cacheKey);
if (existingCacheEntry) {
return existingCacheEntry.contents;
} else {
const originalAssetBuffer = (await plugins.smartrequest.getBinary(urlArg)).body;
const computedAssetBuffer = await this.computeAssetVariation(originalAssetBuffer, wantedDimensionsArg);
this.levelCache.storeCacheEntryByKey(cacheKey, new plugins.levelcache.CacheEntry({
contents: computedAssetBuffer,
ttl: 600000
}));
return computedAssetBuffer;
}
}
public async getFromSmartfile( public async getFromSmartfile(
smartfileArg: plugins.smartfile.Smartfile, smartfileArg: plugins.smartfile.SmartFile,
wantedDimensionsArg?: IDimensions wantedDimensionsArg?: IDimensions
) { ) {
const cacheKey = this.getCacheKey('url', await smartfileArg.getHash(), wantedDimensionsArg); const cacheKey = this.getCacheKey('smartfile', await smartfileArg.getHash(), wantedDimensionsArg);
const existingCacheEntry = await this.levelCache.retrieveCacheEntryByKey(cacheKey); const existingCacheEntry = await this.levelCache.retrieveCacheEntryByKey(cacheKey);
if (existingCacheEntry) { if (existingCacheEntry) {
return existingCacheEntry.contents; return existingCacheEntry.contents;
@ -86,4 +54,11 @@ export class SmartJimp {
return computedAssetBuffer; return computedAssetBuffer;
} }
} }
public async createAvifImageFromBuffer(bufferArg: Buffer) {
const sharpImage = plugins.sharp(bufferArg);
const result = await sharpImage.avif().toBuffer();
return result;
}
} }

View File

@ -4,11 +4,11 @@ import * as path from 'path';
export { path }; export { path };
// @pushrocks scope // @pushrocks scope
import * as levelcache from '@pushrocks/levelcache'; import * as levelcache from '@push.rocks/levelcache';
import * as smartfile from '@pushrocks/smartfile'; import * as smartfile from '@push.rocks/smartfile';
import * as smarthash from '@pushrocks/smarthash'; import * as smarthash from '@push.rocks/smarthash';
import * as smartpath from '@pushrocks/smartpath'; import * as smartpath from '@push.rocks/smartpath';
import * as smartrequest from '@pushrocks/smartrequest'; import * as smartrequest from '@push.rocks/smartrequest';
export { levelcache, smartpath, smarthash, smartfile, smartrequest }; export { levelcache, smartpath, smarthash, smartfile, smartrequest };

View File

@ -3,8 +3,12 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"useDefineForClassFields": false, "useDefineForClassFields": false,
"target": "ES2022", "target": "ES2022",
"module": "ES2022", "module": "NodeNext",
"moduleResolution": "nodenext", "moduleResolution": "NodeNext",
"esModuleInterop": true "esModuleInterop": true,
} "verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
} }