Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
devjmetivier committed Dec 27, 2024
0 parents commit e25ac01
Show file tree
Hide file tree
Showing 20 changed files with 2,916 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish to NPM

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 8
run_install: false

- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: pnpm install, build, and test
run: |
pnpm install
pnpm build
pnpm test
- name: publish
env:
NODE_AUTH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: |
pnpm run deploy
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/*.tgz
dist/
node_modules
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.github
.vscode
.eslintrc
.prettierrc
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"editor.codeActionsOnSave": {
"source.addMissingImports.ts": "always",
"source.fixAll.format": "always",
"source.organizeImports": "always",
"source.organizeImports.biome": "always"
},
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"files.associations": {
"*.css": "tailwindcss"
},
"prettier.requireConfig": true
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Delicious Simplicity

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
60 changes: 60 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"files": {
"maxSize": 20000000
},
"formatter": {
"attributePosition": "auto",
"enabled": true,
"formatWithErrors": false,
"ignore": ["**/.next/**", "**/.turbo/**", "**/dist/**", "**/node_modules/**", "**/pnpm-lock.yaml"],
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 120
},
"javascript": {
"formatter": {
"arrowParentheses": "always",
"attributePosition": "auto",
"bracketSameLine": false,
"bracketSpacing": true,
"jsxQuoteStyle": "single",
"quoteProperties": "asNeeded",
"quoteStyle": "single",
"semicolons": "always",
"trailingCommas": "all"
}
},
"linter": {
"enabled": true,
"ignore": ["**/.next/**", "**/.turbo/**", "**/dist/**", "**/node_modules/**", "**/pnpm-lock.yaml"],
"rules": {
"a11y": {
"noSvgWithoutTitle": "off",
"useKeyWithClickEvents": "off"
},
"nursery": {
"useSortedClasses": {
"fix": "safe",
"level": "error",
"options": {
"attributes": ["className"],
"functions": ["cn"]
}
}
},
"recommended": true,
"style": {
"noNonNullAssertion": "warn"
},
"suspicious": {
"noArrayIndexKey": "warn",
"noExplicitAny": "warn"
}
}
},
"organizeImports": {
"enabled": true
}
}
36 changes: 36 additions & 0 deletions examples/all-primitives.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { KeyDictionary, type KeyPrefixConfig } from 'typekey';

const dict = {
boolean: ['value'] as const,
mixed: ['number', 'string', 'boolean', 'null', 'undefined'] as const,
null: ['value'] as const,
number: ['value'] as const,
string: ['value'] as const,
undefined: ['value'] as const,
} satisfies KeyPrefixConfig;

const keyDictionary = new KeyDictionary(dict);

keyDictionary.generateKey('boolean', { value: true });
// => 'boolean:["true"]'

keyDictionary.generateKey('mixed', {
boolean: true,
null: null,
number: 1,
string: 'string',
undefined: undefined,
});
// => 'mixed:["true","null","1","string","undefined"]'

keyDictionary.generateKey('null', { value: null });
// => 'null:["null"]'

keyDictionary.generateKey('number', { value: 1 });
// => 'number:["1"]'

keyDictionary.generateKey('string', { value: 'string' });
// => 'string:["string"]'

keyDictionary.generateKey('undefined', { value: undefined });
// => 'undefined:["undefined"]'
10 changes: 10 additions & 0 deletions examples/basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { KeyDictionary, type KeyPrefixConfig } from 'typekey';

const dict = {
user: ['id'] as const,
} satisfies KeyPrefixConfig;

const keyDictionary = new KeyDictionary(dict);

keyDictionary.generateKey('user', { id: 1 });
// => 'user:["1"]'
14 changes: 14 additions & 0 deletions examples/with-key-length-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { KeyDictionary, type KeyDictionaryOptions, type KeyPrefixConfig } from 'typekey';

const dict = {
user: ['id'] as const,
} satisfies KeyPrefixConfig;

const options = {
maxKeyLength: 8,
} satisfies KeyDictionaryOptions;

const keyDictionary = new KeyDictionary(dict, options);

keyDictionary.generateKey('user', { id: 1 });
// => 'user:["1'
15 changes: 15 additions & 0 deletions examples/with-throw-option.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { KeyDictionary, type KeyDictionaryOptions, type KeyPrefixConfig } from 'typekey';

const dict = {
user: ['id'] as const,
} satisfies KeyPrefixConfig;

