@paralect/hive 0.1.50-alpha.3 → 0.1.50
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/.claude/settings.local.json +13 -0
- package/cli/helpers/execCommand.js +10 -10
- package/cli/helpers/isProjectInit.js +3 -3
- package/cli/helpers/mergeDirs.js +1 -1
- package/cli/hive.js +105 -105
- package/{test-app → framework}/.cursor/commands/add-service.md +6 -6
- package/{test-app → framework}/.cursor/skills/hive-overview/SKILL.md +1 -1
- package/{test-app → framework}/.cursor/skills/hive-service/SKILL.md +2 -2
- package/framework/bin/start.sh +2 -0
- package/{.hive/bootstrap-hive.js → framework/bootstrap-hive.ts} +4 -4
- package/{.hive → framework}/package-lock.json +212 -156
- package/framework/package.json +42 -0
- package/{.hive/src/app.js → framework/src/app.ts} +1 -1
- package/{.hive/src/bullMqBus.js → framework/src/bullMqBus.ts} +1 -1
- package/{.hive/src/bullMqWrapper.js → framework/src/bullMqWrapper.ts} +1 -1
- package/{.hive/src/app-config/index.js → framework/src/config/index.ts} +7 -7
- package/{.hive/src/db.js → framework/src/db.ts} +21 -6
- package/framework/src/endpoint.ts +132 -0
- package/framework/src/helpers/generateDbTypes.ts +47 -0
- package/{.hive/src/helpers/getMiddlewares.js → framework/src/helpers/getMiddlewares.ts} +1 -1
- package/{.hive/src/helpers/getResourceEndpoints.js → framework/src/helpers/getResourceEndpoints.ts} +8 -8
- package/{.hive/src/helpers/getResources.js → framework/src/helpers/getResources.ts} +1 -1
- package/{.hive/src/helpers/getSchemas.js → framework/src/helpers/getSchemas.ts} +13 -13
- package/framework/src/index.ts +3 -0
- package/{.hive/src/ioEmitter.js → framework/src/ioEmitter.ts} +1 -1
- package/{.hive/src/lib/node-mongo/src/mongo-query-service.js → framework/src/lib/node-mongo/src/mongo-query-service.ts} +18 -7
- package/{.hive/src/lib/node-mongo/src/mongo-service.js → framework/src/lib/node-mongo/src/mongo-service.ts} +17 -9
- package/{starter/src/logger.js → framework/src/logger.ts} +4 -3
- package/{.hive/src/migrations/migrations-log/migration-log.schema.js → framework/src/migrations/migrations-log/migration-log.schema.ts} +1 -1
- package/{.hive/src/migrations/migrations-log/migration-log.service.js → framework/src/migrations/migrations-log/migration-log.service.ts} +1 -1
- package/{.hive/src/migrations/migrations.schema.js → framework/src/migrations/migrations.schema.ts} +1 -1
- package/{.hive/src/resources/_dev/endpoints/triggerSchedulerHandler.js → framework/src/resources/_dev/endpoints/triggerSchedulerHandler.ts} +2 -1
- package/framework/src/resources/health/endpoints/get.ts +14 -0
- package/{.hive/src/resources/schemaMappings/schemaMappings.schema.js → framework/src/resources/schemaMappings/schemaMappings.schema.ts} +1 -1
- package/{.hive/src/routes/index.js → framework/src/routes/index.ts} +23 -27
- package/framework/src/schema.ts +3 -0
- package/{.hive/src/services/emailService.js → framework/src/services/emailService.ts} +1 -1
- package/{.hive/src/socketIo.js → framework/src/socketIo.ts} +1 -1
- package/{.hive → framework}/tsconfig.json +17 -13
- package/package.json +43 -51
- package/starter/hive/autoMap/schemaMappings.json +1 -0
- package/starter/hive/config/.env.example +11 -0
- package/starter/hive/config/app.ts +19 -0
- package/{.hive/src/services/setCookie.js → starter/hive/helpers/setCookie.ts} +1 -2
- package/starter/hive/middlewares/_global.ts +9 -0
- package/{.hive/src/middlewares/attachUser.js → starter/hive/middlewares/attachUser.ts} +2 -2
- package/{.hive/src/middlewares/shouldExist.js → starter/hive/middlewares/shouldExist.ts} +1 -1
- package/{.hive/src/middlewares/shouldNotExist.js → starter/hive/middlewares/shouldNotExist.ts} +1 -1
- package/starter/hive/resources/files/endpoints/upload.ts +25 -0
- package/starter/hive/resources/files/files.schema.ts +20 -0
- package/{.hive/src/resources/tokens/methods/storeToken.js → starter/hive/resources/tokens/methods/storeToken.ts} +3 -3
- package/{.hive/src/resources/tokens/tokens.schema.js → starter/hive/resources/tokens/tokens.schema.ts} +1 -2
- package/starter/hive/resources/users/endpoints/getCurrentUser.ts +12 -0
- package/starter/hive/resources/users/endpoints/getUserProfile.ts +17 -0
- package/{.hive/src/resources/users/users.schema.js → starter/hive/resources/users/users.schema.ts} +1 -2
- package/starter/hive/services/cloudStorage.ts +102 -0
- package/starter/package.json +9 -98
- package/starter/tsconfig.json +16 -20
- package/.cursor/commands/deslop.md +0 -12
- package/.hive/.cursor/commands/add-service.md +0 -188
- package/.hive/.cursor/skills/hive-overview/SKILL.md +0 -50
- package/.hive/.cursor/skills/hive-service/SKILL.md +0 -90
- package/.hive/bin/start.sh +0 -2
- package/.hive/package.json +0 -98
- package/.hive/src/logger.js +0 -43
- package/.hive/src/middlewares/global/tryToAttachUser.js +0 -33
- package/.hive/src/resources/health/endpoints/get.js +0 -19
- package/.hive/src/resources/tokens/methods/setToken.js +0 -8
- package/.hive/src/resources/users/endpoints/getCurrentUser.js +0 -14
- package/.hive/src/resources/users/endpoints/getUserProfile.js +0 -19
- package/.hive/src/resources/users/methods/ensureUserCreated.js +0 -68
- package/.hive/src/security.util.js +0 -38
- package/.hive/src/services/globalTest.js +0 -0
- package/cli/helpers/docker.js +0 -59
- package/cli/helpers/envCheck.js +0 -127
- package/cli/helpers/findPort.js +0 -32
- package/starter/.babelrc +0 -6
- package/starter/.cursor/commands/add-endpoint.md +0 -262
- package/starter/.cursor/commands/add-handler.md +0 -137
- package/starter/.cursor/commands/add-middleware.md +0 -95
- package/starter/.cursor/commands/add-resource.md +0 -71
- package/starter/.cursor/commands/add-scheduler.md +0 -138
- package/starter/.cursor/commands/add-service.md +0 -188
- package/starter/.cursor/skills/hive-auth/SKILL.md +0 -134
- package/starter/.cursor/skills/hive-database/SKILL.md +0 -103
- package/starter/.cursor/skills/hive-endpoint/SKILL.md +0 -103
- package/starter/.cursor/skills/hive-handler/SKILL.md +0 -88
- package/starter/.cursor/skills/hive-mapping/SKILL.md +0 -85
- package/starter/.cursor/skills/hive-middleware/SKILL.md +0 -104
- package/starter/.cursor/skills/hive-overview/SKILL.md +0 -50
- package/starter/.cursor/skills/hive-scheduler/SKILL.md +0 -94
- package/starter/.cursor/skills/hive-schema/SKILL.md +0 -73
- package/starter/.cursor/skills/hive-service/SKILL.md +0 -90
- package/starter/.dockerignore +0 -1
- package/starter/Dockerfile +0 -22
- package/starter/Dockerfile.dev +0 -33
- package/starter/Dockerfile.prod +0 -29
- package/starter/README.md +0 -11
- package/starter/bin/deploy.sh +0 -5
- package/starter/bin/start.sh +0 -2
- package/starter/bootstrap-hive.js +0 -118
- package/starter/deploy/api/Chart.yaml +0 -6
- package/starter/deploy/api/staging.yaml +0 -3
- package/starter/deploy/api/templates/deployment.yaml +0 -44
- package/starter/deploy/api/templates/ingress.yaml +0 -26
- package/starter/deploy/api/templates/service.yaml +0 -14
- package/starter/deploy/script/Dockerfile +0 -39
- package/starter/deploy/script/package-lock.json +0 -1499
- package/starter/deploy/script/package.json +0 -12
- package/starter/deploy/script/src/config.js +0 -48
- package/starter/deploy/script/src/index.js +0 -108
- package/starter/deploy/script/src/util.js +0 -19
- package/starter/initial-data.json +0 -176
- package/starter/loader.mjs +0 -40
- package/starter/package-lock.json +0 -13492
- package/starter/register.mjs +0 -6
- package/starter/ship_logo.png +0 -0
- package/starter/src/app-config/app.js +0 -3
- package/starter/src/app-config/assertEnv.js +0 -15
- package/starter/src/app-config/index.js +0 -65
- package/starter/src/app.js +0 -65
- package/starter/src/assets/emails/components/header.mjml +0 -13
- package/starter/src/assets/emails/dist/.gitkeep +0 -0
- package/starter/src/assets/emails/signup-welcome.mjml +0 -34
- package/starter/src/assets/emails/styles/index.mjml +0 -77
- package/starter/src/autoMap/addHandlers.js +0 -142
- package/starter/src/autoMap/getDependentFields.js +0 -37
- package/starter/src/autoMap/mapSchema.js +0 -99
- package/starter/src/autoMap/schemaMappings.js +0 -13
- package/starter/src/autoMap/schemaMappings.json +0 -3
- package/starter/src/bullMqBus.js +0 -21
- package/starter/src/bullMqWrapper.js +0 -23
- package/starter/src/db.js +0 -53
- package/starter/src/emails/MyEmailComponent.jsx +0 -14
- package/starter/src/emails/compiled/MyEmailComponent.js +0 -6
- package/starter/src/emails/compiled/compiled/MyEmailComponent.js +0 -6
- package/starter/src/emails/compiled/compiled/compiled/MyEmailComponent.js +0 -6
- package/starter/src/emails/compiled/compiled/compiled/compiled/MyEmailComponent.js +0 -6
- package/starter/src/helpers/db/ifUpdated.js +0 -22
- package/starter/src/helpers/esm.js +0 -56
- package/starter/src/helpers/getMiddlewares.js +0 -41
- package/starter/src/helpers/getResourceEndpoints.js +0 -31
- package/starter/src/helpers/getResources.js +0 -35
- package/starter/src/helpers/getSchemas.js +0 -53
- package/starter/src/helpers/importHandlers.js +0 -20
- package/starter/src/helpers/isZodArray.js +0 -13
- package/starter/src/helpers/prettierFormat.js +0 -8
- package/starter/src/helpers/schema/db.schema.js +0 -9
- package/starter/src/helpers/schema/pagination.schema.js +0 -14
- package/starter/src/ioEmitter.js +0 -9
- package/starter/src/jsconfig.json +0 -5
- package/starter/src/lib/node-mongo/.github/workflows/npm-publish.yml +0 -32
- package/starter/src/lib/node-mongo/API.md +0 -654
- package/starter/src/lib/node-mongo/CHANGELOG.md +0 -98
- package/starter/src/lib/node-mongo/README.md +0 -97
- package/starter/src/lib/node-mongo/package-lock.json +0 -3682
- package/starter/src/lib/node-mongo/package.json +0 -74
- package/starter/src/lib/node-mongo/src/index.js +0 -64
- package/starter/src/lib/node-mongo/src/mongo-query-service.js +0 -78
- package/starter/src/lib/node-mongo/src/mongo-service-error.js +0 -15
- package/starter/src/lib/node-mongo/src/mongo-service.js +0 -303
- package/starter/src/middlewares/attachUser.js +0 -41
- package/starter/src/middlewares/global/extractUserTokens.js +0 -15
- package/starter/src/middlewares/global/tryToAttachUser.js +0 -33
- package/starter/src/middlewares/isAuthorized.js +0 -18
- package/starter/src/middlewares/shouldExist.js +0 -37
- package/starter/src/middlewares/shouldNotExist.js +0 -19
- package/starter/src/middlewares/uploadFile.js +0 -5
- package/starter/src/middlewares/validate.js +0 -32
- package/starter/src/migrations/migration.js +0 -8
- package/starter/src/migrations/migration.service.js +0 -76
- package/starter/src/migrations/migrations/1.js +0 -22
- package/starter/src/migrations/migrations-log/migration-log.schema.js +0 -13
- package/starter/src/migrations/migrations-log/migration-log.service.js +0 -50
- package/starter/src/migrations/migrations.schema.js +0 -6
- package/starter/src/migrations/migrator.js +0 -75
- package/starter/src/migrator.js +0 -3
- package/starter/src/resources/_dev/endpoints/triggerSchedulerHandler.js +0 -32
- package/starter/src/resources/health/endpoints/get.js +0 -19
- package/starter/src/resources/schemaMappings/schemaMappings.schema.js +0 -6
- package/starter/src/resources/tokens/methods/generateSecureToken.js +0 -9
- package/starter/src/resources/tokens/methods/setToken.js +0 -8
- package/starter/src/resources/tokens/methods/storeToken.js +0 -35
- package/starter/src/resources/tokens/tokens.schema.js +0 -11
- package/starter/src/resources/users/endpoints/getCurrentUser.js +0 -14
- package/starter/src/resources/users/endpoints/getUserProfile.js +0 -19
- package/starter/src/resources/users/handlers/test.js +0 -1
- package/starter/src/resources/users/methods/ensureUserCreated.js +0 -68
- package/starter/src/resources/users/users.schema.js +0 -16
- package/starter/src/routes/index.js +0 -172
- package/starter/src/routes/middlewares/attachCustomErrors.js +0 -28
- package/starter/src/routes/middlewares/routeErrorHandler.js +0 -27
- package/starter/src/scheduler.js +0 -35
- package/starter/src/security.util.js +0 -38
- package/starter/src/services/emailService.js +0 -15
- package/starter/src/services/globalTest.js +0 -0
- package/starter/src/services/setCookie.js +0 -21
- package/starter/src/socketIo.js +0 -99
- package/test-app/.cursor/commands/add-endpoint.md +0 -262
- package/test-app/.cursor/commands/add-handler.md +0 -137
- package/test-app/.cursor/commands/add-middleware.md +0 -95
- package/test-app/.cursor/commands/add-resource.md +0 -71
- package/test-app/.cursor/commands/add-scheduler.md +0 -138
- package/test-app/.cursor/skills/hive-auth/SKILL.md +0 -134
- package/test-app/.cursor/skills/hive-database/SKILL.md +0 -103
- package/test-app/.cursor/skills/hive-endpoint/SKILL.md +0 -103
- package/test-app/.cursor/skills/hive-handler/SKILL.md +0 -88
- package/test-app/.cursor/skills/hive-mapping/SKILL.md +0 -85
- package/test-app/.cursor/skills/hive-middleware/SKILL.md +0 -104
- package/test-app/.cursor/skills/hive-scheduler/SKILL.md +0 -94
- package/test-app/.cursor/skills/hive-schema/SKILL.md +0 -73
- package/test-app/package-lock.json +0 -462
- package/test-app/package.json +0 -25
- package/test-app/src/resources/tasks/tasks.schema.js +0 -2
- /package/{.hive → framework}/.babelrc +0 -0
- /package/{.hive → framework}/.cursor/commands/add-endpoint.md +0 -0
- /package/{.hive → framework}/.cursor/commands/add-handler.md +0 -0
- /package/{.hive → framework}/.cursor/commands/add-middleware.md +0 -0
- /package/{.hive → framework}/.cursor/commands/add-resource.md +0 -0
- /package/{.hive → framework}/.cursor/commands/add-scheduler.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-auth/SKILL.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-database/SKILL.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-endpoint/SKILL.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-handler/SKILL.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-mapping/SKILL.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-middleware/SKILL.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-scheduler/SKILL.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-schema/SKILL.md +0 -0
- /package/{.hive → framework}/.dockerignore +0 -0
- /package/{.hive → framework}/Dockerfile +0 -0
- /package/{.hive → framework}/Dockerfile.dev +0 -0
- /package/{.hive → framework}/Dockerfile.prod +0 -0
- /package/{.hive → framework}/README.md +0 -0
- /package/{.hive → framework}/bin/deploy.sh +0 -0
- /package/{.hive → framework}/deploy/api/Chart.yaml +0 -0
- /package/{.hive → framework}/deploy/api/staging.yaml +0 -0
- /package/{.hive → framework}/deploy/api/templates/deployment.yaml +0 -0
- /package/{.hive → framework}/deploy/api/templates/ingress.yaml +0 -0
- /package/{.hive → framework}/deploy/api/templates/service.yaml +0 -0
- /package/{.hive → framework}/deploy/script/Dockerfile +0 -0
- /package/{.hive → framework}/deploy/script/package-lock.json +0 -0
- /package/{.hive → framework}/deploy/script/package.json +0 -0
- /package/{.hive/deploy/script/src/config.js → framework/deploy/script/src/config.ts} +0 -0
- /package/{.hive/deploy/script/src/index.js → framework/deploy/script/src/index.ts} +0 -0
- /package/{.hive/deploy/script/src/util.js → framework/deploy/script/src/util.ts} +0 -0
- /package/{.hive → framework}/initial-data.json +0 -0
- /package/{.hive → framework}/ship_logo.png +0 -0
- /package/{.hive → framework}/src/assets/emails/components/header.mjml +0 -0
- /package/{.hive → framework}/src/assets/emails/dist/.gitkeep +0 -0
- /package/{.hive → framework}/src/assets/emails/signup-welcome.mjml +0 -0
- /package/{.hive → framework}/src/assets/emails/styles/index.mjml +0 -0
- /package/{.hive/src/autoMap/addHandlers.js → framework/src/autoMap/addHandlers.ts} +0 -0
- /package/{.hive/src/autoMap/getDependentFields.js → framework/src/autoMap/getDependentFields.ts} +0 -0
- /package/{.hive/src/autoMap/mapSchema.js → framework/src/autoMap/mapSchema.ts} +0 -0
- /package/{.hive → framework}/src/autoMap/schemaMappings.json +0 -0
- /package/{.hive/src/autoMap/schemaMappings.js → framework/src/autoMap/schemaMappings.ts} +0 -0
- /package/{.hive/src/helpers/schema/db.schema.js → framework/src/common/schema/db.schema.ts} +0 -0
- /package/{.hive/src/helpers/schema/pagination.schema.js → framework/src/common/schema/pagination.schema.ts} +0 -0
- /package/{.hive/src/app-config/app.js → framework/src/config/app.ts} +0 -0
- /package/{.hive/src/app-config/assertEnv.js → framework/src/config/assertEnv.ts} +0 -0
- /package/{.hive/src/emails/MyEmailComponent.jsx → framework/src/emails/MyEmailComponent.tsx} +0 -0
- /package/{.hive/src/emails/compiled/MyEmailComponent.js → framework/src/emails/compiled/MyEmailComponent.ts} +0 -0
- /package/{.hive/src/emails/compiled/compiled/MyEmailComponent.js → framework/src/emails/compiled/compiled/MyEmailComponent.ts} +0 -0
- /package/{.hive/src/helpers/db/ifUpdated.js → framework/src/helpers/db/ifUpdated.ts} +0 -0
- /package/{.hive/src/helpers/importHandlers.js → framework/src/helpers/importHandlers.ts} +0 -0
- /package/{.hive/src/helpers/isZodArray.js → framework/src/helpers/isZodArray.ts} +0 -0
- /package/{.hive/src/helpers/prettierFormat.js → framework/src/helpers/prettierFormat.ts} +0 -0
- /package/{.hive → framework}/src/jsconfig.json +0 -0
- /package/{.hive → framework}/src/lib/node-mongo/.github/workflows/npm-publish.yml +0 -0
- /package/{.hive → framework}/src/lib/node-mongo/API.md +0 -0
- /package/{.hive → framework}/src/lib/node-mongo/CHANGELOG.md +0 -0
- /package/{.hive → framework}/src/lib/node-mongo/README.md +0 -0
- /package/{.hive → framework}/src/lib/node-mongo/package-lock.json +0 -0
- /package/{.hive → framework}/src/lib/node-mongo/package.json +0 -0
- /package/{.hive/src/lib/node-mongo/src/index.js → framework/src/lib/node-mongo/src/index.ts} +0 -0
- /package/{.hive/src/lib/node-mongo/src/mongo-service-error.js → framework/src/lib/node-mongo/src/mongo-service-error.ts} +0 -0
- /package/{.hive/src/middlewares/allowNoAuth.js → framework/src/middlewares/allowNoAuth.ts} +0 -0
- /package/{.hive/src/middlewares/global/extractUserTokens.js → framework/src/middlewares/global/extractUserTokens.ts} +0 -0
- /package/{.hive/src/middlewares/validate.js → framework/src/middlewares/validate.ts} +0 -0
- /package/{.hive/src/migrations/migration.service.js → framework/src/migrations/migration.service.ts} +0 -0
- /package/{.hive/src/migrations/migration.js → framework/src/migrations/migration.ts} +0 -0
- /package/{.hive/src/migrations/migrations/1.js → framework/src/migrations/migrations/1.ts} +0 -0
- /package/{.hive/src/migrations/migrator.js → framework/src/migrations/migrator.ts} +0 -0
- /package/{.hive/src/migrator.js → framework/src/migrator.ts} +0 -0
- /package/{.hive/src/routes/middlewares/attachCustomErrors.js → framework/src/routes/middlewares/attachCustomErrors.ts} +0 -0
- /package/{.hive/src/routes/middlewares/routeErrorHandler.js → framework/src/routes/middlewares/routeErrorHandler.ts} +0 -0
- /package/{.hive/src/scheduler/handlers/sendDailyReport.example.js → framework/src/scheduler/handlers/sendDailyReport.example.ts} +0 -0
- /package/{.hive/src/scheduler.js → framework/src/scheduler.ts} +0 -0
- /package/starter/{src/middlewares/allowNoAuth.js → hive/middlewares/allowNoAuth.ts} +0 -0
- /package/{.hive/src/middlewares/isAuthorized.js → starter/hive/middlewares/isAuthorized.ts} +0 -0
- /package/{.hive/src/middlewares/uploadFile.js → starter/hive/middlewares/uploadFile.ts} +0 -0
- /package/{.hive/src/resources/tokens/methods/generateSecureToken.js → starter/hive/resources/tokens/methods/generateSecureToken.ts} +0 -0
- /package/{.hive/src/resources/users/handlers/test.js → starter/hive/resources/users/handlers/test.ts} +0 -0
- /package/starter/{src/scheduler/handlers/sendDailyReport.example.js → hive/scheduler/handlers/dailyExample.ts} +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(npx npm-check-updates:*)",
|
|
5
|
+
"Bash(npm install:*)",
|
|
6
|
+
"Bash(git mv:*)",
|
|
7
|
+
"Bash(npm run test:init:*)",
|
|
8
|
+
"Bash(ls:*)",
|
|
9
|
+
"Bash(node:*)",
|
|
10
|
+
"Bash(HIVE_SRC=$PWD/hive node -e \"\nconst tsx = require\\(''tsx/cjs/api''\\);\nprocess.env.HIVE_SRC = ''$PWD/hive'';\ntsx.require\\(''./.hive/src/app.ts'', __filename\\);\n\")"
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
+
const { spawn } = require('child_process');
|
|
3
4
|
|
|
4
|
-
const execa = require('execa');
|
|
5
5
|
const mkdirp = require('mkdirp');
|
|
6
6
|
|
|
7
7
|
const execCommand = async (command, options = {}, outputFileSrc = null) => {
|
|
@@ -20,29 +20,29 @@ const execCommand = async (command, options = {}, outputFileSrc = null) => {
|
|
|
20
20
|
|
|
21
21
|
return commandPart;
|
|
22
22
|
});
|
|
23
|
-
|
|
24
|
-
// commandParts = command.split(' ').filter((part) => !!part.trim());
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
const commandName = commandParts.shift();
|
|
28
26
|
const commandArguments = commandParts;
|
|
29
27
|
|
|
30
|
-
const
|
|
28
|
+
const child = spawn(commandName, commandArguments, {
|
|
31
29
|
stdio: outputFileSrc ? 'pipe' : 'inherit',
|
|
32
30
|
...options,
|
|
33
31
|
});
|
|
34
32
|
|
|
35
33
|
if (outputFileSrc) {
|
|
36
|
-
console.log('writing to outputFileSrc', outputFileSrc);
|
|
37
34
|
const dir = path.dirname(outputFileSrc);
|
|
38
|
-
|
|
39
35
|
await mkdirp(dir);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
process.stdout.pipe(fs.createWriteStream(outputFileSrc, { flags: 'a+' }));
|
|
36
|
+
child.stdout.pipe(fs.createWriteStream(outputFileSrc, { flags: 'a+' }));
|
|
43
37
|
}
|
|
44
38
|
|
|
45
|
-
return
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
child.on('close', (code) => {
|
|
41
|
+
if (code === 0) resolve();
|
|
42
|
+
else reject(new Error(`Command "${command}" failed with exit code ${code}`));
|
|
43
|
+
});
|
|
44
|
+
child.on('error', reject);
|
|
45
|
+
});
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
module.exports = execCommand;
|
|
@@ -5,9 +5,9 @@ const inquirer = require('inquirer');
|
|
|
5
5
|
|
|
6
6
|
module.exports = async () => {
|
|
7
7
|
if (!process.env.PROJECT_ID) {
|
|
8
|
-
let projectConfigPath = path.resolve(process.env.HIVE_SRC, './hive.config.js');
|
|
9
|
-
|
|
10
|
-
if (
|
|
8
|
+
let projectConfigPath = [path.resolve(process.env.HIVE_SRC, './hive.config.ts'), path.resolve(process.env.HIVE_SRC, './hive.config.js')].find(p => fs.existsSync(p));
|
|
9
|
+
|
|
10
|
+
if (projectConfigPath) {
|
|
11
11
|
const config = require(projectConfigPath);
|
|
12
12
|
if (config.projectId) {
|
|
13
13
|
process.env.PROJECT_ID = config.projectId;
|
package/cli/helpers/mergeDirs.js
CHANGED
|
@@ -71,7 +71,7 @@ async function mergeDirectories(sourceDir1, sourceDir2, targetDir) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
module.exports = async ({ hiveSrc, outDir }) => {
|
|
74
|
-
await mergeDirectories(path.resolve(__dirname, './../../
|
|
74
|
+
await mergeDirectories(path.resolve(__dirname, './../../framework'), hiveSrc, outDir);
|
|
75
75
|
|
|
76
76
|
console.log('Merged resources');
|
|
77
77
|
}
|
package/cli/hive.js
CHANGED
|
@@ -7,41 +7,76 @@ const inquirer = require('inquirer');
|
|
|
7
7
|
const mergeDirs = require('./helpers/mergeDirs');
|
|
8
8
|
const execCommand = require('./helpers/execCommand');
|
|
9
9
|
const downloadDirectory = require('./helpers/downloadDirectory');
|
|
10
|
-
const { isDockerInstalled, startMongo, startRedis } = require('./helpers/docker');
|
|
11
|
-
const { ensureEnvConfig, hashCode } = require('./helpers/envCheck');
|
|
12
|
-
const { findAvailablePort } = require('./helpers/findPort');
|
|
13
10
|
const axios = require('axios');
|
|
11
|
+
const tsx = require('tsx/cjs/api');
|
|
14
12
|
const fs = require('fs');
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
13
|
+
|
|
14
|
+
program
|
|
15
|
+
.version(require('../package.json').version, '-v, --version');
|
|
16
|
+
|
|
17
|
+
function generateDbTypesFile(hiveSrc, frameworkDir, hiveProjectDir) {
|
|
18
|
+
// Write to .hive/src/_generated/ (NOT $HIVE_SRC) to avoid triggering tsx watcher
|
|
19
|
+
const generatedDir = path.resolve(hiveProjectDir, 'src', '_generated');
|
|
20
|
+
|
|
21
|
+
if (!fs.existsSync(generatedDir)) {
|
|
22
|
+
fs.mkdirSync(generatedDir, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Scan for schema files in user resources and framework resources
|
|
26
|
+
const schemas = [];
|
|
27
|
+
const scanDirs = [
|
|
28
|
+
{ dir: path.resolve(hiveSrc, 'resources'), isUser: true },
|
|
29
|
+
{ dir: path.resolve(frameworkDir, 'src', 'resources'), isUser: false },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
for (const { dir: resourcesDir, isUser } of scanDirs) {
|
|
33
|
+
if (!fs.existsSync(resourcesDir)) continue;
|
|
34
|
+
|
|
35
|
+
for (const resourceName of fs.readdirSync(resourcesDir)) {
|
|
36
|
+
const resourcePath = path.resolve(resourcesDir, resourceName);
|
|
37
|
+
if (!fs.statSync(resourcePath).isDirectory()) continue;
|
|
38
|
+
|
|
39
|
+
for (const file of fs.readdirSync(resourcePath)) {
|
|
40
|
+
if ((file.endsWith('.schema.ts') || file.endsWith('.schema.js')) && !file.includes('extends.schema')) {
|
|
41
|
+
const name = file.replace('.schema.ts', '').replace('.schema.js', '');
|
|
42
|
+
// Skip if already found (user schemas override framework)
|
|
43
|
+
if (!schemas.find(s => s.name === name)) {
|
|
44
|
+
schemas.push({ name, resourceName, isUser });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
38
49
|
}
|
|
50
|
+
|
|
51
|
+
// User schemas use @/ (hive/*), framework schemas use @hive/ (.hive/src/*)
|
|
52
|
+
const imports = schemas.map(
|
|
53
|
+
(s) => `import type ${s.name}Schema from '${s.isUser ? '@' : '@hive'}/resources/${s.resourceName}/${s.name}.schema';`
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const entries = schemas.map(
|
|
57
|
+
(s) => ` ${s.name}: MongoService<z.infer<typeof ${s.name}Schema>>;`
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const content = `// Auto-generated by Hive — do not edit manually
|
|
61
|
+
import type { z } from 'zod';
|
|
62
|
+
import type MongoService from '@hive/lib/node-mongo/src/mongo-service';
|
|
63
|
+
${imports.join('\n')}
|
|
64
|
+
|
|
65
|
+
export interface DbServices {
|
|
66
|
+
${entries.join('\n')}
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
|
|
70
|
+
fs.writeFileSync(path.resolve(generatedDir, 'db.types.ts'), content);
|
|
71
|
+
console.log('[hive] Generated db.types.ts');
|
|
39
72
|
}
|
|
40
73
|
|
|
41
74
|
program
|
|
42
75
|
.command('init [projectName]')
|
|
43
76
|
.description('Initialize a new Hive project')
|
|
44
|
-
.
|
|
77
|
+
.option('--skip-install', 'Skip npm install')
|
|
78
|
+
.option('--link', 'Use local file:.. dependency for @paralect/hive (for development)')
|
|
79
|
+
.action(async (projectName, options) => {
|
|
45
80
|
try {
|
|
46
81
|
let name = projectName;
|
|
47
82
|
|
|
@@ -58,41 +93,47 @@ program
|
|
|
58
93
|
}
|
|
59
94
|
|
|
60
95
|
const projectDir = path.resolve(process.cwd(), name);
|
|
96
|
+
const hiveVersion = require('../package.json').version;
|
|
61
97
|
|
|
62
98
|
console.log(`\n🐝 Creating Hive project: ${name}\n`);
|
|
63
99
|
|
|
64
|
-
|
|
65
|
-
await execCommand(`
|
|
66
|
-
await execCommand(`mkdir -p ${projectDir}/src/services`);
|
|
67
|
-
await execCommand(`mkdir -p ${projectDir}/src/scheduler/handlers`);
|
|
100
|
+
const filesDir = path.resolve(__dirname, '../starter');
|
|
101
|
+
await execCommand(`cp -r ${filesDir}/. ${projectDir}/`);
|
|
68
102
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
103
|
+
// Rename .env.example to .env (stored as .example to avoid gitignore)
|
|
104
|
+
const envExample = path.join(projectDir, 'hive', 'config', '.env.example');
|
|
105
|
+
const envFile = path.join(projectDir, 'hive', 'config', '.env');
|
|
106
|
+
if (fs.existsSync(envExample)) {
|
|
107
|
+
fs.renameSync(envExample, envFile);
|
|
108
|
+
}
|
|
74
109
|
|
|
75
|
-
|
|
76
|
-
|
|
110
|
+
const templateFiles = ['package.json'];
|
|
111
|
+
const replacements = {
|
|
112
|
+
'{{PROJECT_NAME}}': name,
|
|
113
|
+
'{{HIVE_DEP}}': options.link ? `file:${path.relative(projectDir, path.resolve(__dirname, '..'))}` : `^${hiveVersion}`,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
for (const file of templateFiles) {
|
|
117
|
+
const filePath = path.join(projectDir, file);
|
|
118
|
+
let content = fs.readFileSync(filePath, 'utf-8');
|
|
119
|
+
for (const [key, value] of Object.entries(replacements)) {
|
|
120
|
+
content = content.replaceAll(key, value);
|
|
121
|
+
}
|
|
122
|
+
fs.writeFileSync(filePath, content);
|
|
123
|
+
}
|
|
77
124
|
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
fs.writeFileSync(
|
|
82
|
-
path.join(appConfigDir, '.env'),
|
|
83
|
-
`MONGODB_URI=mongodb://localhost:27027/${name}\nREDIS_URI=redis://localhost:6389/${redisDb}\nPORT=3001\nNODE_ENV=development\n`
|
|
84
|
-
);
|
|
125
|
+
const projectPkgPath = path.join(projectDir, 'package.json');
|
|
126
|
+
const projectPkg = JSON.parse(fs.readFileSync(projectPkgPath, 'utf-8'));
|
|
127
|
+
fs.writeFileSync(projectPkgPath, JSON.stringify(projectPkg, null, 2));
|
|
85
128
|
|
|
86
|
-
|
|
87
|
-
path.join(projectDir, '.gitignore'),
|
|
88
|
-
`node_modules\n.hive\n.env\nsrc/app-config/.env\n`
|
|
89
|
-
);
|
|
129
|
+
await execCommand(`cp -r ${path.resolve(__dirname, '..')}/framework/.cursor ${projectDir}/`);
|
|
90
130
|
|
|
91
|
-
|
|
131
|
+
if (!options.skipInstall) {
|
|
132
|
+
await execCommand(`npm install`, { cwd: projectDir });
|
|
133
|
+
}
|
|
92
134
|
|
|
93
135
|
console.log(`✅ Project created!\n`);
|
|
94
136
|
console.log(`Next steps:\n`);
|
|
95
|
-
console.log(` cd ${name}`);
|
|
96
137
|
console.log(` hive run ./src\n`);
|
|
97
138
|
console.log(`Start building with AI commands:`);
|
|
98
139
|
console.log(` add-resource tasks`);
|
|
@@ -102,62 +143,21 @@ program
|
|
|
102
143
|
}
|
|
103
144
|
});
|
|
104
145
|
|
|
105
|
-
program
|
|
106
|
-
.command('infra-docker')
|
|
107
|
-
.description('Start shared MongoDB and Redis containers for local development')
|
|
108
|
-
.action(async () => {
|
|
109
|
-
try {
|
|
110
|
-
if (!isDockerInstalled()) {
|
|
111
|
-
console.error('Docker is not installed or not running. Please install Docker first.');
|
|
112
|
-
process.exit(1);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
console.log('\nStarting Hive infrastructure...\n');
|
|
116
|
-
|
|
117
|
-
await startMongo();
|
|
118
|
-
await startRedis();
|
|
119
|
-
|
|
120
|
-
console.log('\n✅ Infrastructure ready!\n');
|
|
121
|
-
console.log('Connection URIs:');
|
|
122
|
-
console.log(' MongoDB: mongodb://localhost:27027/<your-db-name>');
|
|
123
|
-
console.log(' Redis: redis://localhost:6389/<db-number>\n');
|
|
124
|
-
console.log('These containers are shared across all Hive projects.');
|
|
125
|
-
console.log('Each project uses a unique database name for isolation.\n');
|
|
126
|
-
} catch (error) {
|
|
127
|
-
console.error('An error occurred:', error.message);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
146
|
program
|
|
132
147
|
.command('run [dirPath]')
|
|
133
148
|
.description('Run Hive server')
|
|
134
149
|
.action(async (dirPath = '.') => {
|
|
135
150
|
try {
|
|
136
|
-
|
|
137
|
-
const projectDir = path.resolve(hiveSrc, '..');
|
|
138
|
-
const hiveProjectDir = path.resolve(projectDir, '.hive');
|
|
139
|
-
|
|
140
|
-
// Ensure env config exists in hive_src/app-config/.env
|
|
141
|
-
await ensureEnvConfig(hiveSrc);
|
|
142
|
-
|
|
143
|
-
// Find available port
|
|
144
|
-
const defaultPort = parseInt(process.env.PORT) || 3001;
|
|
145
|
-
const port = await findAvailablePort(defaultPort);
|
|
146
|
-
if (port !== defaultPort) {
|
|
147
|
-
console.log(` Port ${defaultPort} in use, using ${port} instead\n`);
|
|
148
|
-
}
|
|
151
|
+
process.env.HIVE_SRC = path.resolve(process.cwd(), dirPath);
|
|
149
152
|
|
|
153
|
+
const hiveProjectDir = path.resolve(process.env.HIVE_SRC, `../.hive`);
|
|
150
154
|
await execCommand(`mkdir -p ${hiveProjectDir}`);
|
|
151
|
-
await execCommand(`
|
|
155
|
+
await execCommand(`cp -r ${path.resolve(__dirname, '..')}/framework/ ${hiveProjectDir}`);
|
|
152
156
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
stdio: 'inherit',
|
|
156
|
-
env: { ...process.env, HIVE_SRC: hiveSrc, PORT: String(port) }
|
|
157
|
-
});
|
|
157
|
+
// Generate types before starting the server
|
|
158
|
+
generateDbTypesFile(process.env.HIVE_SRC, path.resolve(__dirname, '..', 'framework'), hiveProjectDir);
|
|
158
159
|
|
|
159
|
-
|
|
160
|
-
child.on('close', (code) => process.exit(code));
|
|
160
|
+
tsx.require(`${hiveProjectDir}/src/app.ts`, __filename); // TSX doesn't work inside node_moduels
|
|
161
161
|
} catch (error) {
|
|
162
162
|
console.error('An error occurred:', error.message);
|
|
163
163
|
}
|
|
@@ -168,15 +168,15 @@ program
|
|
|
168
168
|
.description('Prepare Hive server')
|
|
169
169
|
.action(async (dirPath = '.') => {
|
|
170
170
|
try {
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
const hiveProjectDir = path.resolve(projectDir, '.hive');
|
|
174
|
-
|
|
175
|
-
// Ensure env config exists in hive_src/app-config/.env
|
|
176
|
-
await ensureEnvConfig(hiveSrc);
|
|
171
|
+
process.env.HIVE_SRC = path.resolve(process.cwd(), dirPath);
|
|
172
|
+
const hiveProjectDir = path.resolve(process.env.HIVE_SRC, `../.hive`);
|
|
177
173
|
|
|
178
174
|
await execCommand(`mkdir -p ${hiveProjectDir}`);
|
|
179
|
-
await execCommand(`
|
|
175
|
+
await execCommand(`cp -r ${path.resolve(__dirname, '..')}/framework/. ${hiveProjectDir}`);
|
|
176
|
+
await execCommand(`npm install --prefix ${hiveProjectDir}`);
|
|
177
|
+
|
|
178
|
+
// Generate db.types.ts from discovered schemas
|
|
179
|
+
generateDbTypesFile(process.env.HIVE_SRC, path.resolve(__dirname, '..', 'framework'), hiveProjectDir);
|
|
180
180
|
} catch (error) {
|
|
181
181
|
console.error('An error occurred:', error.message);
|
|
182
182
|
}
|
|
@@ -36,7 +36,7 @@ When creating a service, use these go-to libraries:
|
|
|
36
36
|
## Template
|
|
37
37
|
|
|
38
38
|
```javascript
|
|
39
|
-
import config from '
|
|
39
|
+
import config from 'config';
|
|
40
40
|
|
|
41
41
|
// Initialize client here
|
|
42
42
|
|
|
@@ -52,7 +52,7 @@ export default {
|
|
|
52
52
|
### `add-service slack sendChannelMessage, replyToThread`
|
|
53
53
|
|
|
54
54
|
```javascript
|
|
55
|
-
import config from '
|
|
55
|
+
import config from 'config';
|
|
56
56
|
import { WebClient } from '@slack/web-api';
|
|
57
57
|
|
|
58
58
|
const client = new WebClient(config.slack.botToken);
|
|
@@ -73,7 +73,7 @@ export default {
|
|
|
73
73
|
### `add-service stripe createCustomer, createPaymentIntent, listInvoices`
|
|
74
74
|
|
|
75
75
|
```javascript
|
|
76
|
-
import config from '
|
|
76
|
+
import config from 'config';
|
|
77
77
|
import Stripe from 'stripe';
|
|
78
78
|
|
|
79
79
|
const client = new Stripe(config.stripe.secretKey);
|
|
@@ -102,7 +102,7 @@ export default {
|
|
|
102
102
|
### `add-service openai chat, generateImage`
|
|
103
103
|
|
|
104
104
|
```javascript
|
|
105
|
-
import config from '
|
|
105
|
+
import config from 'config';
|
|
106
106
|
import OpenAI from 'openai';
|
|
107
107
|
|
|
108
108
|
const client = new OpenAI({ apiKey: config.openai.apiKey });
|
|
@@ -125,7 +125,7 @@ export default {
|
|
|
125
125
|
### `add-service sendgrid sendEmail, sendTemplateEmail`
|
|
126
126
|
|
|
127
127
|
```javascript
|
|
128
|
-
import config from '
|
|
128
|
+
import config from 'config';
|
|
129
129
|
import sgMail from '@sendgrid/mail';
|
|
130
130
|
|
|
131
131
|
sgMail.setApiKey(config.sendgrid.apiKey);
|
|
@@ -144,7 +144,7 @@ export default {
|
|
|
144
144
|
### `add-service s3 upload, getSignedUrl, delete`
|
|
145
145
|
|
|
146
146
|
```javascript
|
|
147
|
-
import config from '
|
|
147
|
+
import config from 'config';
|
|
148
148
|
import { S3Client, PutObjectCommand, GetObjectCommand, DeleteObjectCommand } from '@aws-sdk/client-s3';
|
|
149
149
|
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
150
150
|
|
|
@@ -15,7 +15,7 @@ Location: `/src/services/{name}.js`
|
|
|
15
15
|
## API Client Template
|
|
16
16
|
|
|
17
17
|
```javascript
|
|
18
|
-
import config from '
|
|
18
|
+
import config from 'config';
|
|
19
19
|
import axios from 'axios';
|
|
20
20
|
|
|
21
21
|
const client = axios.create({
|
|
@@ -41,7 +41,7 @@ export default {
|
|
|
41
41
|
## SDK Wrapper Template
|
|
42
42
|
|
|
43
43
|
```javascript
|
|
44
|
-
import config from '
|
|
44
|
+
import config from 'config';
|
|
45
45
|
import { WebClient } from '@slack/web-api';
|
|
46
46
|
|
|
47
47
|
const client = new WebClient(config.slack.botToken);
|
|
@@ -58,7 +58,7 @@ function generateProjectStructure(resources) {
|
|
|
58
58
|
resource.schemas.forEach((schema) => {
|
|
59
59
|
const schemaCode = convertJsonToJs(schema);
|
|
60
60
|
fs.writeFileSync(
|
|
61
|
-
path.join(schemaDir, `${schema.name.toLowerCase()}.schema.
|
|
61
|
+
path.join(schemaDir, `${schema.name.toLowerCase()}.schema.ts`),
|
|
62
62
|
schemaCode
|
|
63
63
|
);
|
|
64
64
|
});
|
|
@@ -71,7 +71,7 @@ function generateProjectStructure(resources) {
|
|
|
71
71
|
resource.endpoints.forEach((endpoint) => {
|
|
72
72
|
const endpointCode = createEndpointCode(endpoint);
|
|
73
73
|
fs.writeFileSync(
|
|
74
|
-
path.join(endpointDir, `${endpoint.name}.
|
|
74
|
+
path.join(endpointDir, `${endpoint.name}.ts`),
|
|
75
75
|
endpointCode
|
|
76
76
|
);
|
|
77
77
|
});
|
|
@@ -84,7 +84,7 @@ function generateProjectStructure(resources) {
|
|
|
84
84
|
resource.handlers.forEach((handler) => {
|
|
85
85
|
const handlerCode = handler.handler;
|
|
86
86
|
fs.writeFileSync(
|
|
87
|
-
path.join(handlerDir, `${handler.name}.
|
|
87
|
+
path.join(handlerDir, `${handler.name}.ts`),
|
|
88
88
|
handlerCode
|
|
89
89
|
);
|
|
90
90
|
});
|
|
@@ -96,7 +96,7 @@ function generateProjectStructure(resources) {
|
|
|
96
96
|
mkdirRecursive(methodDir);
|
|
97
97
|
resource.methods.forEach((method) => {
|
|
98
98
|
const methodCode = method.handler;
|
|
99
|
-
fs.writeFileSync(path.join(methodDir, `${method.name}.
|
|
99
|
+
fs.writeFileSync(path.join(methodDir, `${method.name}.ts`), methodCode);
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
});
|