Skip to content
This repository was archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
I'm not sure how to handle the hashid
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneJeon committed Sep 4, 2019
1 parent 001e763 commit cb11d66
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 26 deletions.
34 changes: 34 additions & 0 deletions .circleci/config.yml
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Sungil Ahn
Copyright (c) 2019 Jane Jeon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Objection-HashId

[![CircleCI](https://img.shields.io/circleci/build/github/JaneJeon/objection-hashid)](https://circleci.com/gh/JaneJeon/objection-hashid) [![Coverage Status](https://coveralls.io/repos/github/JaneJeon/objection-hashid/badge.svg?branch=master)](https://coveralls.io/github/JaneJeon/objection-hashid?branch=master) [![Maintainability](https://api.codeclimate.com/v1/badges/78bae22810143ad84ef1/maintainability)](https://codeclimate.com/github/JaneJeon/objection-hashid/maintainability) [![Version](https://img.shields.io/npm/v/objection-hashid)](https://www.npmjs.com/package/objection-hashid) [![Downloads](https://img.shields.io/npm/dt/objection-hashid)](https://www.npmjs.com/package/objection-hashid) [![install size](https://packagephobia.now.sh/badge?p=objection-hashid)](https://packagephobia.now.sh/result?p=objection-hashid) [![Dependencies](https://img.shields.io/david/JaneJeon/objection-hashid)](https://david-dm.org/JaneJeon/objection-hashid) [![Known Vulnerabilities](https://snyk.io//test/github/JaneJeon/objection-hashid/badge.svg?targetFile=package.json)](https://snyk.io//test/github/JaneJeon/objection-hashid?targetFile=package.json) [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=JaneJeon/objection-hashid)](https://dependabot.com) [![License](https://img.shields.io/npm/l/objection-hashid)](https://github.com/JaneJeon/objection-hashid/blob/master/LICENSE) [![Docs](https://img.shields.io/badge/docs-github-blue)](https://janejeon.github.io/objection-hashid) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

Use objection-visibility!
47 changes: 47 additions & 0 deletions index.js
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 added index.test.js
Empty file.
51 changes: 26 additions & 25 deletions package.json
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",
Expand All @@ -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",
Expand All @@ -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"
]
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2854,6 +2854,11 @@ locate-path@^5.0.0:
dependencies:
p-locate "^4.1.0"

lodash.memoize@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=

lodash.sortby@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
Expand Down

0 comments on commit cb11d66

Please sign in to comment.