const options = {
maxKeyLength: 8,
throwOnMaxLengthViolation: true,
} satisfies KeyDictionaryOptions;

const keyDictionary = new KeyDictionary(dict, options);

keyDictionary.generateKey('user', { id: 1 });
// => KeyDictionaryError - key length would exceed `maxKeyLength` of 8
68 changes: 68 additions & 0 deletions knip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type { KnipConfig } from 'knip';

const nextjsConfig: KnipConfig['next'] = {
entry: [
'{instrumentation,middleware}.{js,ts}',
'app/{manifest,sitemap,robots}.{js,ts}',
'app/**/{error,layout,loading,not-found,page,template,default}.{js,jsx,ts,tsx}',
'app/**/{icon,apple-icon}.{js,jsx,ts,tsx}',
'app/**/{opengraph,twitter}-image.{js,jsx,ts,tsx}',
'app/**/route.{js,jsx,ts,tsx}',
'app/global-error.{js,jsx,ts,tsx}',
'next.config.{js,ts,cjs,mjs}',
'pages/**/*.{js,jsx,ts,tsx}',
'scripts/**',
'src/{instrumentation,middleware}.{js,ts}',
'src/app/{manifest,sitemap,robots}.{js,ts}',
'src/app/**/{error,layout,loading,not-found,page,template,default}.{js,jsx,ts,tsx}',
'src/app/**/{icon,apple-icon}.{js,jsx,ts,tsx}',
'src/app/**/{opengraph,twitter}-image.{js,jsx,ts,tsx}',
'src/app/**/route.{js,jsx,ts,tsx}',
'src/app/global-error.{js,jsx,ts,tsx}',
'src/pages/**/*.{js,jsx,ts,tsx}',
],
};

const commonFilesIgnore = ['src/image/loader.js', 'src/components/ui/**'];
const commonDepsIgnore = [''];

const config: KnipConfig = {
workspaces: {
'apps/api': {
ignore: [...commonFilesIgnore],
ignoreDependencies: [...commonDepsIgnore],
includeEntryExports: true,
next: nextjsConfig,
},
'apps/auth': {
ignore: [...commonFilesIgnore],
ignoreDependencies: [...commonDepsIgnore],
includeEntryExports: true,
next: nextjsConfig,
},
'apps/play': {
ignore: [...commonFilesIgnore],
ignoreDependencies: [...commonDepsIgnore],
includeEntryExports: true,
next: nextjsConfig,
},
'apps/www': {
ignore: [...commonFilesIgnore],
ignoreDependencies: [...commonDepsIgnore],
includeEntryExports: true,
next: nextjsConfig,
},
'packages/api': {
ignore: ['src/server/generated/**', 'scripts/**', 'contentful/codegen.ts'],
includeEntryExports: true,
},
'contentful-apps/user-mgmt': { includeEntryExports: true },
'packages/db': { includeEntryExports: true },
'packages/ui': {
ignore: ['turbo/**', 'dist/**'],
includeEntryExports: true,
},
},
};

export default config;
43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"author": "Devin Metivier <devin@delicious-simplicity.com>",
"contributors": [
"Delicious Simplicity <info@delicious-simplicity.com>",
"Devin Metivier <devin@delicious-simplicity.com>"
],
"description": "TypeScript library for generating cache keys with type safety",
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@types/node": "^20.14.11",
"globals": "^15.8.0",
"knip": "^5.33.3",
"typescript": "~5.7.2",
"vite": "^6.0.6",
"vite-plugin-dts": "^4.4.0",
"vitest": "^2.0.3"
},
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
}
},
"files": ["dist/"],
"keywords": ["cache", "cache-key", "cache-key-dictionary", "cache-key-generator", "cache-key-registry", "caching"],
"license": "MIT",
"main": "dist/index.js",
"name": "typekey",
"repository": {
"type": "git",
"url": "git+https://github.com/delicious-simplicity/typekey.git"
},
"scripts": {
"build": "vite build",
"deploy": "npm publish",
"format": "biome check . --write --unsafe --diagnostic-level=error && biome format --diagnostic-level=error --write .",
"lint": "pnpm biome lint --write --unsafe --diagnostic-level=error",
"test": "vitest"
},
"type": "module",
"types": "dist/index.d.ts",
"version": "2.0.0"
}
Loading

0 comments on commit e25ac01

Please sign in to comment.