Compare commits

...

12 Commits

Author SHA1 Message Date
4b3964c7c4 2.0.0 2022-05-28 12:33:10 +02:00
7fa246e0e4 BREAKING CHANGE(core): switch to esm 2022-05-28 12:33:10 +02:00
dac5342a19 1.0.18 2022-01-24 04:40:22 +01:00
1829db1d82 fix(core): update 2022-01-24 04:40:21 +01:00
3c4cba97c2 1.0.17 2022-01-24 04:39:13 +01:00
b86bd61cbf fix(core): update 2022-01-24 04:39:12 +01:00
ad95154284 1.0.16 2020-10-17 16:44:53 +00:00
7fb47d224e fix(core): update 2020-10-17 16:44:53 +00:00
40175dc4de 1.0.15 2020-10-17 16:38:22 +00:00
115d461d29 fix(core): update 2020-10-17 16:38:22 +00:00
00964a7db1 1.0.14 2020-09-19 15:06:28 +00:00
b00db37bf4 fix(core): update 2020-09-19 15:06:27 +00:00
14 changed files with 8207 additions and 9193 deletions

View File

@ -12,6 +12,9 @@ stages:
- release - release
- metadata - metadata
before_script:
- npm install -g @shipzone/npmci
# ==================== # ====================
# security stage # security stage
# ==================== # ====================
@ -19,23 +22,36 @@ mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
only:
- tags
tags: tags:
- lossless - lossless
- docker - docker
- notpriv - notpriv
audit: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high - npmci command npm audit --audit-level=high --only=dev
tags: tags:
- lossless
- docker - docker
- notpriv allow_failure: true
# ==================== # ====================
# test stage # test stage
@ -50,9 +66,7 @@ testStable:
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- priv
testBuild: testBuild:
stage: test stage: test
@ -63,9 +77,7 @@ testBuild:
- npmci command npm run build - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- notpriv
release: release:
stage: release stage: release
@ -85,11 +97,12 @@ release:
codequality: codequality:
stage: metadata stage: metadata
allow_failure: true allow_failure: true
only:
- tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g typescript
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- lossless - lossless
- docker - docker

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "current file", "command": "npm test",
"type": "node", "name": "Run npm test",
"request": "launch", "request": "launch",
"args": [ "type": "node-terminal"
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
} }
] ]
} }

View File

@ -15,7 +15,7 @@
"properties": { "properties": {
"projectType": { "projectType": {
"type": "string", "type": "string",
"enum": ["website", "element", "service", "npm"] "enum": ["website", "element", "service", "npm", "wcc"]
} }
} }
} }

View File

@ -5,7 +5,7 @@
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "pushrocks",
"gitrepo": "webstore", "gitrepo": "webstore",
"shortDescription": "high performance storage in the browser using indexed db", "description": "high performance storage in the browser using indexed db",
"npmPackagename": "@pushrocks/webstore", "npmPackagename": "@pushrocks/webstore",
"license": "MIT", "license": "MIT",
"projectDomain": "push.rocks" "projectDomain": "push.rocks"

17509
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,11 @@
{ {
"name": "@pushrocks/webstore", "name": "@pushrocks/webstore",
"version": "1.0.13", "version": "2.0.0",
"private": false, "private": false,
"description": "high performance storage in the browser using indexed db", "description": "high performance storage in the browser using indexed db",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"type": "module",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
@ -12,16 +13,20 @@
"build": "(tsbuild --web)" "build": "(tsbuild --web)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.25", "@gitzone/tsbuild": "^2.1.63",
"@gitzone/tstest": "^1.0.44", "@gitzone/tstest": "^1.0.71",
"@pushrocks/tapbundle": "^3.2.9", "@pushrocks/tapbundle": "^5.0.3",
"@types/node": "^14.11.1", "@types/node": "^17.0.36"
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartpromise": "^3.0.6", "@apiglobal/typedrequest-interfaces": "^1.0.15",
"idb": "^5.0.6" "@pushrocks/lik": "^6.0.0",
"@pushrocks/smartenv": "^5.0.1",
"@pushrocks/smartjson": "^4.0.6",
"@pushrocks/smartpromise": "^3.1.6",
"@pushrocks/smartrx": "^2.0.25",
"fake-indexeddb": "^3.1.7",
"idb": "^7.0.1"
}, },
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"

View File

@ -0,0 +1,11 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as webstore from '../ts/index.js';
let testTypedrequestcache: webstore.TypedrequestCache;
tap.test('first test', async () => {
testTypedrequestcache = new webstore.TypedrequestCache('https://test.lossless.com/typedrequest');
expect(testTypedrequestcache).toBeInstanceOf(webstore.TypedrequestCache);
});
tap.start();

View File

