@lafken/schedule 0.10.1

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/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Aníbal Emilio Jorquera Cornejo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # @lafken/schedule
2
+
3
+ Define Amazon EventBridge scheduled rules using TypeScript decorators. `@lafken/schedule` lets you declare cron-based tasks directly on class methods — each one becomes a Lambda function invoked automatically by EventBridge at the specified times.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @lafken/schedule
9
+ ```
10
+
11
+ ## Getting Started
12
+
13
+ Define a schedule class with `@Schedule`, add `@Cron` methods, and register it through `ScheduleResolver`:
14
+
15
+ ```typescript
16
+ import { createApp, createModule } from '@lafken/main';
17
+ import { ScheduleResolver } from '@lafken/schedule/resolver';
18
+ import { Schedule, Cron } from '@lafken/schedule/main';
19
+
20
+ // 1. Define scheduled tasks
21
+ @Schedule()
22
+ export class MaintenanceJobs {
23
+ @Cron({ schedule: 'cron(0 3 * * ? *)' })
24
+ cleanupExpiredSessions() {
25
+ // Runs every day at 3:00 AM UTC
26
+ }
27
+
28
+ @Cron({ schedule: { hour: 0, minute: 0, weekDay: 'SUN' } })
29
+ generateWeeklyReport() {
30
+ // Runs every Sunday at midnight UTC
31
+ }
32
+ }
33
+
34
+ // 2. Register in a module
35
+ const maintenanceModule = createModule({
36
+ name: 'maintenance',
37
+ resources: [MaintenanceJobs],
38
+ });
39
+
40
+ // 3. Add the resolver to the app
41
+ createApp({
42
+ name: 'my-app',
43
+ resolvers: [new ScheduleResolver()],
44
+ modules: [maintenanceModule],
45
+ });
46
+ ```
47
+
48
+ Each `@Cron` method becomes an independent Lambda function with its own EventBridge rule.
49
+
50
+ ## Features
51
+
52
+ ### Schedule Class
53
+
54
+ Use the `@Schedule` decorator to group related cron tasks in a single class. The class itself holds no schedule logic — it acts as a container for `@Cron` handlers:
55
+
56
+ ```typescript
57
+ import { Schedule, Cron } from '@lafken/schedule/main';
58
+
59
+ @Schedule()
60
+ export class DataPipeline {
61
+ @Cron({ schedule: 'cron(0 6 * * ? *)' })
62
+ ingestData() { }
63
+
64
+ @Cron({ schedule: 'cron(30 6 * * ? *)' })
65
+ transformData() { }
66
+ }
67
+ ```
68
+
69
+ ### Cron Expression (String)
70
+
71
+ Pass a standard AWS cron expression as a string. The format follows:
72
+
73
+ ```
74
+ cron(Minutes Hours Day-of-month Month Day-of-week Year)
75
+ ```
76
+
77
+ ```typescript
78
+ @Cron({ schedule: 'cron(0 12 * * ? *)' })
79
+ sendDailyDigest() {
80
+ // Every day at 12:00 PM UTC
81
+ }
82
+
83
+ @Cron({ schedule: 'cron(0 9 1 * ? *)' })
84
+ generateMonthlyInvoice() {
85
+ // First day of every month at 9:00 AM UTC
86
+ }
87
+ ```
88
+
89
+ > [!NOTE]
90
+ > AWS cron expressions require either the day-of-month or day-of-week field to be `?`. You cannot specify both simultaneously. When using a cron string, include the full `cron(...)` wrapper.
91
+
92
+ ### Cron Expression (Object)
93
+
94
+ For a more readable alternative, use the `ScheduleTime` object format. Each field defaults to `'*'` when omitted:
95
+
96
+ ```typescript
97
+ @Cron({
98
+ schedule: {
99
+ minute: 0,
100
+ hour: 8,
101
+ weekDay: 'MON-FRI',
102
+ },
103
+ })
104
+ startBusinessHours() {
105
+ // Every weekday at 8:00 AM UTC
106
+ }
107
+
108
+ @Cron({
109
+ schedule: {
110
+ minute: 30,
111
+ hour: 22,
112
+ day: 15,
113
+ },
114
+ })
115
+ midMonthAudit() {
116
+ // 15th of every month at 10:30 PM UTC
117
+ }
118
+ ```
119
+
120
+ #### ScheduleTime Fields
121
+
122
+ | Field | Type | Default | Description |
123
+ | --------- | --------------------------- | ------- | -------------------- |
124
+ | `minute` | `number \| '*' \| '?'` | `'*'` | Minute (0–59) |
125
+ | `hour` | `number \| '*' \| '?'` | `'*'` | Hour (0–23) |
126
+ | `day` | `number \| '*' \| '?'` | `'*'` | Day of month (1–31) |
127
+ | `month` | `number \| '*' \| '?'` | `'*'` | Month (1–12) |
128
+ | `weekDay` | `number \| string \| '?'` | `'*'` | Day of week (SUN–SAT or 1–7) |
129
+ | `year` | `number \| '*' \| '?'` | `'*'` | Year |
130
+
131
+ When `day` is set to a specific value, `weekDay` is automatically set to `'?'` and vice versa, following the AWS cron constraint.
132
+
133
+ ### Retry Policy
134
+
135
+ Configure how EventBridge handles failed deliveries using `retryAttempts` and `maxEventAge`:
136
+
137
+ ```typescript
138
+ @Cron({
139
+ schedule: 'cron(0 0 * * ? *)',
140
+ retryAttempts: 3,
141
+ maxEventAge: 3600,
142
+ })
143
+ criticalNightlyJob() {
144
+ // Retries up to 3 times, discards events older than 1 hour
145
+ }
146
+ ```
147
+
148
+ | Option | Type | Description |
149
+ | --------------- | -------- | ---------------------------------------------------------- |
150
+ | `retryAttempts` | `number` | Maximum retry attempts if the target invocation fails |
151
+ | `maxEventAge` | `number` | Maximum event age in seconds before the event is discarded |
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './main';
2
+ export * from './resolver';
package/lib/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./main"), exports);
18
+ __exportStar(require("./resolver"), exports);
@@ -0,0 +1 @@
1
+ export * from './schedule';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./schedule"), exports);
@@ -0,0 +1,2 @@
1
+ export * from './schedule';
2
+ export * from './schedule.types';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./schedule"), exports);
18
+ __exportStar(require("./schedule.types"), exports);
@@ -0,0 +1,43 @@
1
+ import type { EventCronProps } from './schedule.types';
2
+ export declare const RESOURCE_TYPE: "CRON";
3
+ /**
4
+ * Class decorator that registers a class as a scheduled event resource.
5
+ *
6
+ * The decorated class groups one or more `@Cron` handler methods that
7
+ * are invoked on a time-based schedule via Amazon EventBridge.
8
+ *
9
+ * @param props - Optional resource configuration (e.g. a custom `name`).
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * @Schedule()
14
+ * export class MaintenanceJobs {
15
+ * @Cron({ schedule: { hour: 3, minute: 0 } })
16
+ * cleanup() { }
17
+ * }
18
+ * ```
19
+ */
20
+ export declare const Schedule: (props?: import("@lafken/common").ResourceProps | undefined) => (constructor: Function) => void;
21
+ /**
22
+ * Method decorator that registers a handler to run on a cron schedule.
23
+ *
24
+ * The decorated method becomes a Lambda function invoked automatically
25
+ * by EventBridge at the times defined by the `schedule` option. The
26
+ * schedule can be a standard AWS cron string or a structured
27
+ * `ScheduleTime` object.
28
+ *
29
+ * @param props - Schedule configuration (schedule expression, maxEventAge,
30
+ * retryAttempts).
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * // Using a cron string (every day at midnight UTC)
35
+ * @Cron({ schedule: 'cron(0 0 * * ? *)' })
36
+ * dailyReport() { }
37
+ *
38
+ * // Using a ScheduleTime object (every Monday at 8:30 AM)
39
+ * @Cron({ schedule: { weekDay: 'MON', hour: 8, minute: 30 } })
40
+ * weeklyDigest() { }
41
+ * ```
42
+ */
43
+ export declare const Cron: (props: EventCronProps) => (target: any, methodName: string, descriptor: PropertyDescriptor) => any;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Cron = exports.Schedule = exports.RESOURCE_TYPE = void 0;
4
+ const common_1 = require("@lafken/common");
5
+ exports.RESOURCE_TYPE = 'CRON';
6
+ /**
7
+ * Class decorator that registers a class as a scheduled event resource.
8
+ *
9
+ * The decorated class groups one or more `@Cron` handler methods that
10
+ * are invoked on a time-based schedule via Amazon EventBridge.
11
+ *
12
+ * @param props - Optional resource configuration (e.g. a custom `name`).
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * @Schedule()
17
+ * export class MaintenanceJobs {
18
+ * @Cron({ schedule: { hour: 3, minute: 0 } })
19
+ * cleanup() { }
20
+ * }
21
+ * ```
22
+ */
23
+ exports.Schedule = (0, common_1.createResourceDecorator)({
24
+ type: exports.RESOURCE_TYPE,
25
+ callerFileIndex: 5,
26
+ });
27
+ /**
28
+ * Method decorator that registers a handler to run on a cron schedule.
29
+ *
30
+ * The decorated method becomes a Lambda function invoked automatically
31
+ * by EventBridge at the times defined by the `schedule` option. The
32
+ * schedule can be a standard AWS cron string or a structured
33
+ * `ScheduleTime` object.
34
+ *
35
+ * @param props - Schedule configuration (schedule expression, maxEventAge,
36
+ * retryAttempts).
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * // Using a cron string (every day at midnight UTC)
41
+ * @Cron({ schedule: 'cron(0 0 * * ? *)' })
42
+ * dailyReport() { }
43
+ *
44
+ * // Using a ScheduleTime object (every Monday at 8:30 AM)
45
+ * @Cron({ schedule: { weekDay: 'MON', hour: 8, minute: 30 } })
46
+ * weeklyDigest() { }
47
+ * ```
48
+ */
49
+ const Cron = (props) => (0, common_1.createLambdaDecorator)({
50
+ getLambdaMetadata: (props, methodName) => ({
51
+ ...props,
52
+ name: methodName,
53
+ }),
54
+ })(props);
55
+ exports.Cron = Cron;
@@ -0,0 +1,70 @@
1
+ import type { LambdaMetadata, ResourceOutputType } from '@lafken/common';
2
+ type ScheduleExpressions = number | '*' | '?' | (string & {});
3
+ /**
4
+ * Attributes that can be exported from an EventBridge schedule rule resource.
5
+ *
6
+ * Based on Terraform `aws_cloudwatch_event_rule` attribute reference:
7
+ * - `arn`: The Amazon Resource Name (ARN) of the rule.
8
+ * - `id`: The name of the rule.
9
+ */
10
+ export type ScheduleOutputAttributes = 'arn' | 'id';
11
+ export interface ScheduleTime {
12
+ day?: ScheduleExpressions;
13
+ hour?: ScheduleExpressions;
14
+ minute?: ScheduleExpressions;
15
+ month?: ScheduleExpressions;
16
+ weekDay?: ScheduleExpressions;
17
+ year?: ScheduleExpressions;
18
+ }
19
+ export interface EventCronProps {
20
+ /**
21
+ * Maximum event age.
22
+ *
23
+ * Specifies the maximum age of an event that can be sent to the rule's targets.
24
+ * Events older than this duration will be discarded.
25
+ */
26
+ maxEventAge?: number;
27
+ /**
28
+ * Retry attempts for failed events.
29
+ *
30
+ * Specifies the maximum number of times EventBridge will retry sending
31
+ * an event to the target if the initial attempt fails.
32
+ */
33
+ retryAttempts?: number;
34
+ /**
35
+ * Schedule for the EventBridge rule.
36
+ *
37
+ * Defines when the rule should trigger, either using a cron expression
38
+ * or a structured schedule object. This allows for time-based Lambda invocation
39
+ *
40
+ * You can provide:
41
+ * - A cron string in the standard AWS format: `cron(* * * * * *)`
42
+ * - A `ScheduleTime` object to specify individual fields:
43
+ * - `minute`, `hour`, `day`, `month`, `weekDay`, `year`
44
+ * - Each field can be a number, '*', '?', a range `${number}-${number}`
45
+ */
46
+ schedule: string | ScheduleTime;
47
+ /**
48
+ * Defines which EventBridge schedule rule attributes should be exported.
49
+ *
50
+ * Supported attributes are based on Terraform `aws_cloudwatch_event_rule`
51
+ * attribute reference:
52
+ * - `arn`: The Amazon Resource Name (ARN) of the rule.
53
+ * - `id`: The name of the rule.
54
+ *
55
+ * Each selected attribute can be exported through SSM Parameter Store (`type: 'ssm'`)
56
+ * or Terraform outputs (`type: 'output'`).
57
+ *
58
+ * @example
59
+ * {
60
+ * outputs: [
61
+ * { type: 'ssm', name: '/my-app/schedule-arn', value: 'arn' },
62
+ * { type: 'output', name: 'schedule_id', value: 'id' }
63
+ * ]
64
+ * }
65
+ */
66
+ outputs?: ResourceOutputType<ScheduleOutputAttributes>;
67
+ }
68
+ export interface EventCronMetadata extends LambdaMetadata, EventCronProps {
69
+ }
70
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ import { CloudwatchEventRule } from '@cdktn/provider-aws/lib/cloudwatch-event-rule';
2
+ import { type AppModule } from '@lafken/resolver';
3
+ import type { CronProps } from './cron.types';
4
+ declare const Cron_base: (new (...args: any[]) => {
5
+ isGlobal(module: import("@lafken/common").ModuleGlobalReferenceNames | (string & {}), id: string): void;
6
+ isDependent(resolveDependency: () => void): void;
7
+ readonly node: import("constructs").Node;
8
+ with(...mixins: import("constructs").IMixin[]): import("constructs").IConstruct;
9
+ toString(): string;
10
+ }) & typeof CloudwatchEventRule;
11
+ export declare class Cron extends Cron_base {
12
+ private props;
13
+ constructor(scope: AppModule, id: string, props: CronProps);
14
+ addEventTarget(id: string): void;
15
+ private static buildScheduleExpression;
16
+ }
17
+ export {};
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Cron = void 0;
4
+ const cloudwatch_event_rule_1 = require("@cdktn/provider-aws/lib/cloudwatch-event-rule");
5
+ const cloudwatch_event_target_1 = require("@cdktn/provider-aws/lib/cloudwatch-event-target");
6
+ const resolver_1 = require("@lafken/resolver");
7
+ class Cron extends resolver_1.lafkenResource.make(cloudwatch_event_rule_1.CloudwatchEventRule) {
8
+ props;
9
+ constructor(scope, id, props) {
10
+ const { handler } = props;
11
+ super(scope, `${handler.name}-cron`, {
12
+ name: handler.name,
13
+ scheduleExpression: Cron.buildScheduleExpression(handler.schedule),
14
+ });
15
+ this.props = props;
16
+ this.isGlobal(scope.id, id);
17
+ this.addEventTarget(id);
18
+ new resolver_1.ResourceOutput(this, handler.outputs);
19
+ }
20
+ addEventTarget(id) {
21
+ const { handler, resourceMetadata } = this.props;
22
+ const lambdaHandler = new resolver_1.LambdaHandler(this, `${handler.name}-${resourceMetadata.name}`, {
23
+ ...handler,
24
+ originalName: resourceMetadata.originalName,
25
+ filename: resourceMetadata.filename,
26
+ foldername: resourceMetadata.foldername,
27
+ suffix: 'event',
28
+ principal: 'events.amazonaws.com',
29
+ sourceArn: this.arn,
30
+ });
31
+ new cloudwatch_event_target_1.CloudwatchEventTarget(this, `${id}-event-target`, {
32
+ rule: this.name,
33
+ arn: lambdaHandler.arn,
34
+ retryPolicy: {
35
+ maximumRetryAttempts: handler.retryAttempts,
36
+ maximumEventAgeInSeconds: handler.maxEventAge,
37
+ },
38
+ });
39
+ }
40
+ static buildScheduleExpression(schedule) {
41
+ if (typeof schedule === 'string') {
42
+ return `cron(${schedule})`;
43
+ }
44
+ const { minute = '*', hour = '*', day = '*', month = '*', year = '*', weekDay = '*', } = schedule;
45
+ let dayValue;
46
+ let weekDayValue;
47
+ if (day && day !== '*' && day !== '?') {
48
+ dayValue = day.toString();
49
+ weekDayValue = '?';
50
+ }
51
+ else if (weekDay && weekDay !== '*' && weekDay !== '?') {
52
+ dayValue = '?';
53
+ weekDayValue = weekDay.toString();
54
+ }
55
+ else {
56
+ dayValue = day?.toString() ?? '*';
57
+ weekDayValue = '?';
58
+ }
59
+ return `cron(${minute} ${hour} ${dayValue} ${month} ${weekDayValue} ${year})`;
60
+ }
61
+ }
62
+ exports.Cron = Cron;
@@ -0,0 +1,6 @@
1
+ import type { ResourceMetadata } from '@lafken/common';
2
+ import type { EventCronMetadata } from '../../main';
3
+ export interface CronProps {
4
+ resourceMetadata: ResourceMetadata;
5
+ handler: EventCronMetadata;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export * from './resolver';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./resolver"), exports);
@@ -0,0 +1,6 @@
1
+ import { type ClassResource } from '@lafken/common';
2
+ import { type AppModule, type ResolverType } from '@lafken/resolver';
3
+ export declare class ScheduleResolver implements ResolverType {
4
+ type: "CRON";
5
+ create(module: AppModule, resource: ClassResource): void;
6
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScheduleResolver = void 0;
4
+ const common_1 = require("@lafken/common");
5
+ const resolver_1 = require("@lafken/resolver");
6
+ const main_1 = require("../main");
7
+ const cron_1 = require("./cron/cron");
8
+ class ScheduleResolver {
9
+ type = main_1.RESOURCE_TYPE;
10
+ create(module, resource) {
11
+ const metadata = (0, common_1.getResourceMetadata)(resource);
12
+ const handlers = (0, common_1.getResourceHandlerMetadata)(resource);
13
+ resolver_1.lambdaAssets.initializeMetadata({
14
+ foldername: metadata.foldername,
15
+ filename: metadata.filename,
16
+ minify: metadata.minify,
17
+ className: metadata.originalName,
18
+ methods: handlers.map((handler) => handler.name),
19
+ });
20
+ for (const handler of handlers) {
21
+ const id = `${handler.name}-${metadata.name}`;
22
+ new cron_1.Cron(module, id, {
23
+ handler,
24
+ resourceMetadata: metadata,
25
+ });
26
+ }
27
+ }
28
+ }
29
+ exports.ScheduleResolver = ScheduleResolver;
package/package.json ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "@lafken/schedule",
3
+ "version": "0.10.1",
4
+ "private": false,
5
+ "description": "Define EventBridge scheduled rules and cron jobs using TypeScript decorators with Lafken",
6
+ "keywords": [
7
+ "aws",
8
+ "eventbridge",
9
+ "schedule",
10
+ "cron",
11
+ "scheduling",
12
+ "serverless",
13
+ "typescript",
14
+ "decorators",
15
+ "lafken"
16
+ ],
17
+ "homepage": "https://github.com/Hero64/lafken#readme",
18
+ "bugs": "https://github.com/Hero64/lafken/issues",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/Hero64/lafken",
22
+ "directory": "packages/schedule"
23
+ },
24
+ "license": "MIT",
25
+ "author": "Aníbal Jorquera",
26
+ "exports": {
27
+ "./main": {
28
+ "import": "./lib/main/index.js",
29
+ "types": "./lib/main/index.d.ts",
30
+ "require": "./lib/main/index.js"
31
+ },
32
+ "./resolver": {
33
+ "import": "./lib/resolver/index.js",
34
+ "types": "./lib/resolver/index.d.ts",
35
+ "require": "./lib/resolver/index.js"
36
+ }
37
+ },
38
+ "typesVersions": {
39
+ "*": {
40
+ "main": [
41
+ "./lib/main/index.d.ts"
42
+ ],
43
+ "resolver": [
44
+ "./lib/resolver/index.d.ts"
45
+ ]
46
+ }
47
+ },
48
+ "files": [
49
+ "lib"
50
+ ],
51
+ "dependencies": {
52
+ "reflect-metadata": "^0.2.2",
53
+ "@lafken/resolver": "0.10.1"
54
+ },
55
+ "devDependencies": {
56
+ "@cdktn/provider-aws": "^23.5.0",
57
+ "@swc/core": "^1.15.21",
58
+ "@swc/helpers": "^0.5.20",
59
+ "@vitest/runner": "^4.1.2",
60
+ "cdktn": "^0.22.1",
61
+ "cdktn-vitest": "^1.0.0",
62
+ "constructs": "^10.6.0",
63
+ "typescript": "6.0.2",
64
+ "unplugin-swc": "^1.5.9",
65
+ "vitest": "^4.1.2",
66
+ "@lafken/common": "0.10.1"
67
+ },
68
+ "peerDependencies": {
69
+ "@cdktn/provider-aws": ">=23.0.0",
70
+ "@lafken/common": "0.7.0",
71
+ "cdktn": ">=0.22.0",
72
+ "constructs": "^10.4.5"
73
+ },
74
+ "engines": {
75
+ "node": ">=20.19"
76
+ },
77
+ "publishConfig": {
78
+ "access": "public"
79
+ },
80
+ "scripts": {
81
+ "build": "pnpm clean && tsc -p ./tsconfig.build.json",
82
+ "check-types": "tsc --noEmit -p ./tsconfig.build.json",
83
+ "clean": "rm -rf ./lib",
84
+ "dev": "tsc -w",
85
+ "test": "vitest"
86
+ }
87
+ }