@turbofy-ai/app-runtime 0.0.9 → 0.0.10

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/dist/src/dsl.d.ts CHANGED
@@ -1639,8 +1639,30 @@ export interface ITableDataChangeTrigger<TName extends string, TOperation extend
1639
1639
  new: ITriggerData;
1640
1640
  } : ITriggerData;
1641
1641
  }
1642
+ export type IScheduleRateUnit = "minutes" | "hours" | "days";
1643
+ export interface IScheduleRate {
1644
+ value: number;
1645
+ unit: IScheduleRateUnit;
1646
+ }
1642
1647
  export interface IScheduledTrigger<TName extends string> extends ISharedTriggerDeclaration<TName> {
1643
1648
  variant: TriggerVariantEnum.SCHEDULE;
1649
+ /**
1650
+ * AWS 6-field cron expression: minutes hours day-of-month month
1651
+ * day-of-week year (e.g. "0 9 * * ? *" — daily at 9:00).
1652
+ * Exactly one of `cron` and `rate` must be set for the trigger to fire.
1653
+ */
1654
+ cron?: string;
1655
+ /** Fixed-interval alternative to `cron` (e.g. every 10 minutes). */
1656
+ rate?: IScheduleRate;
1657
+ /** IANA timezone the cron expression is evaluated in. Defaults to UTC. */
1658
+ timezone?: string;
1659
+ /**
1660
+ * ISO 8601 date (e.g. "2026-08-01") or datetime before which the schedule
1661
+ * does not fire. Date-only values are interpreted as midnight UTC.
1662
+ */
1663
+ startDate?: string;
1664
+ /** ISO 8601 date or datetime after which the schedule no longer fires. */
1665
+ endDate?: string;
1644
1666
  _tsTriggerData: unknown;
1645
1667
  }
