@monolayer/sdk 1.2.0-canary.4
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/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/bin/cli.js +21609 -0
- package/dist/cjs/configuration.d.ts +65 -0
- package/dist/cjs/configuration.js +45 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/introspection.d.ts +2 -0
- package/dist/cjs/introspection.js +11 -0
- package/dist/cjs/make/broadcast.d.ts +10 -0
- package/dist/cjs/make/broadcast.js +37 -0
- package/dist/cjs/make/config.d.ts +2 -0
- package/dist/cjs/make/config.js +44 -0
- package/dist/cjs/make/cron.d.ts +9 -0
- package/dist/cjs/make/cron.js +30 -0
- package/dist/cjs/make/make.d.ts +6 -0
- package/dist/cjs/make/make.js +134 -0
- package/dist/cjs/make/manifest.d.ts +202 -0
- package/dist/cjs/make/manifest.js +165 -0
- package/dist/cjs/make/required-filtes.d.ts +1 -0
- package/dist/cjs/make/required-filtes.js +17 -0
- package/dist/cjs/make/task.d.ts +9 -0
- package/dist/cjs/make/task.js +30 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/packages/docker/df.d.ts +543 -0
- package/dist/cjs/packages/docker/df.js +395 -0
- package/dist/cjs/packages/docker/validator.d.ts +7 -0
- package/dist/cjs/packages/docker/validator.js +18 -0
- package/dist/cjs/packages/utils/create-file.d.ts +1 -0
- package/dist/cjs/packages/utils/create-file.js +18 -0
- package/dist/cjs/packages/utils/date-string.d.ts +1 -0
- package/dist/cjs/packages/utils/date-string.js +12 -0
- package/dist/cjs/packages/utils/exception.d.ts +1 -0
- package/dist/cjs/packages/utils/exception.js +8 -0
- package/dist/cjs/packages/utils/hash-value.d.ts +16 -0
- package/dist/cjs/packages/utils/hash-value.js +25 -0
- package/dist/cjs/packages/utils/import-default.d.ts +1 -0
- package/dist/cjs/packages/utils/import-default.js +14 -0
- package/dist/cjs/packages/utils/import-file.d.ts +8 -0
- package/dist/cjs/packages/utils/import-file.js +41 -0
- package/dist/cjs/packages/utils/log-with-spinner.d.ts +1 -0
- package/dist/cjs/packages/utils/log-with-spinner.js +24 -0
- package/dist/cjs/packages/utils/path.d.ts +2 -0
- package/dist/cjs/packages/utils/path.js +21 -0
- package/dist/cjs/packages/utils/playground.d.ts +1 -0
- package/dist/cjs/packages/utils/playground.js +35 -0
- package/dist/cjs/scaffolding/add-env-var.d.ts +6 -0
- package/dist/cjs/scaffolding/add-env-var.js +65 -0
- package/dist/cjs/scaffolding/add-import.d.ts +16 -0
- package/dist/cjs/scaffolding/add-import.js +43 -0
- package/dist/cjs/scaffolding/add-script.d.ts +1 -0
- package/dist/cjs/scaffolding/add-script.js +35 -0
- package/dist/cjs/scaffolding/broadcast-workload.d.ts +1 -0
- package/dist/cjs/scaffolding/broadcast-workload.js +36 -0
- package/dist/cjs/scaffolding/bucket-workload.d.ts +6 -0
- package/dist/cjs/scaffolding/bucket-workload.js +23 -0
- package/dist/cjs/scaffolding/cron-workload.d.ts +6 -0
- package/dist/cjs/scaffolding/cron-workload.js +28 -0
- package/dist/cjs/scaffolding/drizzle.d.ts +4 -0
- package/dist/cjs/scaffolding/drizzle.js +22 -0
- package/dist/cjs/scaffolding/lifecycle.d.ts +9 -0
- package/dist/cjs/scaffolding/lifecycle.js +61 -0
- package/dist/cjs/scaffolding/postgres-database-workload.d.ts +15 -0
- package/dist/cjs/scaffolding/postgres-database-workload.js +39 -0
- package/dist/cjs/scaffolding/prisma.d.ts +4 -0
- package/dist/cjs/scaffolding/prisma.js +40 -0
- package/dist/cjs/scaffolding/replace-string.d.ts +10 -0
- package/dist/cjs/scaffolding/replace-string.js +37 -0
- package/dist/cjs/scaffolding/task-workload.d.ts +6 -0
- package/dist/cjs/scaffolding/task-workload.js +30 -0
- package/dist/cjs/scaffolding/workload.d.ts +1 -0
- package/dist/cjs/scaffolding/workload.js +18 -0
- package/dist/cjs/scan/project.d.ts +23 -0
- package/dist/cjs/scan/project.js +79 -0
- package/dist/cjs/scan/workload-imports.d.ts +21 -0
- package/dist/cjs/scan/workload-imports.js +188 -0
- package/dist/cjs/test-helpers/postgres.d.ts +13 -0
- package/dist/cjs/test-helpers/postgres.js +52 -0
- package/dist/cjs/test-helpers/redis.d.ts +13 -0
- package/dist/cjs/test-helpers/redis.js +46 -0
- package/dist/cjs/test-helpers/task.d.ts +14 -0
- package/dist/cjs/test-helpers/task.js +18 -0
- package/dist/cjs/test-helpers.d.ts +3 -0
- package/dist/cjs/test-helpers.js +10 -0
- package/dist/cjs/workloads/app-lifecycle/after-rollout.d.ts +22 -0
- package/dist/cjs/workloads/app-lifecycle/after-rollout.js +28 -0
- package/dist/cjs/workloads/app-lifecycle/before-rollout.d.ts +22 -0
- package/dist/cjs/workloads/app-lifecycle/before-rollout.js +28 -0
- package/dist/cjs/workloads/app-lifecycle/bootstrap.d.ts +22 -0
- package/dist/cjs/workloads/app-lifecycle/bootstrap.js +28 -0
- package/dist/cjs/workloads/app-lifecycle/lifecycle-workload.d.ts +11 -0
- package/dist/cjs/workloads/app-lifecycle/lifecycle-workload.js +11 -0
- package/dist/cjs/workloads/assertions.d.ts +13 -0
- package/dist/cjs/workloads/assertions.js +14 -0
- package/dist/cjs/workloads/stateful/bucket.d.ts +82 -0
- package/dist/cjs/workloads/stateful/bucket.js +95 -0
- package/dist/cjs/workloads/stateful/database.d.ts +25 -0
- package/dist/cjs/workloads/stateful/database.js +42 -0
- package/dist/cjs/workloads/stateful/postgres-database.d.ts +29 -0
- package/dist/cjs/workloads/stateful/postgres-database.js +39 -0
- package/dist/cjs/workloads/stateful/redis.d.ts +30 -0
- package/dist/cjs/workloads/stateful/redis.js +40 -0
- package/dist/cjs/workloads/stateful/stateful-workload.d.ts +25 -0
- package/dist/cjs/workloads/stateful/stateful-workload.js +41 -0
- package/dist/cjs/workloads/stateless/broadcast/channel-data.d.ts +3 -0
- package/dist/cjs/workloads/stateless/broadcast/channel-data.js +6 -0
- package/dist/cjs/workloads/stateless/broadcast/client/app-sync-client.d.ts +78 -0
- package/dist/cjs/workloads/stateless/broadcast/client/app-sync-client.js +128 -0
- package/dist/cjs/workloads/stateless/broadcast/client/app-sync-publisher.d.ts +34 -0
- package/dist/cjs/workloads/stateless/broadcast/client/app-sync-publisher.js +78 -0
- package/dist/cjs/workloads/stateless/broadcast/client/authenticator.d.ts +28 -0
- package/dist/cjs/workloads/stateless/broadcast/client/authenticator.js +43 -0
- package/dist/cjs/workloads/stateless/broadcast/client/broadcast-provider.d.ts +17 -0
- package/dist/cjs/workloads/stateless/broadcast/client/broadcast-provider.js +34 -0
- package/dist/cjs/workloads/stateless/broadcast/client/client.d.ts +8 -0
- package/dist/cjs/workloads/stateless/broadcast/client/client.js +28 -0
- package/dist/cjs/workloads/stateless/broadcast/client/connectionManager.d.ts +62 -0
- package/dist/cjs/workloads/stateless/broadcast/client/connectionManager.js +166 -0
- package/dist/cjs/workloads/stateless/broadcast/client/eventEmitter.d.ts +32 -0
- package/dist/cjs/workloads/stateless/broadcast/client/eventEmitter.js +53 -0
- package/dist/cjs/workloads/stateless/broadcast/client/messageBuilder.d.ts +24 -0
- package/dist/cjs/workloads/stateless/broadcast/client/messageBuilder.js +43 -0
- package/dist/cjs/workloads/stateless/broadcast/client/parser.d.ts +12 -0
- package/dist/cjs/workloads/stateless/broadcast/client/parser.js +22 -0
- package/dist/cjs/workloads/stateless/broadcast/client/provider.d.ts +4 -0
- package/dist/cjs/workloads/stateless/broadcast/client/provider.js +11 -0
- package/dist/cjs/workloads/stateless/broadcast/client/subscriptionManager.d.ts +34 -0
- package/dist/cjs/workloads/stateless/broadcast/client/subscriptionManager.js +91 -0
- package/dist/cjs/workloads/stateless/broadcast/client/types.d.ts +72 -0
- package/dist/cjs/workloads/stateless/broadcast/client/types.js +6 -0
- package/dist/cjs/workloads/stateless/broadcast/matcher.d.ts +13 -0
- package/dist/cjs/workloads/stateless/broadcast/matcher.js +46 -0
- package/dist/cjs/workloads/stateless/broadcast/router.d.ts +103 -0
- package/dist/cjs/workloads/stateless/broadcast/router.js +98 -0
- package/dist/cjs/workloads/stateless/broadcast/types.d.ts +17 -0
- package/dist/cjs/workloads/stateless/broadcast/types.js +2 -0
- package/dist/cjs/workloads/stateless/cron.d.ts +49 -0
- package/dist/cjs/workloads/stateless/cron.js +55 -0
- package/dist/cjs/workloads/stateless/stateless-workload.d.ts +3 -0
- package/dist/cjs/workloads/stateless/stateless-workload.js +7 -0
- package/dist/cjs/workloads/stateless/task/backoffs.d.ts +9 -0
- package/dist/cjs/workloads/stateless/task/backoffs.js +17 -0
- package/dist/cjs/workloads/stateless/task/dispatcher.d.ts +3 -0
- package/dist/cjs/workloads/stateless/task/dispatcher.js +22 -0
- package/dist/cjs/workloads/stateless/task/local.d.ts +14 -0
- package/dist/cjs/workloads/stateless/task/local.js +54 -0
- package/dist/cjs/workloads/stateless/task/perform-later.d.ts +2 -0
- package/dist/cjs/workloads/stateless/task/perform-later.js +7 -0
- package/dist/cjs/workloads/stateless/task/perform-now.d.ts +5 -0
- package/dist/cjs/workloads/stateless/task/perform-now.js +24 -0
- package/dist/cjs/workloads/stateless/task/perform.d.ts +7 -0
- package/dist/cjs/workloads/stateless/task/perform.js +10 -0
- package/dist/cjs/workloads/stateless/task/task.d.ts +88 -0
- package/dist/cjs/workloads/stateless/task/task.js +61 -0
- package/dist/cjs/workloads/stateless/task/validate-data-size.d.ts +1 -0
- package/dist/cjs/workloads/stateless/task/validate-data-size.js +10 -0
- package/dist/cjs/workloads/workload.d.ts +14 -0
- package/dist/cjs/workloads/workload.js +16 -0
- package/dist/cjs/workloads.d.ts +22 -0
- package/dist/cjs/workloads.js +30 -0
- package/dist/esm/configuration.d.ts +65 -0
- package/dist/esm/configuration.js +15 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/introspection.d.ts +2 -0
- package/dist/esm/introspection.js +2 -0
- package/dist/esm/make/broadcast.d.ts +10 -0
- package/dist/esm/make/broadcast.js +30 -0
- package/dist/esm/make/config.d.ts +2 -0
- package/dist/esm/make/config.js +41 -0
- package/dist/esm/make/cron.d.ts +9 -0
- package/dist/esm/make/cron.js +23 -0
- package/dist/esm/make/make.d.ts +6 -0
- package/dist/esm/make/make.js +120 -0
- package/dist/esm/make/manifest.d.ts +202 -0
- package/dist/esm/make/manifest.js +162 -0
- package/dist/esm/make/required-filtes.d.ts +1 -0
- package/dist/esm/make/required-filtes.js +11 -0
- package/dist/esm/make/task.d.ts +9 -0
- package/dist/esm/make/task.js +23 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/packages/docker/df.d.ts +543 -0
- package/dist/esm/packages/docker/df.js +381 -0
- package/dist/esm/packages/docker/validator.d.ts +7 -0
- package/dist/esm/packages/docker/validator.js +14 -0
- package/dist/esm/packages/utils/create-file.d.ts +1 -0
- package/dist/esm/packages/utils/create-file.js +11 -0
- package/dist/esm/packages/utils/date-string.d.ts +1 -0
- package/dist/esm/packages/utils/date-string.js +8 -0
- package/dist/esm/packages/utils/exception.d.ts +1 -0
- package/dist/esm/packages/utils/exception.js +4 -0
- package/dist/esm/packages/utils/hash-value.d.ts +16 -0
- package/dist/esm/packages/utils/hash-value.js +20 -0
- package/dist/esm/packages/utils/import-default.d.ts +1 -0
- package/dist/esm/packages/utils/import-default.js +10 -0
- package/dist/esm/packages/utils/import-file.d.ts +8 -0
- package/dist/esm/packages/utils/import-file.js +13 -0
- package/dist/esm/packages/utils/log-with-spinner.d.ts +1 -0
- package/dist/esm/packages/utils/log-with-spinner.js +17 -0
- package/dist/esm/packages/utils/path.d.ts +2 -0
- package/dist/esm/packages/utils/path.js +17 -0
- package/dist/esm/packages/utils/playground.d.ts +1 -0
- package/dist/esm/packages/utils/playground.js +11 -0
- package/dist/esm/scaffolding/add-env-var.d.ts +6 -0
- package/dist/esm/scaffolding/add-env-var.js +57 -0
- package/dist/esm/scaffolding/add-import.d.ts +16 -0
- package/dist/esm/scaffolding/add-import.js +39 -0
- package/dist/esm/scaffolding/add-script.d.ts +1 -0
- package/dist/esm/scaffolding/add-script.js +29 -0
- package/dist/esm/scaffolding/broadcast-workload.d.ts +1 -0
- package/dist/esm/scaffolding/broadcast-workload.js +30 -0
- package/dist/esm/scaffolding/bucket-workload.d.ts +6 -0
- package/dist/esm/scaffolding/bucket-workload.js +17 -0
- package/dist/esm/scaffolding/cron-workload.d.ts +6 -0
- package/dist/esm/scaffolding/cron-workload.js +22 -0
- package/dist/esm/scaffolding/drizzle.d.ts +4 -0
- package/dist/esm/scaffolding/drizzle.js +19 -0
- package/dist/esm/scaffolding/lifecycle.d.ts +9 -0
- package/dist/esm/scaffolding/lifecycle.js +53 -0
- package/dist/esm/scaffolding/postgres-database-workload.d.ts +15 -0
- package/dist/esm/scaffolding/postgres-database-workload.js +31 -0
- package/dist/esm/scaffolding/prisma.d.ts +4 -0
- package/dist/esm/scaffolding/prisma.js +34 -0
- package/dist/esm/scaffolding/replace-string.d.ts +10 -0
- package/dist/esm/scaffolding/replace-string.js +30 -0
- package/dist/esm/scaffolding/task-workload.d.ts +6 -0
- package/dist/esm/scaffolding/task-workload.js +24 -0
- package/dist/esm/scaffolding/workload.d.ts +1 -0
- package/dist/esm/scaffolding/workload.js +12 -0
- package/dist/esm/scan/project.d.ts +23 -0
- package/dist/esm/scan/project.js +69 -0
- package/dist/esm/scan/workload-imports.d.ts +21 -0
- package/dist/esm/scan/workload-imports.js +144 -0
- package/dist/esm/test-helpers/postgres.d.ts +13 -0
- package/dist/esm/test-helpers/postgres.js +26 -0
- package/dist/esm/test-helpers/redis.d.ts +13 -0
- package/dist/esm/test-helpers/redis.js +20 -0
- package/dist/esm/test-helpers/task.d.ts +14 -0
- package/dist/esm/test-helpers/task.js +14 -0
- package/dist/esm/test-helpers.d.ts +3 -0
- package/dist/esm/test-helpers.js +3 -0
- package/dist/esm/workloads/app-lifecycle/after-rollout.d.ts +22 -0
- package/dist/esm/workloads/app-lifecycle/after-rollout.js +24 -0
- package/dist/esm/workloads/app-lifecycle/before-rollout.d.ts +22 -0
- package/dist/esm/workloads/app-lifecycle/before-rollout.js +24 -0
- package/dist/esm/workloads/app-lifecycle/bootstrap.d.ts +22 -0
- package/dist/esm/workloads/app-lifecycle/bootstrap.js +24 -0
- package/dist/esm/workloads/app-lifecycle/lifecycle-workload.d.ts +11 -0
- package/dist/esm/workloads/app-lifecycle/lifecycle-workload.js +7 -0
- package/dist/esm/workloads/assertions.d.ts +13 -0
- package/dist/esm/workloads/assertions.js +6 -0
- package/dist/esm/workloads/stateful/bucket.d.ts +82 -0
- package/dist/esm/workloads/stateful/bucket.js +95 -0
- package/dist/esm/workloads/stateful/database.d.ts +25 -0
- package/dist/esm/workloads/stateful/database.js +42 -0
- package/dist/esm/workloads/stateful/postgres-database.d.ts +29 -0
- package/dist/esm/workloads/stateful/postgres-database.js +35 -0
- package/dist/esm/workloads/stateful/redis.d.ts +30 -0
- package/dist/esm/workloads/stateful/redis.js +36 -0
- package/dist/esm/workloads/stateful/stateful-workload.d.ts +25 -0
- package/dist/esm/workloads/stateful/stateful-workload.js +41 -0
- package/dist/esm/workloads/stateless/broadcast/channel-data.d.ts +3 -0
- package/dist/esm/workloads/stateless/broadcast/channel-data.js +2 -0
- package/dist/esm/workloads/stateless/broadcast/client/app-sync-client.d.ts +78 -0
- package/dist/esm/workloads/stateless/broadcast/client/app-sync-client.js +130 -0
- package/dist/esm/workloads/stateless/broadcast/client/app-sync-publisher.d.ts +34 -0
- package/dist/esm/workloads/stateless/broadcast/client/app-sync-publisher.js +76 -0
- package/dist/esm/workloads/stateless/broadcast/client/authenticator.d.ts +28 -0
- package/dist/esm/workloads/stateless/broadcast/client/authenticator.js +39 -0
- package/dist/esm/workloads/stateless/broadcast/client/broadcast-provider.d.ts +17 -0
- package/dist/esm/workloads/stateless/broadcast/client/broadcast-provider.js +29 -0
- package/dist/esm/workloads/stateless/broadcast/client/client.d.ts +8 -0
- package/dist/esm/workloads/stateless/broadcast/client/client.js +25 -0
- package/dist/esm/workloads/stateless/broadcast/client/connectionManager.d.ts +62 -0
- package/dist/esm/workloads/stateless/broadcast/client/connectionManager.js +164 -0
- package/dist/esm/workloads/stateless/broadcast/client/eventEmitter.d.ts +32 -0
- package/dist/esm/workloads/stateless/broadcast/client/eventEmitter.js +50 -0
- package/dist/esm/workloads/stateless/broadcast/client/messageBuilder.d.ts +24 -0
- package/dist/esm/workloads/stateless/broadcast/client/messageBuilder.js +39 -0
- package/dist/esm/workloads/stateless/broadcast/client/parser.d.ts +12 -0
- package/dist/esm/workloads/stateless/broadcast/client/parser.js +19 -0
- package/dist/esm/workloads/stateless/broadcast/client/provider.d.ts +4 -0
- package/dist/esm/workloads/stateless/broadcast/client/provider.js +8 -0
- package/dist/esm/workloads/stateless/broadcast/client/subscriptionManager.d.ts +34 -0
- package/dist/esm/workloads/stateless/broadcast/client/subscriptionManager.js +91 -0
- package/dist/esm/workloads/stateless/broadcast/client/types.d.ts +72 -0
- package/dist/esm/workloads/stateless/broadcast/client/types.js +5 -0
- package/dist/esm/workloads/stateless/broadcast/matcher.d.ts +13 -0
- package/dist/esm/workloads/stateless/broadcast/matcher.js +43 -0
- package/dist/esm/workloads/stateless/broadcast/router.d.ts +103 -0
- package/dist/esm/workloads/stateless/broadcast/router.js +93 -0
- package/dist/esm/workloads/stateless/broadcast/server/broadcast-server.d.ts +2 -0
- package/dist/esm/workloads/stateless/broadcast/server/broadcast-server.js +316 -0
- package/dist/esm/workloads/stateless/broadcast/types.d.ts +17 -0
- package/dist/esm/workloads/stateless/broadcast/types.js +1 -0
- package/dist/esm/workloads/stateless/cron.d.ts +49 -0
- package/dist/esm/workloads/stateless/cron.js +52 -0
- package/dist/esm/workloads/stateless/stateless-workload.d.ts +3 -0
- package/dist/esm/workloads/stateless/stateless-workload.js +8 -0
- package/dist/esm/workloads/stateless/task/backoffs.d.ts +9 -0
- package/dist/esm/workloads/stateless/task/backoffs.js +14 -0
- package/dist/esm/workloads/stateless/task/dispatcher.d.ts +3 -0
- package/dist/esm/workloads/stateless/task/dispatcher.js +18 -0
- package/dist/esm/workloads/stateless/task/local.d.ts +14 -0
- package/dist/esm/workloads/stateless/task/local.js +48 -0
- package/dist/esm/workloads/stateless/task/perform-later.d.ts +2 -0
- package/dist/esm/workloads/stateless/task/perform-later.js +4 -0
- package/dist/esm/workloads/stateless/task/perform-now.d.ts +5 -0
- package/dist/esm/workloads/stateless/task/perform-now.js +18 -0
- package/dist/esm/workloads/stateless/task/perform.d.ts +7 -0
- package/dist/esm/workloads/stateless/task/perform.js +8 -0
- package/dist/esm/workloads/stateless/task/task.d.ts +88 -0
- package/dist/esm/workloads/stateless/task/task.js +59 -0
- package/dist/esm/workloads/stateless/task/validate-data-size.d.ts +1 -0
- package/dist/esm/workloads/stateless/task/validate-data-size.js +7 -0
- package/dist/esm/workloads/workload.d.ts +14 -0
- package/dist/esm/workloads/workload.js +16 -0
- package/dist/esm/workloads.d.ts +22 -0
- package/dist/esm/workloads.js +13 -0
- package/package.json +155 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { StatelessWorkload } from "../../workloads/stateless/stateless-workload.js";
|
|
2
|
+
export interface CronOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Function with the code that will be executed.
|
|
5
|
+
*/
|
|
6
|
+
run: () => Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Schedule in crontab format.
|
|
9
|
+
*/
|
|
10
|
+
schedule: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Workload for recurring tasks.
|
|
14
|
+
*
|
|
15
|
+
* A Cron workload is initialized with a unique id and the following options:
|
|
16
|
+
*
|
|
17
|
+
* - `schedule` in [unix-cron](https://man7.org/linux/man-pages/man5/crontab.5.html)
|
|
18
|
+
* format to specify when it should run.
|
|
19
|
+
*
|
|
20
|
+
* - `run` function with the code that will be executed.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { Cron } from "@monolayer/sdk";
|
|
25
|
+
*
|
|
26
|
+
* const reports = new Cron("reports", {
|
|
27
|
+
* schedule: "* * * * *",
|
|
28
|
+
* run: async () => {
|
|
29
|
+
* // Do something;
|
|
30
|
+
* },
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* export default reports;
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class Cron extends StatelessWorkload {
|
|
37
|
+
/**
|
|
38
|
+
* Unique ID
|
|
39
|
+
*/
|
|
40
|
+
id: string;
|
|
41
|
+
options: CronOptions;
|
|
42
|
+
run: () => Promise<void>;
|
|
43
|
+
schedule: string;
|
|
44
|
+
constructor(
|
|
45
|
+
/**
|
|
46
|
+
* Unique ID
|
|
47
|
+
*/
|
|
48
|
+
id: string, options: CronOptions);
|
|
49
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import cronParser from "cron-parser";
|
|
2
|
+
import { StatelessWorkload } from "../../workloads/stateless/stateless-workload.js";
|
|
3
|
+
/**
|
|
4
|
+
* Workload for recurring tasks.
|
|
5
|
+
*
|
|
6
|
+
* A Cron workload is initialized with a unique id and the following options:
|
|
7
|
+
*
|
|
8
|
+
* - `schedule` in [unix-cron](https://man7.org/linux/man-pages/man5/crontab.5.html)
|
|
9
|
+
* format to specify when it should run.
|
|
10
|
+
*
|
|
11
|
+
* - `run` function with the code that will be executed.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { Cron } from "@monolayer/sdk";
|
|
16
|
+
*
|
|
17
|
+
* const reports = new Cron("reports", {
|
|
18
|
+
* schedule: "* * * * *",
|
|
19
|
+
* run: async () => {
|
|
20
|
+
* // Do something;
|
|
21
|
+
* },
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* export default reports;
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export class Cron extends StatelessWorkload {
|
|
28
|
+
id;
|
|
29
|
+
options;
|
|
30
|
+
run;
|
|
31
|
+
schedule;
|
|
32
|
+
constructor(
|
|
33
|
+
/**
|
|
34
|
+
* Unique ID
|
|
35
|
+
*/
|
|
36
|
+
id, options) {
|
|
37
|
+
super(id);
|
|
38
|
+
this.id = id;
|
|
39
|
+
this.options = options;
|
|
40
|
+
this.run = options.run;
|
|
41
|
+
this.schedule = parseSchedule(options.schedule);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function parseSchedule(schedule) {
|
|
45
|
+
try {
|
|
46
|
+
const parsed = cronParser.parseExpression(schedule);
|
|
47
|
+
return parsed.stringify();
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
throw new Error(`Failed to parse schedule: ${schedule}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ConstantBackoff {
|
|
2
|
+
type: "constant";
|
|
3
|
+
delay: number;
|
|
4
|
+
}
|
|
5
|
+
export interface ExponentialBackoff {
|
|
6
|
+
type: "exponential";
|
|
7
|
+
delay: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function computeBackoff(attemptsMade: number, backoff?: ExponentialBackoff | ConstantBackoff): number;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function computeBackoff(attemptsMade, backoff) {
|
|
2
|
+
if (backoff !== undefined) {
|
|
3
|
+
switch (backoff.type) {
|
|
4
|
+
case "constant":
|
|
5
|
+
return backoff.delay;
|
|
6
|
+
case "exponential":
|
|
7
|
+
if (backoff.delay < 0 || attemptsMade < 0) {
|
|
8
|
+
throw new Error("Retry number cannot be less that 0");
|
|
9
|
+
}
|
|
10
|
+
return Math.round(Math.pow(2, attemptsMade) * backoff.delay);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { developmentDispatch, testDispatch, } from "../../../workloads/stateless/task/local.js";
|
|
2
|
+
export const dispatcherAdapterSymbol = Symbol.for("@monolayer/sdk-task-dispacher");
|
|
3
|
+
const TASK_DISPATCHER_SYMBOL = Symbol.for("@monolayer/sdk/task-dispatcher");
|
|
4
|
+
export async function dispatcher() {
|
|
5
|
+
if (process.env.NODE_ENV === "production") {
|
|
6
|
+
// @ts-expect-error defined at runtime
|
|
7
|
+
const dispatcher = globalThis[TASK_DISPATCHER_SYMBOL];
|
|
8
|
+
if (dispatcher === undefined)
|
|
9
|
+
throw new Error(`undefined dispatcher`);
|
|
10
|
+
return dispatcher;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
if (process.env.NODE_ENV === "test") {
|
|
14
|
+
return testDispatch;
|
|
15
|
+
}
|
|
16
|
+
return developmentDispatch;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ExecutionId } from "../../../workloads/stateless/task/perform-now.js";
|
|
2
|
+
import type { PerformOptions, Task } from "../../../workloads/stateless/task/task.js";
|
|
3
|
+
export declare function developmentDispatch<P>(task: Task<P>, data: P | P[], options?: PerformOptions): Promise<ExecutionId | ExecutionId[]>;
|
|
4
|
+
export declare function testDispatch<P>(task: Task<P>, data: P | P[], options?: PerformOptions): Promise<ExecutionId | ExecutionId[]>;
|
|
5
|
+
export declare const testDispatchers: Record<string, {
|
|
6
|
+
executionId: ExecutionId;
|
|
7
|
+
data: unknown;
|
|
8
|
+
}[]>;
|
|
9
|
+
export declare function dispatcherForTask<P>(task: Task<P>): DispatcherTask<P>[];
|
|
10
|
+
interface DispatcherTask<P> {
|
|
11
|
+
executionId: ExecutionId;
|
|
12
|
+
data: P;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { remember } from "@epic-web/remember";
|
|
2
|
+
import { randomUUID } from "crypto";
|
|
3
|
+
import { performNow, } from "../../../workloads/stateless/task/perform-now.js";
|
|
4
|
+
export async function developmentDispatch(task, data,
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
+
options) {
|
|
7
|
+
if (Array.isArray(data)) {
|
|
8
|
+
const executionId = [];
|
|
9
|
+
for (const single of data) {
|
|
10
|
+
await performNow(task, single);
|
|
11
|
+
executionId.push(randomUUID());
|
|
12
|
+
}
|
|
13
|
+
return executionId;
|
|
14
|
+
}
|
|
15
|
+
await performNow(task, data);
|
|
16
|
+
return randomUUID();
|
|
17
|
+
}
|
|
18
|
+
export async function testDispatch(task, data,
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
20
|
+
options) {
|
|
21
|
+
const testDispather = dispatcherForTask(task);
|
|
22
|
+
if (Array.isArray(data)) {
|
|
23
|
+
const executionIds = [];
|
|
24
|
+
const executionId = randomUUID();
|
|
25
|
+
for (const single of data) {
|
|
26
|
+
testDispather.push({
|
|
27
|
+
executionId,
|
|
28
|
+
data: single,
|
|
29
|
+
});
|
|
30
|
+
executionIds.push(executionId);
|
|
31
|
+
}
|
|
32
|
+
return executionIds;
|
|
33
|
+
}
|
|
34
|
+
const executionId = randomUUID();
|
|
35
|
+
testDispather.push({
|
|
36
|
+
executionId: executionId,
|
|
37
|
+
data: data,
|
|
38
|
+
});
|
|
39
|
+
return executionId;
|
|
40
|
+
}
|
|
41
|
+
export const testDispatchers = remember("TestDispatchers", () => ({}));
|
|
42
|
+
export function dispatcherForTask(task) {
|
|
43
|
+
const queueKey = task.id;
|
|
44
|
+
if (testDispatchers[queueKey] === undefined) {
|
|
45
|
+
testDispatchers[queueKey] = [];
|
|
46
|
+
}
|
|
47
|
+
return testDispatchers[queueKey];
|
|
48
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { randomUUID } from "crypto";
|
|
2
|
+
import workAndHandleError from "../../../workloads/stateless/task/perform.js";
|
|
3
|
+
export async function performNow(task, data) {
|
|
4
|
+
if (!Array.isArray(data)) {
|
|
5
|
+
const taskId = randomUUID();
|
|
6
|
+
await workAndHandleError({ task, taskId, data });
|
|
7
|
+
return taskId;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
const taskIds = [];
|
|
11
|
+
for (const singlePayload of data) {
|
|
12
|
+
const taskId = randomUUID();
|
|
13
|
+
await workAndHandleError({ task, taskId, data: singlePayload });
|
|
14
|
+
taskIds.push(taskId);
|
|
15
|
+
}
|
|
16
|
+
return taskIds;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { ConstantBackoff, ExponentialBackoff } from "../../../workloads/stateless/task/backoffs.js";
|
|
2
|
+
import { Workload } from "../../../workloads/workload.js";
|
|
3
|
+
export declare class Task<P> extends Workload {
|
|
4
|
+
/**
|
|
5
|
+
* Name of the task.
|
|
6
|
+
*/
|
|
7
|
+
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* Function that processes a task.
|
|
10
|
+
*/
|
|
11
|
+
work: (task: {
|
|
12
|
+
taskId: string;
|
|
13
|
+
data: P;
|
|
14
|
+
}) => Promise<void>;
|
|
15
|
+
options?: TaskOptions<P> | undefined;
|
|
16
|
+
constructor(
|
|
17
|
+
/**
|
|
18
|
+
* Name of the task.
|
|
19
|
+
*/
|
|
20
|
+
name: string,
|
|
21
|
+
/**
|
|
22
|
+
* Function that processes a task.
|
|
23
|
+
*/
|
|
24
|
+
work: (task: {
|
|
25
|
+
taskId: string;
|
|
26
|
+
data: P;
|
|
27
|
+
}) => Promise<void>, options?: TaskOptions<P> | undefined);
|
|
28
|
+
/**
|
|
29
|
+
* Performs the task immediately in the current processs.
|
|
30
|
+
*/
|
|
31
|
+
performNow(data: P | P[]): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Performs the task later, dispatching the task to a queue.
|
|
34
|
+
*
|
|
35
|
+
* **NOTES**
|
|
36
|
+
*
|
|
37
|
+
* In development, the task will be performed immediately.
|
|
38
|
+
*
|
|
39
|
+
* In test, the task will collected ans can be retrieved with the `performedTasks` test helper.
|
|
40
|
+
*/
|
|
41
|
+
performLater(data: P | P[], options?: PerformOptions): Promise<import("../../../workloads/stateless/task/perform-now.js").ExecutionId | import("../../../workloads/stateless/task/perform-now.js").ExecutionId[]>;
|
|
42
|
+
handleError(error?: unknown, data?: P, executionId?: string): void;
|
|
43
|
+
}
|
|
44
|
+
export interface TaskOptions<P> {
|
|
45
|
+
onError?: (error: TaskError<P>) => void;
|
|
46
|
+
retry?: RetryOptions;
|
|
47
|
+
}
|
|
48
|
+
export declare class TaskError<P> extends Error {
|
|
49
|
+
cause: TaskErrorCause<P>;
|
|
50
|
+
constructor(message: string, cause: TaskErrorCause<P>);
|
|
51
|
+
}
|
|
52
|
+
export type TaskErrorCause<P> = {
|
|
53
|
+
task: string;
|
|
54
|
+
executionId?: string;
|
|
55
|
+
data?: P;
|
|
56
|
+
error: unknown;
|
|
57
|
+
};
|
|
58
|
+
export interface RetryOptions {
|
|
59
|
+
/**
|
|
60
|
+
* The total number of attempts to try the job until it completes.
|
|
61
|
+
* @defaultValue 0
|
|
62
|
+
*/
|
|
63
|
+
times: number;
|
|
64
|
+
/**
|
|
65
|
+
* Backoff setting for automatic retries if the job fails.
|
|
66
|
+
*
|
|
67
|
+
* **Important**
|
|
68
|
+
*
|
|
69
|
+
* This setting does not have any effect on Tasks backed by an `SQS` queue in production.
|
|
70
|
+
*
|
|
71
|
+
* Retries will happen after the `VisibilityTimeout` of the message expires (30 seconds by default).
|
|
72
|
+
* See: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html#consumer-fails-to-process-message
|
|
73
|
+
*
|
|
74
|
+
* You can to implement an custom backoff strategy using a dead-letter queue to handle retries
|
|
75
|
+
* and a Lambda function.
|
|
76
|
+
*
|
|
77
|
+
* @defaultValue { type: "constant", delay: 0 }
|
|
78
|
+
*/
|
|
79
|
+
backoff?: ExponentialBackoff | ConstantBackoff;
|
|
80
|
+
}
|
|
81
|
+
export interface PerformOptions {
|
|
82
|
+
/**
|
|
83
|
+
* Amount in milliseconds to wait until this task can be processed.
|
|
84
|
+
*
|
|
85
|
+
* @defaultValue 0
|
|
86
|
+
*/
|
|
87
|
+
delay?: number;
|
|
88
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { kebabCase } from "case-anything";
|
|
2
|
+
import { performLater } from "../../../workloads/stateless/task/perform-later.js";
|
|
3
|
+
import { performNow } from "../../../workloads/stateless/task/perform-now.js";
|
|
4
|
+
import { Workload } from "../../../workloads/workload.js";
|
|
5
|
+
export class Task extends Workload {
|
|
6
|
+
name;
|
|
7
|
+
work;
|
|
8
|
+
options;
|
|
9
|
+
constructor(
|
|
10
|
+
/**
|
|
11
|
+
* Name of the task.
|
|
12
|
+
*/
|
|
13
|
+
name,
|
|
14
|
+
/**
|
|
15
|
+
* Function that processes a task.
|
|
16
|
+
*/
|
|
17
|
+
work, options) {
|
|
18
|
+
super(kebabCase(name));
|
|
19
|
+
this.name = name;
|
|
20
|
+
this.work = work;
|
|
21
|
+
this.options = options;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Performs the task immediately in the current processs.
|
|
25
|
+
*/
|
|
26
|
+
async performNow(data) {
|
|
27
|
+
await performNow(this, data);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Performs the task later, dispatching the task to a queue.
|
|
31
|
+
*
|
|
32
|
+
* **NOTES**
|
|
33
|
+
*
|
|
34
|
+
* In development, the task will be performed immediately.
|
|
35
|
+
*
|
|
36
|
+
* In test, the task will collected ans can be retrieved with the `performedTasks` test helper.
|
|
37
|
+
*/
|
|
38
|
+
async performLater(data, options) {
|
|
39
|
+
return await performLater(this, data, options);
|
|
40
|
+
}
|
|
41
|
+
handleError(error, data, executionId) {
|
|
42
|
+
if (this.options?.onError) {
|
|
43
|
+
this.options?.onError(new TaskError("Error while performing tasks", {
|
|
44
|
+
task: this.id,
|
|
45
|
+
executionId,
|
|
46
|
+
data,
|
|
47
|
+
error,
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
console.log(`An error was thrown in ${this.id} and the onError callback function is undefined.`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export class TaskError extends Error {
|
|
56
|
+
constructor(message, cause) {
|
|
57
|
+
super(message, { cause });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validateJsonStringified<P>(data: P, max?: number): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function validateJsonStringified(data, max = 256000) {
|
|
2
|
+
const dataString = JSON.stringify(typeof data === "undefined" ? {} : data);
|
|
3
|
+
const byteLength = Buffer.byteLength(dataString, "utf8");
|
|
4
|
+
if (byteLength > max) {
|
|
5
|
+
throw new Error(`Data size exceeds the limit (${max} bytes)`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module main
|
|
3
|
+
*/
|
|
4
|
+
export { ContainerConfig, type Configuration, } from "./configuration.js";
|
|
5
|
+
export { AfterRollout } from "./workloads/app-lifecycle/after-rollout.js";
|
|
6
|
+
export { BeforeRollout } from "./workloads/app-lifecycle/before-rollout.js";
|
|
7
|
+
export { Bootstrap } from "./workloads/app-lifecycle/bootstrap.js";
|
|
8
|
+
export { type LifecycleWorkload } from "./workloads/app-lifecycle/lifecycle-workload.js";
|
|
9
|
+
export { Bucket, BucketOptions, bucketLocalConfiguration, type AccessGrant, type PublicAccess, } from "./workloads/stateful/bucket.js";
|
|
10
|
+
export type { Database } from "./workloads/stateful/database.js";
|
|
11
|
+
export { PostgresDatabase } from "./workloads/stateful/postgres-database.js";
|
|
12
|
+
export { Redis } from "./workloads/stateful/redis.js";
|
|
13
|
+
export type { StatefulWorkload, StatefulWorkloadWithClient, } from "./workloads/stateful/stateful-workload.js";
|
|
14
|
+
export { ChannelData } from "./workloads/stateless/broadcast/channel-data.js";
|
|
15
|
+
export { broadcastClient } from "./workloads/stateless/broadcast/client/client.js";
|
|
16
|
+
export { Broadcast } from "./workloads/stateless/broadcast/router.js";
|
|
17
|
+
export type { StatelessWorkload } from "./workloads/stateless/stateless-workload.js";
|
|
18
|
+
export { Task, type RetryOptions, type TaskOptions, } from "./workloads/stateless/task/task.js";
|
|
19
|
+
export type { Workload } from "./workloads/workload.js";
|
|
20
|
+
export { Cron, type CronOptions } from "./workloads/stateless/cron.js";
|
|
21
|
+
export { BroadcastPublisher } from "./workloads/stateless/broadcast/client/app-sync-publisher.js";
|
|
22
|
+
export { Broadcast as BroadcastProvider } from "./workloads/stateless/broadcast/client/provider.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { AfterRollout } from "./workloads/app-lifecycle/after-rollout.js";
|
|
2
|
+
export { BeforeRollout } from "./workloads/app-lifecycle/before-rollout.js";
|
|
3
|
+
export { Bootstrap } from "./workloads/app-lifecycle/bootstrap.js";
|
|
4
|
+
export { Bucket, bucketLocalConfiguration, } from "./workloads/stateful/bucket.js";
|
|
5
|
+
export { PostgresDatabase } from "./workloads/stateful/postgres-database.js";
|
|
6
|
+
export { Redis } from "./workloads/stateful/redis.js";
|
|
7
|
+
export { ChannelData } from "./workloads/stateless/broadcast/channel-data.js";
|
|
8
|
+
export { broadcastClient } from "./workloads/stateless/broadcast/client/client.js";
|
|
9
|
+
export { Broadcast } from "./workloads/stateless/broadcast/router.js";
|
|
10
|
+
export { Task, } from "./workloads/stateless/task/task.js";
|
|
11
|
+
export { Cron } from "./workloads/stateless/cron.js";
|
|
12
|
+
export { BroadcastPublisher } from "./workloads/stateless/broadcast/client/app-sync-publisher.js";
|
|
13
|
+
export { Broadcast as BroadcastProvider } from "./workloads/stateless/broadcast/client/provider.js";
|