create-dacosta-proj 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env.template ADDED
@@ -0,0 +1,16 @@
1
+ # Project
2
+
3
+ PROJECT_ID=
4
+
5
+ # Supabase
6
+
7
+ SUPABASE_PROJECT_URL=
8
+ SUPABASE_SECRET_KEY=
9
+
10
+ # Bypass API
11
+
12
+ API_BYPASS_TOKEN=
13
+
14
+ # Encryption
15
+
16
+ ENCRYPTION_KEY=
package/devref.json ADDED
@@ -0,0 +1 @@
1
+ true
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from "eslint/config";
2
+
3
+ export default defineConfig([{
4
+ languageOptions: {
5
+ globals: {},
6
+ ecmaVersion: "latest",
7
+ sourceType: "script",
8
+ },
9
+
10
+ rules: {
11
+ indent: ["error", "tab"],
12
+ "linebreak-style": ["error", "unix"],
13
+ quotes: ["error", "single"],
14
+ semi: ["error", "always"],
15
+ },
16
+ }]);
package/jsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "paths": {
5
+ "@/*": ["src/*"]
6
+ }
7
+ },
8
+ "include": ["src"]
9
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "create-dacosta-proj",
3
+ "version": "1.0.0",
4
+ "bin": {
5
+ "create-dacosta-proj": "./src/index.js"
6
+ },
7
+ "main": "src/index.js",
8
+ "scripts": {
9
+ "dev": "nodemon src/index.js",
10
+ "start": "node src/index.js"
11
+ },
12
+ "dependencies": {
13
+ "dotenv": "^17.3.1",
14
+ "generate-unique-id": "^2.0.3",
15
+ "redis": "^5.11.0",
16
+ "simple-supabase": "git+https://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:x-oauth-basic@github.com/itsgox/NM-Simple-Supabase.git"
17
+ },
18
+ "devDependencies": {
19
+ "eslint": "^9.39.3",
20
+ "module-alias": "^2.3.4",
21
+ "nodemon": "^3.1.13"
22
+ },
23
+ "_moduleAliases": {
24
+ "@": "src"
25
+ }
26
+ }
@@ -0,0 +1,53 @@
1
+ // Database Types
2
+
3
+ /**
4
+ * @callback dbGet
5
+ * @param {string} path
6
+ * @param {string} field
7
+ * @param {boolean} ignoreCache
8
+ * @returns {Promise<any>}
9
+ */
10
+
11
+ /**
12
+ * @callback dbSet
13
+ * @param {string} path
14
+ * @param {string} field
15
+ * @param {any} value
16
+ * @returns {Promise<any>}
17
+ */
18
+
19
+ /**
20
+ * @callback dbDeleteField
21
+ * @param {string} path
22
+ * @param {string} field
23
+ * @returns {Promise<any>}
24
+ */
25
+
26
+ /**
27
+ * @callback dbDeleteRow
28
+ * @param {string} path
29
+ * @returns {Promise<any>}
30
+ */
31
+
32
+ /**
33
+ * @typedef {Object} DB
34
+ * @property {dbGet} get
35
+ * @property {dbSet} set
36
+ * @property {dbDeleteField} deleteField
37
+ * @property {dbDeleteRow} deleteRow
38
+ */
39
+
40
+ // Global
41
+
42
+ /**
43
+ * @type {{
44
+ * db: DB,
45
+ * redis: import('redis').RedisClientType | null,
46
+ * }}
47
+ */
48
+
49
+ const global = {
50
+ db: null,
51
+ redis: null
52
+ };
53
+ module.exports = { global };
@@ -0,0 +1,15 @@
1
+ // Packages / Helpers
2
+
3
+ const generateUniqueId = require('generate-unique-id');
4
+ const redis = require('@/helpers/getRedis');
5
+
6
+ async function generateId(customLength) {
7
+ const id = generateUniqueId({ length: customLength || 32 });
8
+ const exists = await redis.exists(`${process.env.PROJECT_ID}_ids_${id}`);
9
+ if (exists) return await generateId(customLength);
10
+ else {
11
+ await redis.set(`${process.env.PROJECT_ID}_ids_${id}`, '.');
12
+ return id;
13
+ }
14
+ }
15
+ module.exports = { generateId };
@@ -0,0 +1,4 @@
1
+ const redis = require('redis');
2
+ const client = redis.createClient();
3
+ client.connect();
4
+ module.exports = client;
@@ -0,0 +1,3 @@
1
+ module.exports = async (ms) => {
2
+ return new Promise(resolve => setTimeout(resolve, ms));
3
+ };
package/src/index.js ADDED
@@ -0,0 +1,41 @@
1
+ // Global Tools
2
+
3
+ require('dotenv').config({ quiet: true });
4
+ require('module-alias/register');
5
+
6
+ // Packages / Helpers
7
+
8
+ const { SimpleSupabase } = require('simple-supabase');
9
+ const redis = require('@/helpers/getRedis');
10
+ const { global } = require('@/config/global');
11
+
12
+ // Start System
13
+
14
+ (async () => {
15
+
16
+ // Handle Errors
17
+
18
+ process.on('unhandledRejection', async (error) => console.log('Unhandled Rejection', error));
19
+ process.on('uncaughtException', async (error) => console.log('Uncaught Exception', error));
20
+
21
+ // Database / Redis
22
+
23
+ let db = await SimpleSupabase({
24
+ credentials: {
25
+ projectUrl: process.env.SUPABASE_PROJECT_URL,
26
+ serviceKey: process.env.SUPABASE_SECRET_KEY
27
+ },
28
+ clientOptions: {
29
+ auth: {
30
+ persistSession: false
31
+ }
32
+ },
33
+ redisPrefix: process.env.PROJECT_ID
34
+ });
35
+
36
+ global.db = db;
37
+ global.redis = redis;
38
+
39
+ // ------- Start Here -------
40
+
41
+ })();