StorageBase

This commit is contained in:
2022-05-26 18:49:49 -05:00
commit 94126fe5f9
12 changed files with 666 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
node_modules
lib
examples/*.js
+10
View File
@@ -0,0 +1,10 @@
{
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "avoid"
}
+7
View File
@@ -0,0 +1,7 @@
Copyright 2022 Ashley Zomo
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+1
View File
@@ -0,0 +1 @@
# discord.js-storage
+16
View File
@@ -0,0 +1,16 @@
const { build } = require('esbuild')
const define = {
TOKEN: `"${process.argv[2]}"`,
}
build({
entryPoints: ['examples/main.ts'],
outfile: 'examples/main.js',
target: 'es6',
platform: 'node',
format: 'cjs',
define,
})
+1
View File
@@ -0,0 +1 @@
declare const TOKEN: string
+7
View File
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"strict": true
}
}
+27
View File
@@ -0,0 +1,27 @@
{
"name": "discord.js-storage",
"description": "",
"version": "1.0.0",
"main": "lib/main.js",
"types": "lib/main.d.ts",
"scripts": {
"build": "tsc",
"buildexamples": "node buildexample.js",
"prettier": "prettier --write .",
"prepare": "npm run build"
},
"repository": {
"type": "git",
"url": "git@git.zomo.dev:zomo/discordslash.git"
},
"author": "ashley zomo",
"license": "ISC",
"devDependencies": {
"discord.js": "^13.6.0",
"prettier": "^2.6.2",
"typescript": "^4.6.3"
},
"dependencies": {
"esbuild": "^0.14.28"
}
}
+527
View File
@@ -0,0 +1,527 @@
lockfileVersion: 5.3
specifiers:
discord.js: ^13.6.0
esbuild: ^0.14.28
prettier: ^2.6.2
typescript: ^4.6.3
dependencies:
esbuild: 0.14.28
devDependencies:
discord.js: 13.6.0
prettier: 2.6.2
typescript: 4.6.3
packages:
/@discordjs/builders/0.11.0:
resolution:
{
integrity: sha512-ZTB8yJdJKrKlq44dpWkNUrAtEJEq0gqpb7ASdv4vmq6/mZal5kOv312hQ56I/vxwMre+VIkoHquNUAfnTbiYtg==,
}
engines: { node: '>=16.0.0', npm: '>=7.0.0' }
dependencies:
'@sindresorhus/is': 4.6.0
discord-api-types: 0.26.1
ts-mixer: 6.0.1
tslib: 2.3.1
zod: 3.14.3
dev: true
/@discordjs/collection/0.4.0:
resolution:
{
integrity: sha512-zmjq+l/rV35kE6zRrwe8BHqV78JvIh2ybJeZavBi5NySjWXqN3hmmAKg7kYMMXSeiWtSsMoZ/+MQi0DiQWy2lw==,
}
engines: { node: '>=16.0.0', npm: '>=7.0.0' }
dev: true
/@sapphire/async-queue/1.3.0:
resolution:
{
integrity: sha512-z+CDw5X4UgIEpZL8KM+ThVx1i8V60HBg0l/oFewTNbQQeRDJHdVxHyJykv+SF1H+Rc8EkMS81VTWo95jVYgO/g==,
}
engines: { node: '>=v14.0.0', npm: '>=7.0.0' }
dev: true
/@sindresorhus/is/4.6.0:
resolution:
{
integrity: sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==,
}
engines: { node: '>=10' }
dev: true
/@types/node-fetch/2.6.1:
resolution:
{
integrity: sha512-oMqjURCaxoSIsHSr1E47QHzbmzNR5rK8McHuNb11BOM9cHcIK3Avy0s/b2JlXHoQGTYS3NsvWzV1M0iK7l0wbA==,
}
dependencies:
'@types/node': 17.0.23
form-data: 3.0.1
dev: true
/@types/node/17.0.23:
resolution:
{
integrity: sha512-UxDxWn7dl97rKVeVS61vErvw086aCYhDLyvRQZ5Rk65rZKepaFdm53GeqXaKBuOhED4e9uWq34IC3TdSdJJ2Gw==,
}
dev: true
/@types/ws/8.5.3:
resolution:
{
integrity: sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==,
}
dependencies:
'@types/node': 17.0.23
dev: true
/asynckit/0.4.0:
resolution: { integrity: sha1-x57Zf380y48robyXkLzDZkdLS3k= }
dev: true
/combined-stream/1.0.8:
resolution:
{
integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==,
}
engines: { node: '>= 0.8' }
dependencies:
delayed-stream: 1.0.0
dev: true
/delayed-stream/1.0.0:
resolution: { integrity: sha1-3zrhmayt+31ECqrgsp4icrJOxhk= }
engines: { node: '>=0.4.0' }
dev: true
/discord-api-types/0.26.1:
resolution:
{
integrity: sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ==,
}
engines: { node: '>=12' }
dev: true
/discord.js/13.6.0:
resolution:
{
integrity: sha512-tXNR8zgsEPxPBvGk3AQjJ9ljIIC6/LOPjzKwpwz8Y1Q2X66Vi3ZqFgRHYwnHKC0jC0F+l4LzxlhmOJsBZDNg9g==,
}
engines: { node: '>=16.6.0', npm: '>=7.0.0' }
dependencies:
'@discordjs/builders': 0.11.0
'@discordjs/collection': 0.4.0
'@sapphire/async-queue': 1.3.0
'@types/node-fetch': 2.6.1
'@types/ws': 8.5.3
discord-api-types: 0.26.1
form-data: 4.0.0
node-fetch: 2.6.7
ws: 8.5.0
transitivePeerDependencies:
- bufferutil
- encoding
- utf-8-validate
dev: true
/esbuild-android-64/0.14.28:
resolution:
{
integrity: sha512-A52C3zq+9tNwCqZ+4kVLBxnk/WnrYM8P2+QNvNE9B6d2OVPs214lp3g6UyO+dKDhUdefhfPCuwkP8j2A/+szNA==,
}
engines: { node: '>=12' }
cpu: [x64]
os: [android]
requiresBuild: true
dev: false
optional: true
/esbuild-android-arm64/0.14.28:
resolution:
{
integrity: sha512-sm0fDEGElZhMC3HLZeECI2juE4aG7uPfMBMqNUhy9CeX399Pz8rC6e78OXMXInGjSdEAwQmCOHmfsP7uv3Q8rA==,
}
engines: { node: '>=12' }
cpu: [arm64]
os: [android]
requiresBuild: true
dev: false
optional: true
/esbuild-darwin-64/0.14.28:
resolution:
{
integrity: sha512-nzDd7mQ44FvsFHtOafZdBgn3Li5SMsnMnoz1J2MM37xJmR3wGNTFph88KypjHgWqwbxCI7MXS1U+sN4qDeeW6Q==,
}
engines: { node: '>=12' }
cpu: [x64]
os: [darwin]
requiresBuild: true
dev: false
optional: true
/esbuild-darwin-arm64/0.14.28:
resolution:
{
integrity: sha512-XEq/bLR/glsUl+uGrBimQzOVs/CmwI833fXUhP9xrLI3IJ+rKyrZ5IA8u+1crOEf1LoTn8tV+hInmX6rGjbScw==,
}
engines: { node: '>=12' }
cpu: [arm64]
os: [darwin]
requiresBuild: true
dev: false
optional: true
/esbuild-freebsd-64/0.14.28:
resolution:
{
integrity: sha512-rTKLgUj/HEcPeE5XZ7IZwWpFx7IWMfprN7QRk/TUJE1s1Ipb58esboIesUpjirJz/BwrgHq+FDG9ChAI8dZAtQ==,
}
engines: { node: '>=12' }
cpu: [x64]
os: [freebsd]
requiresBuild: true
dev: false
optional: true
/esbuild-freebsd-arm64/0.14.28:
resolution:
{
integrity: sha512-sBffxD1UMOsB7aWMoExmipycjcy3HJGwmqE4GQZUTZvdiH4GhjgUiVdtPyt7kSCdL40JqnWQJ4b1l8Y51oCF4Q==,
}
engines: { node: '>=12' }
cpu: [arm64]
os: [freebsd]
requiresBuild: true
dev: false
optional: true
/esbuild-linux-32/0.14.28:
resolution:
{
integrity: sha512-+Wxidh3fBEQ9kHcCsD4etlBTMb1n6QY2uXv3rFhVn88CY/JP782MhA57/ipLMY4kOLeSKEuFGN4rtjHuhmRMig==,
}
engines: { node: '>=12' }
cpu: [ia32]
os: [linux]
requiresBuild: true
dev: false
optional: true
/esbuild-linux-64/0.14.28:
resolution:
{
integrity: sha512-7+xgsC4LvR6cnzaBdiljNnPDjbkwzahogN+S9uy9AoYw7ZjPnnXc6sjQAVCbqGb7MEgrWdpa6u/Tao79i4lWxg==,
}
engines: { node: '>=12' }
cpu: [x64]
os: [linux]
requiresBuild: true
dev: false
optional: true
/esbuild-linux-arm/0.14.28:
resolution:
{
integrity: sha512-L5isjmlLbh9E0WVllXiVETbScgMbth/+XkXQii1WwgO1RvLIfaGrVFz8d2n6EH/ImtgYxPYGx+OcvIKQBc91Rg==,
}
engines: { node: '>=12' }
cpu: [arm]
os: [linux]
requiresBuild: true
dev: false
optional: true
/esbuild-linux-arm64/0.14.28:
resolution:
{
integrity: sha512-EjRHgwg+kgXABzyoPGPOPg4d5wZqRnZ/ZAxBDzLY+i6DS8OUfTSlZHWIOZzU4XF7125WxRBg9ULbrFJBl+57Eg==,
}
engines: { node: '>=12' }
cpu: [arm64]
os: [linux]
requiresBuild: true
dev: false
optional: true
/esbuild-linux-mips64le/0.14.28:
resolution:
{
integrity: sha512-krx9SSg7yfiUKk64EmjefOyiEF6nv2bRE4um/LiTaQ6Y/6FP4UF3/Ou/AxZVyR154uSRq63xejcAsmswXAYRsw==,
}
engines: { node: '>=12' }
cpu: [mips64el]
os: [linux]
requiresBuild: true
dev: false
optional: true
/esbuild-linux-ppc64le/0.14.28:
resolution:
{
integrity: sha512-LD0Xxu9g+DNuhsEBV5QuVZ4uKVBMup0xPIruLweuAf9/mHXFnaCuNXUBF5t0DxKl7GQ5MSioKtnb92oMo+QXEw==,
}
engines: { node: '>=12' }
cpu: [ppc64]
os: [linux]
requiresBuild: true
dev: false
optional: true
/esbuild-linux-riscv64/0.14.28:
resolution:
{
integrity: sha512-L/DWfRh2P0vxq4Y+qieSNXKGdMg+e9Qe8jkbN2/8XSGYDTPzO2OcAxSujob4qIh7iSl+cknbXV+BvH0YFR0jbg==,
}
engines: { node: '>=12' }
cpu: [riscv64]
os: [linux]
requiresBuild: true
dev: false
optional: true
/esbuild-linux-s390x/0.14.28:
resolution:
{
integrity: sha512-rrgxmsbmL8QQknWGnAL9bGJRQYLOi2AzXy5OTwfhxnj9eqjo5mSVbJXjgiq5LPUAMQZGdPH5yaNK0obAXS81Zw==,
}
engines: { node: '>=12' }
cpu: [s390x]
os: [linux]
requiresBuild: true
dev: false
optional: true
/esbuild-netbsd-64/0.14.28:
resolution:
{
integrity: sha512-h8wntIyOR8/xMVVM6TvJxxWKh4AjmLK87IPKpuVi8Pq0kyk0RMA+eo4PFGk5j2XK0D7dj8PcSF5NSlP9kN/j0A==,
}
engines: { node: '>=12' }
cpu: [x64]
os: [netbsd]
requiresBuild: true
dev: false
optional: true
/esbuild-openbsd-64/0.14.28:
resolution:
{
integrity: sha512-HBv18rVapbuDx52/fhZ/c/w6TXyaQAvRxiDDn5Hz/pBcwOs3cdd2WxeIKlWmDoqm2JMx5EVlq4IWgoaRX9mVkw==,
}
engines: { node: '>=12' }
cpu: [x64]
os: [openbsd]
requiresBuild: true
dev: false
optional: true
/esbuild-sunos-64/0.14.28:
resolution:
{
integrity: sha512-zlIxePhZxKYheR2vBCgPVvTixgo/ozOfOMoP6RZj8dxzquU1NgeyhjkcRXucbLCtmoNJ+i4PtWwPZTLuDd3bGg==,
}
engines: { node: '>=12' }
cpu: [x64]
os: [sunos]
requiresBuild: true
dev: false
optional: true
/esbuild-windows-32/0.14.28:
resolution:
{
integrity: sha512-am9DIJxXlld1BOAY/VlvBQHMUCPL7S3gB/lnXIY3M4ys0gfuRqPf4EvMwZMzYUbFKBY+/Qb8SRgPRRGhwnJ8Kg==,
}
engines: { node: '>=12' }
cpu: [ia32]
os: [win32]
requiresBuild: true
dev: false
optional: true
/esbuild-windows-64/0.14.28:
resolution:
{
integrity: sha512-78PhySDnmRZlsPNp/W/5Fim8iivlBQQxfhBFIqR7xwvfDmCFUSByyMKP7LCHgNtb04yNdop8nJJkJaQ8Xnwgiw==,
}
engines: { node: '>=12' }
cpu: [x64]
os: [win32]
requiresBuild: true
dev: false
optional: true
/esbuild-windows-arm64/0.14.28:
resolution:
{
integrity: sha512-VhXGBTo6HELD8zyHXynV6+L2jWx0zkKnGx4TmEdSBK7UVFACtOyfUqpToG0EtnYyRZ0HESBhzPSVpP781ovmvA==,
}
engines: { node: '>=12' }
cpu: [arm64]
os: [win32]
requiresBuild: true
dev: false
optional: true
/esbuild/0.14.28:
resolution:
{
integrity: sha512-YLNprkCcMVKQ5sekmCKEQ3Obu/L7s6+iij38xNKyBeSmSsTWur4Ky/9zB3XIGT8SCJITG/bZwAR2l7YOAXch4Q==,
}
engines: { node: '>=12' }
hasBin: true
requiresBuild: true
optionalDependencies:
esbuild-android-64: 0.14.28
esbuild-android-arm64: 0.14.28
esbuild-darwin-64: 0.14.28
esbuild-darwin-arm64: 0.14.28
esbuild-freebsd-64: 0.14.28
esbuild-freebsd-arm64: 0.14.28
esbuild-linux-32: 0.14.28
esbuild-linux-64: 0.14.28
esbuild-linux-arm: 0.14.28
esbuild-linux-arm64: 0.14.28
esbuild-linux-mips64le: 0.14.28
esbuild-linux-ppc64le: 0.14.28
esbuild-linux-riscv64: 0.14.28
esbuild-linux-s390x: 0.14.28
esbuild-netbsd-64: 0.14.28
esbuild-openbsd-64: 0.14.28
esbuild-sunos-64: 0.14.28
esbuild-windows-32: 0.14.28
esbuild-windows-64: 0.14.28
esbuild-windows-arm64: 0.14.28
dev: false
/form-data/3.0.1:
resolution:
{
integrity: sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==,
}
engines: { node: '>= 6' }
dependencies:
asynckit: 0.4.0
combined-stream: 1.0.8
mime-types: 2.1.35
dev: true
/form-data/4.0.0:
resolution:
{
integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==,
}
engines: { node: '>= 6' }
dependencies:
asynckit: 0.4.0
combined-stream: 1.0.8
mime-types: 2.1.35
dev: true
/mime-db/1.52.0:
resolution:
{
integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==,
}
engines: { node: '>= 0.6' }
dev: true
/mime-types/2.1.35:
resolution:
{
integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==,
}
engines: { node: '>= 0.6' }
dependencies:
mime-db: 1.52.0
dev: true
/node-fetch/2.6.7:
resolution:
{
integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==,
}
engines: { node: 4.x || >=6.0.0 }
peerDependencies:
encoding: ^0.1.0
peerDependenciesMeta:
encoding:
optional: true
dependencies:
whatwg-url: 5.0.0
dev: true
/prettier/2.6.2:
resolution:
{
integrity: sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==,
}
engines: { node: '>=10.13.0' }
hasBin: true
dev: true
/tr46/0.0.3:
resolution: { integrity: sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o= }
dev: true
/ts-mixer/6.0.1:
resolution:
{
integrity: sha512-hvE+ZYXuINrx6Ei6D6hz+PTim0Uf++dYbK9FFifLNwQj+RwKquhQpn868yZsCtJYiclZF1u8l6WZxxKi+vv7Rg==,
}
dev: true
/tslib/2.3.1:
resolution:
{
integrity: sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==,
}
dev: true
/typescript/4.6.3:
resolution:
{
integrity: sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==,
}
engines: { node: '>=4.2.0' }
hasBin: true
dev: true
/webidl-conversions/3.0.1:
resolution: { integrity: sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE= }
dev: true
/whatwg-url/5.0.0:
resolution: { integrity: sha1-lmRU6HZUYuN2RNNib2dCzotwll0= }
dependencies:
tr46: 0.0.3
webidl-conversions: 3.0.1
dev: true
/ws/8.5.0:
resolution:
{
integrity: sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==,
}
engines: { node: '>=10.0.0' }
peerDependencies:
bufferutil: ^4.0.1
utf-8-validate: ^5.0.2
peerDependenciesMeta:
bufferutil:
optional: true
utf-8-validate:
optional: true
dev: true
/zod/3.14.3:
resolution:
{
integrity: sha512-OzwRCSXB1+/8F6w6HkYHdbuWysYWnAF4fkRgKDcSFc54CE+Sv0rHXKfeNUReGCrHukm1LNpi6AYeXotznhYJbQ==,
}
dev: true
+52
View File
@@ -0,0 +1,52 @@
/*
initGlobalStorage()
initChannelStorage(channel/channels)
channelStorage(channel) => Storage
Storage {
get() => string
set(string | json)
getJson() => json
}
*/
import { JSONObject } from './util'
class StorageBase {
val: string
fallbackJSON: JSONObject
constructor(val: string | JSONObject, fallbackJSON?: JSONObject) {
if (typeof val !== 'string') {
val = JSON.stringify(val)
}
if (fallbackJSON === undefined) {
fallbackJSON = val.constructor() as JSONObject
}
this.val = val
this.fallbackJSON = fallbackJSON
}
set(val: string | JSONObject) {
if (typeof val !== 'string') {
val = JSON.stringify(val)
}
this.val = val
}
get(): string {
return this.val
}
getJson(): JSONObject {
let val
try {
val = JSON.parse(this.val)
} catch (e) {
val = {}
}
return val
}
}
+4
View File
@@ -0,0 +1,4 @@
export type JSONDataTypes = string | number | boolean
export type JSONObject<Value = JSONDataTypes, Key extends string = string> = {
[key in Key]: Value
}
+11
View File
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"declaration": true,
"outDir": "./lib",
"strict": true
},
"include": ["src"],
"exclude": ["node_modules"]
}