1646
1668
  export interface IManualTrigger<TName extends string> extends ISharedTriggerDeclaration<TName> {
@@ -1946,6 +1968,33 @@ export interface ITableDataChangeTriggerOptions {
1946
1968
  export interface ISharedTriggerOptions {
1947
1969
  condition?: string;
1948
1970
  }
1971
+ export type IScheduleTriggerOptions = ISharedTriggerOptions & {
1972
+ /**
1973
+ * ISO 8601 date (e.g. "2026-08-01") or datetime before which the schedule
1974
+ * does not fire. Date-only values are interpreted as midnight UTC.
1975
+ */
1976
+ startDate?: string;
1977
+ /** ISO 8601 date or datetime after which the schedule no longer fires. */
1978
+ endDate?: string;
1979
+ } & ({
1980
+ /**
1981
+ * AWS 6-field cron expression: minutes hours day-of-month month
1982
+ * day-of-week year (e.g. "0 9 * * ? *" — daily at 9:00).
1983
+ */
1984
+ cron: string;
1985
+ /** IANA timezone the cron expression is evaluated in. Defaults to UTC. */
1986
+ timezone?: string;
1987
+ rate?: never;
1988
+ } | {
1989
+ /** Fixed interval, e.g. { value: 10, unit: "minutes" }. */
1990
+ rate: IScheduleRate;
1991
+ cron?: never;
1992
+ timezone?: never;
1993
+ } | {
1994
+ cron?: never;
1995
+ rate?: never;
1996
+ timezone?: never;
1997
+ });
1949
1998
  export type IFlowTriggerDefinition = {
1950
1999
  variant: TriggerVariantEnum.TABLE_DATA_CHANGE;
1951
2000
  tableId: string;
@@ -1953,6 +2002,11 @@ export type IFlowTriggerDefinition = {
1953
2002
  condition?: string;
1954
2003
  } | {
1955
2004
  variant: TriggerVariantEnum.SCHEDULE;
2005
+ cron?: string;
2006
+ rate?: IScheduleRate;
2007
+ timezone?: string;
2008
+ startDate?: string;
2009
+ endDate?: string;
1956
2010
  condition?: string;
1957
2011
  } | {
1958
2012
  variant: TriggerVariantEnum.MANUAL;
@@ -1960,7 +2014,7 @@ export type IFlowTriggerDefinition = {
1960
2014
  };
1961
2015
  declare const trigger: {
1962
2016
  tableDataChange(opts: ITableDataChangeTriggerOptions): IFlowTriggerDefinition;
1963
- schedule(opts?: ISharedTriggerOptions): IFlowTriggerDefinition;
2017
+ schedule(opts?: IScheduleTriggerOptions): IFlowTriggerDefinition;
1964
2018
  manual(opts?: ISharedTriggerOptions): IFlowTriggerDefinition;
1965
2019
  };
1966
2020
  export type DeepParamObject<P> = P extends object ? {
@@ -2089,7 +2143,7 @@ export interface IValidateFlowsOptions {
2089
2143
  export declare function validateFlows(flows: IValidatableFlow[], opts?: IValidateFlowsOptions): IFlowValidationResult;
2090
2144
 
2091
2145
  declare namespace flowBuilder {
2092
- export { IFlowOptions, IFlowOutput, IFlowStepDefinition, IFlowStepOptions, IFlowTriggerDefinition, ISharedTriggerOptions, IStepParamsInput, ITableDataChangeTriggerOptions, TABLE_ID_PARAM_NAMES, buildFlow, js, secret, step, trigger };
2146
+ export { IFlowOptions, IFlowOutput, IFlowStepDefinition, IFlowStepOptions, IFlowTriggerDefinition, IScheduleTriggerOptions, ISharedTriggerOptions, IStepParamsInput, ITableDataChangeTriggerOptions, TABLE_ID_PARAM_NAMES, buildFlow, js, secret, step, trigger };
2093
2147
  }
2094
2148
  declare namespace dataBuilder {
2095
2149
  export { TableDef, TableOpts, TableSearchConfig, build, enumType, fields, table };
package/dist/src/dsl.js CHANGED
@@ -16641,6 +16641,112 @@ var schemas = {
16641
16641
  genericAI: genericAIStepSchema
16642
16642
  };
16643
16643
 
16644
+ // ../declarations/src/flows/schedule.ts
16645
+ var SCHEDULE_RATE_UNITS = [
16646
+ "minutes",
16647
+ "hours",
16648
+ "days"
16649
+ ];
16650
+ var CRON_MINUTES_PATTERN = /^[\d,\-*/]+$/;
16651
+ var CRON_HOURS_PATTERN = /^[\d,\-*/]+$/;
16652
+ var CRON_DAY_OF_MONTH_PATTERN = /^[\d,\-*/?LW]+$/i;
16653
+ var CRON_MONTH_PATTERN = /^(?:[\d,\-*/]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)+$/i;
16654
+ var CRON_DAY_OF_WEEK_PATTERN = /^(?:[\d,\-*/?L#]|SUN|MON|TUE|WED|THU|FRI|SAT)+$/i;
16655
+ var CRON_YEAR_PATTERN = /^[\d,\-*/]+$/;
16656
+ var CRON_FIELDS = [
16657
+ { label: "minutes", pattern: CRON_MINUTES_PATTERN },
16658
+ { label: "hours", pattern: CRON_HOURS_PATTERN },
16659
+ { label: "day-of-month", pattern: CRON_DAY_OF_MONTH_PATTERN },
16660
+ { label: "month", pattern: CRON_MONTH_PATTERN },
16661
+ { label: "day-of-week", pattern: CRON_DAY_OF_WEEK_PATTERN },
16662
+ { label: "year", pattern: CRON_YEAR_PATTERN }
16663
+ ];
16664
+ function validateCronExpression(cron) {
16665
+ const fields2 = cron.trim().split(/\s+/);
16666
+ if (fields2.length !== 6) {
16667
+ return [
16668
+ `Cron expression "${cron}" must have 6 fields (minutes hours day-of-month month day-of-week year), got ${fields2.length}`
16669
+ ];
16670
+ }
16671
+ const errors = [];
16672
+ fields2.forEach((field, index) => {
16673
+ if (!CRON_FIELDS[index].pattern.test(field)) {
16674
+ errors.push(
16675
+ `Cron expression "${cron}": invalid ${CRON_FIELDS[index].label} field "${field}"`
16676
+ );
16677
+ }
16678
+ });
16679
+ const dayOfMonth = fields2[2];
16680
+ const dayOfWeek = fields2[4];
16681
+ if (dayOfMonth !== "?" && dayOfWeek !== "?") {
16682
+ errors.push(
16683
+ `Cron expression "${cron}": one of day-of-month and day-of-week must be "?"`
16684
+ );
16685
+ }
16686
+ return errors;
16687
+ }
16688
+ function isValidScheduleDate(date5) {
16689
+ return !Number.isNaN(Date.parse(date5));
16690
+ }
16691
+ function isValidTimezone(timezone) {
16692
+ try {
16693
+ new Intl.DateTimeFormat("en-US", { timeZone: timezone });
16694
+ return true;
16695
+ } catch {
16696
+ return false;
16697
+ }
16698
+ }
16699
+ function validateRate(rate) {
16700
+ const errors = [];
16701
+ if (!Number.isInteger(rate.value) || rate.value < 1) {
16702
+ errors.push(
16703
+ `Schedule rate value must be a positive integer, got ${rate.value}`
16704
+ );
16705
+ }
16706
+ if (!SCHEDULE_RATE_UNITS.includes(rate.unit)) {
16707
+ errors.push(
16708
+ `Schedule rate unit must be one of ${SCHEDULE_RATE_UNITS.join(", ")}, got "${rate.unit}"`
16709
+ );
16710
+ }
16711
+ return errors;
16712
+ }
16713
+ function validateScheduleConfig(config2) {
16714
+ if (config2.cron !== void 0 && config2.rate !== void 0) {
16715
+ return ['Schedule triggers must set either "cron" or "rate", not both'];
16716
+ }
16717
+ const errors = [];
16718
+ if (config2.cron !== void 0) {
16719
+ errors.push(...validateCronExpression(config2.cron));
16720
+ }
16721
+ if (config2.rate !== void 0) {
16722
+ errors.push(...validateRate(config2.rate));
16723
+ }
16724
+ if (config2.timezone !== void 0) {
16725
+ if (config2.cron === void 0) {
16726
+ errors.push('Schedule "timezone" is only supported with "cron"');
16727
+ } else if (!isValidTimezone(config2.timezone)) {
16728
+ errors.push(`Unknown timezone "${config2.timezone}"`);
16729
+ }
16730
+ }
16731
+ if (config2.startDate !== void 0 && !isValidScheduleDate(config2.startDate)) {
16732
+ errors.push(
16733
+ `Schedule "startDate" must be an ISO 8601 date, got "${config2.startDate}"`
16734
+ );
16735
+ }
16736
+ if (config2.endDate !== void 0 && !isValidScheduleDate(config2.endDate)) {
16737
+ errors.push(
16738
+ `Schedule "endDate" must be an ISO 8601 date, got "${config2.endDate}"`
16739
+ );
16740
+ }
16741
+ if (config2.startDate !== void 0 && config2.endDate !== void 0 && isValidScheduleDate(config2.startDate) && isValidScheduleDate(config2.endDate) && Date.parse(config2.endDate) <= Date.parse(config2.startDate)) {
16742
+ errors.push('Schedule "endDate" must be after "startDate"');
16743
+ }
16744
+ return errors;
16745
+ }
16746
+ function hasScheduleExpression(config2) {
16747
+ return config2.cron !== void 0 || config2.rate !== void 0;
16748
+ }
16749
+
16644
16750
  // ../dsl-builders/src/apps/app-builder.ts
16645
16751
  var app_builder_exports = {};
16646
16752
  __export(app_builder_exports, {
@@ -22963,7 +23069,11 @@ function collectWriteSteps(declaration) {
22963
23069
  const params = step2.params;
22964
23070
  const ofTypeConfig = step2.paramsConfig?.ofType;
22965
23071
  if (isStaticParamConfig(ofTypeConfig) && typeof params.ofType === "string") {
22966
- staticWrites.push({ stepName: step2.name, ofType: params.ofType, operation });
23072
+ staticWrites.push({
23073
+ stepName: step2.name,
23074
+ ofType: params.ofType,
23075
+ operation
23076
+ });
22967
23077
  } else {
22968
23078
  dynamicWrites.push({
22969
23079
  stepName: step2.name,
@@ -23163,6 +23273,28 @@ function validateFlow(declaration, ctx) {
23163
23273
  for (const step2 of Object.values(steps)) {
23164
23274
  validateStepParams(step2, issue2, errors, warnings);
23165
23275
  }
23276
+ for (const [triggerName, trigger2] of Object.entries(
23277
+ declaration.triggers ?? {}
23278
+ )) {
23279
+ if (trigger2.variant !== "SCHEDULE" /* SCHEDULE */) continue;
23280
+ const scheduleErrors = validateScheduleConfig(trigger2);
23281
+ for (const message of scheduleErrors) {
23282
+ errors.push(
23283
+ issue2(
23284
+ `triggers.${triggerName}`,
23285
+ `Trigger "${triggerName}": ${message}`
23286
+ )
23287
+ );
23288
+ }
23289
+ if (scheduleErrors.length === 0 && !hasScheduleExpression(trigger2)) {
23290
+ warnings.push(
23291
+ issue2(
23292
+ `triggers.${triggerName}`,
23293
+ `Trigger "${triggerName}": schedule trigger has neither "cron" nor "rate" and will never fire`
23294
+ )
23295
+ );
23296
+ }
23297
+ }
23166
23298
  const { staticWrites, dynamicWrites } = collectWriteSteps(declaration);
23167
23299
  const tableTriggers = collectTableDataChangeTriggers(declaration);
23168
23300
  for (const write of staticWrites) {
@@ -23313,9 +23445,19 @@ var trigger = {
23313
23445
  ...opts.condition !== void 0 ? { condition: opts.condition } : {}
23314
23446
  };
23315
23447
  },
23448
+ // opts stays optional for round-trip fidelity: legacy declarations may
23449
+ // hold a schedule trigger without an expression (it never fires and is
23450
+ // reported as a validation warning).
23316
23451
  schedule(opts) {
23317
23452
  return {
23318
23453
  variant: "SCHEDULE" /* SCHEDULE */,
23454
+ ...opts && "cron" in opts ? {
23455
+ cron: opts.cron,
23456
+ ...opts.timezone !== void 0 ? { timezone: opts.timezone } : {}
23457
+ } : {},
23458
+ ...opts && "rate" in opts ? { rate: opts.rate } : {},
23459
+ ...opts?.startDate !== void 0 ? { startDate: opts.startDate } : {},
23460
+ ...opts?.endDate !== void 0 ? { endDate: opts.endDate } : {},
23319
23461
  ...opts?.condition !== void 0 ? { condition: opts.condition } : {}
23320
23462
  };
23321
23463
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turbofy-ai/app-runtime",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -30,6 +30,7 @@
30
30
  ],
31
31
  "scripts": {
32
32
  "build": "npm run generate && tsc && tsx scripts/bundle-dsl.ts",
33
+ "prepublishOnly": "npm run build",
33
34
  "generate": "tsx scripts/write-ui-reexports.ts",
34
35
  "pretypecheck": "npm run generate",
35
36
  "typecheck": "tsc --noEmit"