This repository was archived by the owner on Jan 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I'm not sure how to handle the hashid
- Loading branch information
Showing
7 changed files
with
118 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
version: 2 | ||
|
||
jobs: | ||
build: | ||
docker: | ||
- image: circleci/node | ||
|
||
working_directory: ~/repo | ||
|
||
steps: | ||
- checkout | ||
|
||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "yarn.lock" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-dependencies- | ||
|
||
- run: yarn --frozen-lockfile | ||
|
||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v1-dependencies-{{ checksum "yarn.lock" }} | ||
|
||
- run: yarn lint | ||
|
||
- run: yarn test --coverage --ci --runInBand --reporters=default --reporters=jest-junit --forceExit | ||
|
||
- store_test_results: | ||
path: junit.xml | ||
|
||
- run: yarn coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Objection-HashId | ||
|
||
[](https://circleci.com/gh/JaneJeon/objection-hashid) [](https://coveralls.io/github/JaneJeon/objection-hashid?branch=master) [](https://codeclimate.com/github/JaneJeon/objection-hashid/maintainability) [](https://www.npmjs.com/package/objection-hashid) [](https://www.npmjs.com/package/objection-hashid) [](https://packagephobia.now.sh/result?p=objection-hashid) [](https://david-dm.org/JaneJeon/objection-hashid) [](https://snyk.io//test/github/JaneJeon/objection-hashid?targetFile=package.json) [](https://dependabot.com) [](https://github.com/JaneJeon/objection-hashid/blob/master/LICENSE) [](https://janejeon.github.io/objection-hashid) [](https://standardjs.com) | ||
|
||
Use objection-visibility! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const HashId = require('hashids/cjs') | ||
const memoize = require('lodash.memoize') | ||
|
||
const memoizeHashId = memoize( | ||
(salt, minLength, alphabet, seps) => | ||
new HashId(salt, minLength, alphabet, seps) | ||
) | ||
|
||
// you can override any of the hashid properties (minus the salt) by passing thru opt | ||
module.exports = (opts = {hashId = 'id'}) => { | ||
return Model => { | ||
// you can also override the hashid properties on a per-model basis using model properties | ||
return class extends Model { | ||
static get hashIdSalt() { | ||
return this.name | ||
} | ||
|
||
static get hashIdMinLength() { | ||
return opts.minLength | ||
} | ||
|
||
static get hashIdAlphabet() { | ||
return opts.alphabet | ||
} | ||
|
||
static get hashIdSeps() { | ||
return opts.seps | ||
} | ||
|
||
// you can even override the hashId instance! | ||
static get hashIdInstance() { | ||
return memoizeHashId( | ||
this.hashIdSalt, | ||
this.hashIdMinLength, | ||
this.hashIdAlphabet, | ||
this.hashIdSeps | ||
) | ||
} | ||
|
||
static get QueryBuilder() { | ||
return class extends Model.QueryBuilder { | ||
// TODO: | ||
} | ||
} | ||
} | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,11 @@ | ||
{ | ||
"name": "objection-hashid", | ||
"version": "0.1.0", | ||
"description": "Obfuscate your Objection.js model ids using hashids!", | ||
"description": "Objection plugin to automatically obfuscate model ids using hashids!", | ||
"main": "index.js", | ||
"repository": "https://github.com/JaneJeon/objection-hashid", | ||
"repository": "JaneJeon/objection-hashid", | ||
"author": "Jane Jeon <[email protected]>", | ||
"license": "MIT", | ||
"keywords": [ | ||
"objection", | ||
"objection.js", | ||
"knex", | ||
"knexjs", | ||
"knex.js", | ||
"orm", | ||
"plugin", | ||
"id", | ||
"ids", | ||
"hashids", | ||
"hashid", | ||
"hash", | ||
"obfuscation", | ||
"youtube", | ||
"bitly", | ||
"encode", | ||
"decode", | ||
"encrypt", | ||
"decrypt" | ||
], | ||
"scripts": { | ||
"test": "jest", | ||
"test:watch": "yarn test --watch", | ||
|
@@ -38,7 +17,8 @@ | |
"pre-push": "yarn test" | ||
}, | ||
"dependencies": { | ||
"hashids": "^2.0.0" | ||
"hashids": "^2.0.0", | ||
"lodash.memoize": "^4.1.2" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^24.0.18", | ||
|
@@ -51,5 +31,26 @@ | |
"objection": "^1.6.9", | ||
"sqlite3": "^4.1.0", | ||
"standard": "^14.1.0" | ||
} | ||
}, | ||
"keywords": [ | ||
"objection", | ||
"objection.js", | ||
"knex", | ||
"knexjs", | ||
"knex.js", | ||
"orm", | ||
"plugin", | ||
"id", | ||
"ids", | ||
"hashids", | ||
"hashid", | ||
"hash", | ||
"obfuscation", | ||
"youtube", | ||
"bitly", | ||
"encode", | ||
"decode", | ||
"encrypt", | ||
"decrypt" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters