@paralect/hive 0.1.48 → 0.1.50-alpha.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/.cursor/commands/deslop.md +12 -0
- package/.hive/.babelrc +3 -0
- package/.hive/.cursor/commands/add-endpoint.md +262 -0
- package/.hive/.cursor/commands/add-handler.md +137 -0
- package/.hive/.cursor/commands/add-middleware.md +95 -0
- package/.hive/.cursor/commands/add-resource.md +71 -0
- package/.hive/.cursor/commands/add-scheduler.md +138 -0
- package/.hive/.cursor/commands/add-service.md +188 -0
- package/.hive/.cursor/skills/hive-auth/SKILL.md +134 -0
- package/.hive/.cursor/skills/hive-database/SKILL.md +103 -0
- package/.hive/.cursor/skills/hive-endpoint/SKILL.md +103 -0
- package/.hive/.cursor/skills/hive-handler/SKILL.md +88 -0
- package/.hive/.cursor/skills/hive-mapping/SKILL.md +85 -0
- package/.hive/.cursor/skills/hive-middleware/SKILL.md +104 -0
- package/.hive/.cursor/skills/hive-overview/SKILL.md +50 -0
- package/.hive/.cursor/skills/hive-scheduler/SKILL.md +94 -0
- package/.hive/.cursor/skills/hive-schema/SKILL.md +73 -0
- package/.hive/.cursor/skills/hive-service/SKILL.md +90 -0
- package/.hive/.dockerignore +1 -0
- package/.hive/Dockerfile +22 -0
- package/.hive/Dockerfile.dev +33 -0
- package/.hive/Dockerfile.prod +29 -0
- package/.hive/README.md +11 -0
- package/.hive/bin/deploy.sh +5 -0
- package/.hive/bin/start.sh +2 -0
- package/.hive/bootstrap-hive.js +118 -0
- package/.hive/deploy/api/Chart.yaml +6 -0
- package/.hive/deploy/api/staging.yaml +3 -0
- package/.hive/deploy/api/templates/deployment.yaml +44 -0
- package/.hive/deploy/api/templates/ingress.yaml +26 -0
- package/.hive/deploy/api/templates/service.yaml +14 -0
- package/.hive/deploy/script/Dockerfile +39 -0
- package/.hive/deploy/script/package-lock.json +1499 -0
- package/.hive/deploy/script/package.json +12 -0
- package/.hive/deploy/script/src/config.js +48 -0
- package/.hive/deploy/script/src/index.js +108 -0
- package/.hive/deploy/script/src/util.js +19 -0
- package/.hive/initial-data.json +176 -0
- package/.hive/package-lock.json +10242 -0
- package/.hive/package.json +98 -0
- package/.hive/ship_logo.png +0 -0
- package/.hive/src/app-config/app.js +3 -0
- package/.hive/src/app-config/assertEnv.js +15 -0
- package/.hive/src/app-config/index.js +62 -0
- package/.hive/src/app.js +69 -0
- package/.hive/src/assets/emails/components/header.mjml +13 -0
- package/.hive/src/assets/emails/dist/.gitkeep +0 -0
- package/.hive/src/assets/emails/signup-welcome.mjml +34 -0
- package/.hive/src/assets/emails/styles/index.mjml +77 -0
- package/.hive/src/autoMap/addHandlers.js +142 -0
- package/.hive/src/autoMap/getDependentFields.js +37 -0
- package/.hive/src/autoMap/mapSchema.js +99 -0
- package/.hive/src/autoMap/schemaMappings.js +13 -0
- package/.hive/src/autoMap/schemaMappings.json +3 -0
- package/.hive/src/bullMqBus.js +21 -0
- package/.hive/src/bullMqWrapper.js +23 -0
- package/.hive/src/db.js +52 -0
- package/.hive/src/emails/MyEmailComponent.jsx +14 -0
- package/.hive/src/emails/compiled/MyEmailComponent.js +18 -0
- package/.hive/src/emails/compiled/compiled/MyEmailComponent.js +18 -0
- package/.hive/src/helpers/db/ifUpdated.js +22 -0
- package/.hive/src/helpers/getMiddlewares.js +38 -0
- package/.hive/src/helpers/getResourceEndpoints.js +28 -0
- package/.hive/src/helpers/getResources.js +32 -0
- package/.hive/src/helpers/getSchemas.js +50 -0
- package/.hive/src/helpers/importHandlers.js +29 -0
- package/.hive/src/helpers/isZodArray.js +13 -0
- package/.hive/src/helpers/prettierFormat.js +8 -0
- package/.hive/src/helpers/schema/db.schema.js +9 -0
- package/.hive/src/helpers/schema/pagination.schema.js +14 -0
- package/.hive/src/ioEmitter.js +9 -0
- package/.hive/src/jsconfig.json +5 -0
- package/.hive/src/lib/node-mongo/.github/workflows/npm-publish.yml +32 -0
- package/.hive/src/lib/node-mongo/API.md +654 -0
- package/.hive/src/lib/node-mongo/CHANGELOG.md +98 -0
- package/.hive/src/lib/node-mongo/README.md +97 -0
- package/.hive/src/lib/node-mongo/package-lock.json +3682 -0
- package/.hive/src/lib/node-mongo/package.json +74 -0
- package/.hive/src/lib/node-mongo/src/index.js +64 -0
- package/.hive/src/lib/node-mongo/src/mongo-query-service.js +78 -0
- package/.hive/src/lib/node-mongo/src/mongo-service-error.js +15 -0
- package/.hive/src/lib/node-mongo/src/mongo-service.js +303 -0
- package/.hive/src/logger.js +43 -0
- package/.hive/src/middlewares/allowNoAuth.js +9 -0
- package/.hive/src/middlewares/attachUser.js +41 -0
- package/.hive/src/middlewares/global/extractUserTokens.js +15 -0
- package/.hive/src/middlewares/global/tryToAttachUser.js +33 -0
- package/.hive/src/middlewares/isAuthorized.js +18 -0
- package/.hive/src/middlewares/shouldExist.js +37 -0
- package/.hive/src/middlewares/shouldNotExist.js +19 -0
- package/.hive/src/middlewares/uploadFile.js +5 -0
- package/.hive/src/middlewares/validate.js +32 -0
- package/.hive/src/migrations/migration.js +8 -0
- package/.hive/src/migrations/migration.service.js +73 -0
- package/.hive/src/migrations/migrations/1.js +22 -0
- package/.hive/src/migrations/migrations-log/migration-log.schema.js +13 -0
- package/.hive/src/migrations/migrations-log/migration-log.service.js +50 -0
- package/.hive/src/migrations/migrations.schema.js +6 -0
- package/.hive/src/migrations/migrator.js +75 -0
- package/.hive/src/migrator.js +4 -0
- package/.hive/src/resources/_dev/endpoints/triggerSchedulerHandler.js +32 -0
- package/.hive/src/resources/health/endpoints/get.js +19 -0
- package/.hive/src/resources/schemaMappings/schemaMappings.schema.js +6 -0
- package/.hive/src/resources/tokens/methods/generateSecureToken.js +9 -0
- package/.hive/src/resources/tokens/methods/setToken.js +8 -0
- package/.hive/src/resources/tokens/methods/storeToken.js +35 -0
- package/.hive/src/resources/tokens/tokens.schema.js +11 -0
- package/.hive/src/resources/users/endpoints/getCurrentUser.js +14 -0
- package/.hive/src/resources/users/endpoints/getUserProfile.js +19 -0
- package/.hive/src/resources/users/handlers/test.js +1 -0
- package/.hive/src/resources/users/methods/ensureUserCreated.js +68 -0
- package/.hive/src/resources/users/users.schema.js +16 -0
- package/.hive/src/routes/index.js +172 -0
- package/.hive/src/routes/middlewares/attachCustomErrors.js +28 -0
- package/.hive/src/routes/middlewares/routeErrorHandler.js +27 -0
- package/.hive/src/scheduler/handlers/sendDailyReport.example.js +7 -0
- package/.hive/src/scheduler.js +32 -0
- package/.hive/src/security.util.js +38 -0
- package/.hive/src/services/emailService.js +15 -0
- package/.hive/src/services/globalTest.js +0 -0
- package/.hive/src/services/setCookie.js +21 -0
- package/.hive/src/socketIo.js +99 -0
- package/.hive/tsconfig.json +31 -0
- package/AGENTS.md +96 -0
- package/README.md +271 -0
- package/cli/helpers/docker.js +59 -0
- package/cli/helpers/envCheck.js +123 -0
- package/cli/helpers/findPort.js +32 -0
- package/cli/hive.js +155 -15
- package/package.json +1 -1
- package/starter/.cursor/commands/add-endpoint.md +262 -0
- package/starter/.cursor/commands/add-handler.md +137 -0
- package/starter/.cursor/commands/add-middleware.md +95 -0
- package/starter/.cursor/commands/add-resource.md +71 -0
- package/starter/.cursor/commands/add-scheduler.md +138 -0
- package/starter/.cursor/commands/add-service.md +188 -0
- package/starter/.cursor/skills/hive-auth/SKILL.md +134 -0
- package/starter/.cursor/skills/hive-database/SKILL.md +103 -0
- package/starter/.cursor/skills/hive-endpoint/SKILL.md +103 -0
- package/starter/.cursor/skills/hive-handler/SKILL.md +88 -0
- package/starter/.cursor/skills/hive-mapping/SKILL.md +85 -0
- package/starter/.cursor/skills/hive-middleware/SKILL.md +104 -0
- package/starter/.cursor/skills/hive-overview/SKILL.md +50 -0
- package/starter/.cursor/skills/hive-scheduler/SKILL.md +94 -0
- package/starter/.cursor/skills/hive-schema/SKILL.md +73 -0
- package/starter/.cursor/skills/hive-service/SKILL.md +90 -0
- package/starter/src/app.js +4 -3
- package/test-app/.cursor/commands/add-endpoint.md +262 -0
- package/test-app/.cursor/commands/add-handler.md +137 -0
- package/test-app/.cursor/commands/add-middleware.md +95 -0
- package/test-app/.cursor/commands/add-resource.md +71 -0
- package/test-app/.cursor/commands/add-scheduler.md +138 -0
- package/test-app/.cursor/commands/add-service.md +188 -0
- package/test-app/.cursor/skills/hive-auth/SKILL.md +134 -0
- package/test-app/.cursor/skills/hive-database/SKILL.md +103 -0
- package/test-app/.cursor/skills/hive-endpoint/SKILL.md +103 -0
- package/test-app/.cursor/skills/hive-handler/SKILL.md +88 -0
- package/test-app/.cursor/skills/hive-mapping/SKILL.md +85 -0
- package/test-app/.cursor/skills/hive-middleware/SKILL.md +104 -0
- package/test-app/.cursor/skills/hive-overview/SKILL.md +50 -0
- package/test-app/.cursor/skills/hive-scheduler/SKILL.md +94 -0
- package/test-app/.cursor/skills/hive-schema/SKILL.md +73 -0
- package/test-app/.cursor/skills/hive-service/SKILL.md +90 -0
- package/test-app/package-lock.json +8684 -0
- package/test-app/package.json +21 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import config from 'app-config';
|
|
2
|
+
import bullMq from './bullMq';
|
|
3
|
+
const queue = bullMq.Queue(`database-${config.env}`);
|
|
4
|
+
|
|
5
|
+
let handlers = {};
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
on(eventName, handler) {
|
|
9
|
+
console.log('registering', eventName);
|
|
10
|
+
|
|
11
|
+
handlers[eventName] = handlers[eventName] || [];
|
|
12
|
+
handlers[eventName].push(handler);
|
|
13
|
+
},
|
|
14
|
+
emit(eventName, data) {
|
|
15
|
+
queue.add(eventName, data);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
bullMq.Worker(`database-${config.env}`, async ({ name: eventName, data }) => {
|
|
20
|
+
await Promise.all((handlers[eventName] || []).map(h => h(data)));
|
|
21
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import config from 'app-config';
|
|
2
|
+
import { Queue, Worker } from 'bullMq';
|
|
3
|
+
|
|
4
|
+
let connectionOpts = {
|
|
5
|
+
host: config.redis.url.split('@')[1].split(':')[0],
|
|
6
|
+
port: config.redis.url.split('@')[1].split(':')[1],
|
|
7
|
+
username: 'default',
|
|
8
|
+
password: config.redis.url.split(':')[2].split('@')[0],
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
Queue(queueName) {
|
|
13
|
+
return new Queue(queueName, {
|
|
14
|
+
connection: connectionOpts,
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
Worker(queueName, workerFn, options = {}) {
|
|
18
|
+
return new Worker(queueName, workerFn, {
|
|
19
|
+
...options,
|
|
20
|
+
connection: connectionOpts,
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
};
|
package/.hive/src/db.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import _ from "lodash";
|
|
3
|
+
import getSchemas from "helpers/getSchemas";
|
|
4
|
+
import getResources from "helpers/getResources";
|
|
5
|
+
import importHandlers from "helpers/importHandlers";
|
|
6
|
+
import config from "app-config";
|
|
7
|
+
import { connect } from "lib/node-mongo";
|
|
8
|
+
|
|
9
|
+
const db = connect(config.mongoUri);
|
|
10
|
+
|
|
11
|
+
db.services = {};
|
|
12
|
+
db.schemas = {};
|
|
13
|
+
|
|
14
|
+
db.init = async () => {
|
|
15
|
+
const schemaPaths = await getSchemas();
|
|
16
|
+
|
|
17
|
+
await Promise.all(_.map(
|
|
18
|
+
schemaPaths,
|
|
19
|
+
async ({ file: schemaFile, resourceName, name: schemaName }) => {
|
|
20
|
+
let { default: schema, secureFields = [] } = (await import(schemaFile));
|
|
21
|
+
|
|
22
|
+
if (process.env.HIVE_SRC) {
|
|
23
|
+
let extendSchemaPath = `${process.env.HIVE_SRC}/resources/${resourceName}/${schemaName}.extends.schema.js`;
|
|
24
|
+
if (fs.existsSync(extendSchemaPath)) {
|
|
25
|
+
let extendsSchema = (await import(extendSchemaPath)).default;
|
|
26
|
+
schema = schema.append(extendsSchema);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
db.schemas[schemaName] = schema;
|
|
30
|
+
|
|
31
|
+
db.services[schemaName] = db.createService(`${resourceName}`, {
|
|
32
|
+
validate: (obj) => {
|
|
33
|
+
return { value: schema.parse(obj) };
|
|
34
|
+
},
|
|
35
|
+
secureFields: secureFields,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
));
|
|
39
|
+
|
|
40
|
+
const resourcePaths = await getResources();
|
|
41
|
+
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
_.each(resourcePaths, ({ name }) => {
|
|
44
|
+
importHandlers(name)
|
|
45
|
+
});
|
|
46
|
+
}, 0);
|
|
47
|
+
|
|
48
|
+
(await import("autoMap/addHandlers")).default();
|
|
49
|
+
(await import("autoMap/mapSchema")).default();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default db;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const React = require('react');
|
|
2
|
+
const { Html, Head, Body, Container, Heading, Text } = require('@react-email/components');
|
|
3
|
+
|
|
4
|
+
export const MyEmailComponent = ({ name }) => (
|
|
5
|
+
<Html>
|
|
6
|
+
<Head />
|
|
7
|
+
<Body>
|
|
8
|
+
<Container>
|
|
9
|
+
<Heading>Hello, {name}!</Heading>
|
|
10
|
+
<Text>This is a test email using @react-email and Express.</Text>
|
|
11
|
+
</Container>
|
|
12
|
+
</Body>
|
|
13
|
+
</Html>
|
|
14
|
+
);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MyEmailComponent = void 0;
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var _require = require('@react-email/components'),
|
|
9
|
+
Html = _require.Html,
|
|
10
|
+
Head = _require.Head,
|
|
11
|
+
Body = _require.Body,
|
|
12
|
+
Container = _require.Container,
|
|
13
|
+
Heading = _require.Heading,
|
|
14
|
+
Text = _require.Text;
|
|
15
|
+
var MyEmailComponent = exports.MyEmailComponent = function MyEmailComponent(_ref) {
|
|
16
|
+
var name = _ref.name;
|
|
17
|
+
return /*#__PURE__*/React.createElement(Html, null, /*#__PURE__*/React.createElement(Head, null), /*#__PURE__*/React.createElement(Body, null, /*#__PURE__*/React.createElement(Container, null, /*#__PURE__*/React.createElement(Heading, null, "Hello, ", name, "!"), /*#__PURE__*/React.createElement(Text, null, "This is a test email using @react-email and Express."))));
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MyEmailComponent = void 0;
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var _require = require('@react-email/components'),
|
|
9
|
+
Html = _require.Html,
|
|
10
|
+
Head = _require.Head,
|
|
11
|
+
Body = _require.Body,
|
|
12
|
+
Container = _require.Container,
|
|
13
|
+
Heading = _require.Heading,
|
|
14
|
+
Text = _require.Text;
|
|
15
|
+
var MyEmailComponent = exports.MyEmailComponent = function MyEmailComponent(_ref) {
|
|
16
|
+
var name = _ref.name;
|
|
17
|
+
return /*#__PURE__*/React.createElement(Html, null, /*#__PURE__*/React.createElement(Head, null), /*#__PURE__*/React.createElement(Body, null, /*#__PURE__*/React.createElement(Container, null, /*#__PURE__*/React.createElement(Heading, null, "Hello, ", name, "!"), /*#__PURE__*/React.createElement(Text, null, "This is a test email using @react-email and Express."))));
|
|
18
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
|
|
3
|
+
export default (fieldNames, callback) => {
|
|
4
|
+
return async ({ doc, prevDoc }) => {
|
|
5
|
+
let isFieldChanged = false;
|
|
6
|
+
|
|
7
|
+
_.forEach(fieldNames, (fieldName) => {
|
|
8
|
+
if (!_.isEqual(doc[fieldName], prevDoc[fieldName])) {
|
|
9
|
+
isFieldChanged = true;
|
|
10
|
+
return false; // break loop
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return true;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
if (isFieldChanged) {
|
|
17
|
+
return callback({ doc, prevDoc });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return () => {};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
promises: { readdir },
|
|
7
|
+
} = fs;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const getFiles = async (source) => {
|
|
11
|
+
return (await readdir(source, { withFileTypes: true }))
|
|
12
|
+
.filter((file) => !file.isDirectory())
|
|
13
|
+
.map((file) => ({ fileName: file.name }));
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default async () => {
|
|
17
|
+
let middlewaresDirs = await getFiles(`${__dirname}/../middlewares`);
|
|
18
|
+
|
|
19
|
+
if (process.env.HIVE_SRC) {
|
|
20
|
+
let hiveMiddlewaresDirPath = `${process.env.HIVE_SRC}/middlewares`;
|
|
21
|
+
|
|
22
|
+
if (fs.existsSync(hiveMiddlewaresDirPath)) {
|
|
23
|
+
middlewaresDirs = _.uniqBy([...middlewaresDirs, ...((await getFiles(hiveMiddlewaresDirPath)).map(r => ({ fileName: r.fileName, isHive: true })))], r => r.fileName);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return Promise.all(middlewaresDirs
|
|
28
|
+
.map(({ fileName, isHive }) => ({
|
|
29
|
+
filePath: isHive ? path.resolve(`${process.env.HIVE_SRC}/middlewares/${fileName}`) : path.resolve(`${__dirname}/../middlewares/${fileName}`),
|
|
30
|
+
name: fileName.replace('.js', ''),
|
|
31
|
+
})).map(async ({ filePath, name }) => {
|
|
32
|
+
return {
|
|
33
|
+
name,
|
|
34
|
+
filePath,
|
|
35
|
+
fn: (await import(filePath)).default,
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
promises: { readdir },
|
|
6
|
+
} = fs;
|
|
7
|
+
|
|
8
|
+
export default async (resourceName) => {
|
|
9
|
+
let endpointFiles = [];
|
|
10
|
+
|
|
11
|
+
if (fs.existsSync(`${process.env.HIVE_SRC}/resources/${resourceName}/endpoints`)) {
|
|
12
|
+
endpointFiles = [...endpointFiles, ...(await readdir(
|
|
13
|
+
`${process.env.HIVE_SRC}/resources/${resourceName}/endpoints`
|
|
14
|
+
)).map( f => ({ name: f, isHiveEndpoint: true}))];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (fs.existsSync(`${__dirname}/../resources/${resourceName}/endpoints`)) {
|
|
18
|
+
endpointFiles = [...endpointFiles, ...(await readdir(
|
|
19
|
+
`${__dirname}/../resources/${resourceName}/endpoints`
|
|
20
|
+
)).map( f => ({ name: f }))];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return endpointFiles.map(({ name, isHiveEndpoint }) => ({
|
|
24
|
+
file: isHiveEndpoint ? `${process.env.HIVE_SRC}/resources/${resourceName}/endpoints/${name}`: `${__dirname}/../resources/${resourceName}/endpoints/${name}`,
|
|
25
|
+
name: _.last(name.split("/")).replace(".js", ""),
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
promises: { readdir },
|
|
7
|
+
} = fs;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const getDirectories = async (source) => {
|
|
11
|
+
return (await readdir(source, { withFileTypes: true }))
|
|
12
|
+
.filter((dir) => dir.isDirectory())
|
|
13
|
+
.map((dir) => ({ dirName: dir.name }));
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default async () => {
|
|
17
|
+
let resourceDirs = await getDirectories(`${__dirname}/../resources`);
|
|
18
|
+
|
|
19
|
+
if (process.env.HIVE_SRC) {
|
|
20
|
+
let hiveResourcesDirPath = `${process.env.HIVE_SRC}/resources`;
|
|
21
|
+
|
|
22
|
+
if (fs.existsSync(hiveResourcesDirPath)) {
|
|
23
|
+
resourceDirs = _.uniqBy([...resourceDirs, ...((await getDirectories(hiveResourcesDirPath)).map(r => ({ dirName: r.dirName, isHive: true })))], r => r.dirName);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return resourceDirs
|
|
28
|
+
.filter(({ dirName }) => dirName !== "health")
|
|
29
|
+
.map(({ dirName }) => ({
|
|
30
|
+
name: dirName,
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import fs, { promises } from "fs";
|
|
3
|
+
import getResources from "./getResources.js";
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
promises: { readdir },
|
|
7
|
+
} = { promises };
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const getSchemas = async (resourceDir) => {
|
|
11
|
+
return (await readdir(resourceDir))
|
|
12
|
+
.filter((f) => f.includes("schema.js"))
|
|
13
|
+
.filter((f) => !f.includes("extends.schema"))
|
|
14
|
+
.map((f) => ({
|
|
15
|
+
name: f.replace(".schema.js", ""),
|
|
16
|
+
file: `${resourceDir}/${f}`,
|
|
17
|
+
resourceName: _.last(resourceDir.split('/')),
|
|
18
|
+
isHive: process.env.HIVE_SRC && resourceDir.includes(process.env.HIVE_SRC),
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const getResourceSchemas = async (resourceName) => {
|
|
23
|
+
let schemaFiles = [];
|
|
24
|
+
|
|
25
|
+
if (fs.existsSync(`${process.env.HIVE_SRC}/resources/${resourceName}`)) {
|
|
26
|
+
schemaFiles = (await getSchemas(`${process.env.HIVE_SRC}/resources/${resourceName}`));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (fs.existsSync(`${__dirname}/../resources/${resourceName}`)) {
|
|
30
|
+
schemaFiles = [...schemaFiles, ...(await getSchemas(`${__dirname}/../resources/${resourceName}`)).filter(schema => !schemaFiles.find(s => s.name === schema.name))];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return schemaFiles;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default async () => {
|
|
37
|
+
const resources = await getResources();
|
|
38
|
+
let schemas = [];
|
|
39
|
+
|
|
40
|
+
await Promise.all(
|
|
41
|
+
resources.map(async ({ name: resourceName }) => {
|
|
42
|
+
const resourceSchemas = await getResourceSchemas(resourceName);
|
|
43
|
+
schemas.push(...resourceSchemas);
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
console.log('schemas', schemas);
|
|
48
|
+
|
|
49
|
+
return schemas;
|
|
50
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import requireDir from "require-dir";
|
|
4
|
+
|
|
5
|
+
export default (resourceName) => {
|
|
6
|
+
if (fs.existsSync(`${process.env.HIVE_SRC}/resources/${resourceName}/handlers`)) {
|
|
7
|
+
requireDir(`${process.env.HIVE_SRC}/resources/${resourceName}/handlers`, {
|
|
8
|
+
mapValue: (handler, handlerName) => {
|
|
9
|
+
console.log(
|
|
10
|
+
`[handlers] Registering handler ${handlerName}`
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
return handler;
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (fs.existsSync(`${__dirname}/../resources/${resourceName}/handlers`)) {
|
|
19
|
+
requireDir(`${__dirname}/../resources/${resourceName}/handlers`, {
|
|
20
|
+
mapValue: (handler, handlerName) => {
|
|
21
|
+
console.log(
|
|
22
|
+
`[handlers] Registering handler ${handlerName}`
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return handler;
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ZodArray } from 'zod';
|
|
2
|
+
|
|
3
|
+
const isZodArray = (schema) => {
|
|
4
|
+
if (schema instanceof ZodArray) return true;
|
|
5
|
+
|
|
6
|
+
if (schema._def?.innerType) {
|
|
7
|
+
return isZodArray(schema._def.innerType);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return false;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default isZodArray;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const paginationSchema = z.object({
|
|
4
|
+
page: z.coerce.number().default(1),
|
|
5
|
+
perPage: z.coerce.number().default(10),
|
|
6
|
+
|
|
7
|
+
searchValue: z.string().optional(),
|
|
8
|
+
|
|
9
|
+
sort: z
|
|
10
|
+
.object({
|
|
11
|
+
createdOn: z.enum(['asc', 'desc']).default('asc'),
|
|
12
|
+
})
|
|
13
|
+
.default({}),
|
|
14
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import config from 'app-config';
|
|
2
|
+
import { Emitter } from '@socket.io/redis-emitter';
|
|
3
|
+
import { createClient } from 'redis';
|
|
4
|
+
|
|
5
|
+
const redisClient = createClient({ url: config.redis.url });
|
|
6
|
+
|
|
7
|
+
const emitter = new Emitter(redisClient);
|
|
8
|
+
|
|
9
|
+
export default emitter;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
+
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Node.js Package
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [created]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v2
|
|
15
|
+
- uses: actions/setup-node@v1
|
|
16
|
+
with:
|
|
17
|
+
node-version: 12
|
|
18
|
+
- run: npm ci
|
|
19
|
+
|
|
20
|
+
publish-npm:
|
|
21
|
+
needs: build
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v2
|
|
25
|
+
- uses: actions/setup-node@v1
|
|
26
|
+
with:
|
|
27
|
+
node-version: 12
|
|
28
|
+
registry-url: https://registry.npmjs.org/
|
|
29
|
+
- run: npm ci
|
|
30
|
+
- run: npm publish
|
|
31
|
+
env:
|
|
32
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|