@ -1,5 +1,5 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as webstore from '../ts/index'; import * as webstore from '../ts/index.js';
let testWebstore: webstore.WebStore; let testWebstore: webstore.WebStore;
@ -8,16 +8,12 @@ tap.test('first test', async () => {
dbName: 'mytest-db', dbName: 'mytest-db',
storeName: 'mytest-store', storeName: 'mytest-store',
}); });
expect(testWebstore).to.be.instanceOf(webstore.WebStore); expect(testWebstore).toBeInstanceOf(webstore.WebStore);
});
tap.test('should init the database', async () => {
await testWebstore.init();
}); });
tap.test('should allow storing a string', async () => { tap.test('should allow storing a string', async () => {
await testWebstore.set('mystring', 'heythere'); await testWebstore.set('mystring', 'heythere');
expect(await testWebstore.get('mystring')).to.equal('heythere'); expect(await testWebstore.get('mystring')).toEqual('heythere');
}); });
tap.test('should allow storing an object', async () => { tap.test('should allow storing an object', async () => {
@ -37,8 +33,8 @@ tap.test('should overwrite a value', async () => {
tap.test('should correctly check the existence of keys', async () => { tap.test('should correctly check the existence of keys', async () => {
const resultNotThere = await testWebstore.check('notThere'); const resultNotThere = await testWebstore.check('notThere');
const resultThere = await testWebstore.check('testProp1'); const resultThere = await testWebstore.check('testProp1');
expect(resultNotThere).to.be.false; expect(resultNotThere).toBeFalse();
expect(resultThere).to.be.true; expect(resultThere).toBeTrue();
}); });
tap.start(); tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/webstore',
version: '2.0.0',
description: 'high performance storage in the browser using indexed db'
}

View File

@ -1 +1,2 @@
export * from './webstore.classes.webstore'; export * from './webstore.classes.typedrequestcache.js';
export * from './webstore.classes.webstore.js';

View File

@ -0,0 +1,47 @@
import { WebStore } from './webstore.classes.webstore.js';
import * as plugins from './webstore.plugins.js';
/**
* a cache that can be used to store and retrieve typedrequests
*/
export class TypedrequestCache {
private webstore: WebStore;
constructor(domainArg = 'default') {
this.webstore = new WebStore<plugins.typedrequestInterfaces.ITypedRequest>({
dbName: 'trStore',
storeName: `trStore-${domainArg}`,
});
}
private buildKey(requestArg: plugins.typedrequestInterfaces.ITypedRequest) {
return plugins.smartjson.stringify({
method: requestArg.method,
request: requestArg.request,
});
}
/**
* stores by request
* @param typedrequestarg
*/
public async setByRequest(
typedrequestArg: plugins.typedrequestInterfaces.ITypedRequest
): Promise<void> {
if (!typedrequestArg.response) {
throw new Error('You cannot store requests without a response present');
}
await this.webstore.set(this.buildKey(typedrequestArg), typedrequestArg);
}
/**
* get by full tyoedrequest by partial typedrequest
* @param typedrequestarg
*/
public async getByRequest(
typedrequestArg: plugins.typedrequestInterfaces.ITypedRequest
): Promise<plugins.typedrequestInterfaces.ITypedRequest> {
const result = await this.webstore.get(this.buildKey(typedrequestArg));
return result;
}
}

View File

@ -1,4 +1,4 @@
import * as plugins from './webstore.plugins'; import * as plugins from './webstore.plugins.js';
export interface IWebStoreOptions { export interface IWebStoreOptions {
dbName: string; dbName: string;
@ -18,15 +18,24 @@ export class WebStore<T = any> {
public async init() { public async init() {
if (this.initCalled) { if (this.initCalled) {
return this.readyDeferred.promise; await this.readyDeferred.promise;
return;
} }
this.initCalled = true; this.initCalled = true;
const smartenv = new plugins.smartenv.Smartenv();
if (!smartenv.isBrowser) {
const fetch = await smartenv.getSafeNodeModule('fake-indexeddb/auto.js');
globalThis.fetch = fetch.default;
}
this.db = await plugins.idb.openDB(this.options.dbName, 1, { this.db = await plugins.idb.openDB(this.options.dbName, 1, {
upgrade: (db) => { upgrade: (db) => {
db.createObjectStore(this.options.storeName); db.createObjectStore(this.options.storeName);
}, },
}); });
this.readyDeferred.resolve(); this.readyDeferred.resolve();
return;
} }
async get(key: string): Promise<T> { async get(key: string): Promise<T> {
@ -41,6 +50,7 @@ export class WebStore<T = any> {
} }
async set(key: string, val: T) { async set(key: string, val: T) {
await this.init();
return this.db.put(this.options.storeName, val, key); return this.db.put(this.options.storeName, val, key);
} }

View File

@ -1,9 +1,16 @@
// pushrocks scope // pushrocks scope
import * as lik from '@pushrocks/lik';
import * as smartenv from '@pushrocks/smartenv';
import * as smartjson from '@pushrocks/smartjson';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrx from '@pushrocks/smartrx';
export { export { lik, smartenv, smartjson, smartpromise, smartrx };
smartpromise
}; // apiglobal scope
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
export { typedrequestInterfaces };
// thirdparty scope // thirdparty scope
import * as idb from 'idb'; import * as idb from 'idb';

View File

@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}