• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

teableio / teable / 8421654220

25 Mar 2024 02:22PM CUT coverage: 79.934% (+53.8%) from 26.087%
8421654220

Pull #495

github

web-flow
Merge 4faeebea5 into 1869c986d
Pull Request #495: chore: add licenses for non-NPM packages

3256 of 3853 branches covered (84.51%)

25152 of 31466 relevant lines covered (79.93%)

1188.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.99
/apps/nestjs-backend/src/features/automation/actions/action-core.ts
1
import type {
2✔
2
  Event,
2✔
3
  Almanac,
2✔
4
  RuleResult,
2✔
5
  TopLevelCondition,
2✔
6
  RuleProperties,
2✔
7
} from 'json-rules-engine';
2✔
8
import { startsWith } from 'lodash';
2✔
9
import { JsonSchemaParser } from '../engine/json-schema/parser';
2✔
10
import type { ActionTypeEnums } from '../enums/action-type.enum';
2✔
11
import type { IMailSenderSchema } from './mail-sender';
2✔
12
import type { ICreateRecordSchema, IUpdateRecordSchema } from './records';
2✔
13
import type { IWebhookSchema } from './webhook';
2✔
14

2✔
15
export type IActionType = Exclude<ActionTypeEnums, ActionTypeEnums.Decision>;
2✔
16

2✔
17
export enum ActionResponseStatus {
2✔
18
  OK = 200,
2✔
19
  BadRequest = 400,
2✔
20
  Unauthorized = 401,
2✔
21
  TooManyRequests = 429,
2✔
22

2✔
23
  InternalServerError = 500,
2✔
24
  ServiceUnavailable = 503,
2✔
25
  GatewayTimeout = 504,
2✔
26
}
2✔
27

2✔
28
export type IActionResponse<T> = {
2✔
29
  error?: string;
2✔
30
  data: T;
2✔
31
  status: ActionResponseStatus;
2✔
32
};
2✔
33

2✔
34
export type IActionInputSchema =
2✔
35
  | IWebhookSchema
2✔
36
  | IMailSenderSchema
2✔
37
  | ICreateRecordSchema
2✔
38
  | IUpdateRecordSchema;
2✔
39

2✔
40
export type INullSchema = { type: string };
2✔
41
export type IConstSchema = { type: string; value: number | string | boolean };
2✔
42

2✔
43
export type IObjectPathValueSchema = {
2✔
44
  type: string;
2✔
45
  object: { nodeId: string; nodeType: string };
2✔
46
  path: { type: string; elements: IConstSchema[] };
2✔
47
};
2✔
48

2✔
49
export type ITemplateSchema = {
2✔
50
  type: string;
2✔
51
  elements: (IConstSchema | IObjectPathValueSchema)[];
2✔
52
};
2✔
53

2✔
54
export type IObjectSchema = {
2✔
55
  type: string;
2✔
56
  properties: {
2✔
57
    key: IConstSchema;
2✔
58
    value:
2✔
59
      | INullSchema
2✔
60
      | IConstSchema
2✔
61
      | IObjectPathValueSchema
2✔
62
      | ITemplateSchema
2✔
63
      | IObjectSchema
2✔
64
      | IObjectArraySchema;
2✔
65
  }[];
2✔
66
};
2✔
67

2✔
68
export type IObjectArraySchema = {
2✔
69
  type: string;
2✔
70
  elements: (IConstSchema | IObjectPathValueSchema | ITemplateSchema | IObjectSchema)[];
2✔
71
};
2✔
72

2✔
73
export const actionConst = {
2✔
74
  OutPutFlag: 'action.',
2✔
75
};
2✔
76

2✔
77
export abstract class ActionCore implements RuleProperties {
2✔
78
  name?: string;
×
79
  conditions!: TopLevelCondition;
×
80
  event!: Event;
×
81
  priority?: number;
×
82

×
83
  protected constructor() {
×
84
    this.setConditions({
×
85
      any: [
×
86
        {
×
87
          fact: '__fact_always__',
×
88
          operator: 'always',
×
89
          value: undefined,
×
90
        },
×
91
      ],
×
92
    });
×
93

×
94
    this.setEvent({ type: '__unknown__' });
×
95
  }
×
96

×
97
  abstract bindParams(id: string, inputSchema: IActionInputSchema, priority?: number): this;
×
98

×
99
  protected async parseInputSchema<TResult>(
×
100
    schema: IActionInputSchema,
×
101
    almanac: Almanac
×
102
  ): Promise<TResult> {
×
103
    const jsonSchemaParser = new JsonSchemaParser<IActionInputSchema, TResult>(schema, {
×
104
      pathResolver: async (value, path) => {
×
105
        const [id, p] = path;
×
106
        const omitPath = `${startsWith(id, actionConst.OutPutFlag) ? 'data.' : ''}${p}`;
×
107
        return await almanac.factValue(id, undefined, omitPath);
×
108
      },
×
109
    });
×
110

×
111
    return await jsonSchemaParser.parse();
×
112
  }
×
113

×
114
  protected setName(name: string): this {
×
115
    if (!name) {
×
116
      throw new Error('Rule "name" must be defined');
×
117
    }
×
118
    this.name = name;
×
119
    return this;
×
120
  }
×
121

×
122
  protected setEvent(event: Event): this {
×
123
    if (!event) throw new Error('Rule: setEvent() requires event object');
×
124
    if (!Object.prototype.hasOwnProperty.call(event, 'type'))
×
125
      throw new Error('Rule: setEvent() requires event object with "type" property');
×
126
    this.event = event;
×
127
    return this;
×
128
  }
×
129

×
130
  protected setPriority(priority?: number): this {
×
131
    priority = priority ?? 1;
×
132
    if (priority <= 0) throw new Error('Priority must be greater than zero');
×
133
    this.priority = priority;
×
134
    return this;
×
135
  }
×
136

×
137
  setConditions(conditions: TopLevelCondition): this {
×
138
    if (
×
139
      !Object.prototype.hasOwnProperty.call(conditions, 'all') &&
×
140
      !Object.prototype.hasOwnProperty.call(conditions, 'any')
×
141
    ) {
×
142
      throw new Error('"conditions" root must contain a single instance of "all" or "any"');
×
143
    }
×
144
    this.conditions = conditions;
×
145
    return this;
×
146
  }
×
147

×
148
  onSuccess = (_event: Event, _almanac: Almanac, _ruleResult: RuleResult): void => {
×
149
    // Needs to be implemented by the successor itself
×
150
  };
×
151
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc