@squidcloud/backend 1.0.2 → 1.0.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.
@@ -1,13 +1,13 @@
1
- import { ActionMethodDecorator, ActionType, ApiEndpointId, CollectionName, CronExpression, ExecutableAction, IntegrationId, QueryName, SchedulerAction, SchedulerId, SecureApiAction, SecureDatabaseAction, SecureExecutableAction, SecureGraphQLAction, SecureNamedQueryAction, TransformDatabaseAction, TriggerAction, TriggerId, WebhookAction, WebhookId } from '@squidcloud/common';
1
+ import { ActionMethodDecorator, ActionType, ApiEndpointId, CollectionName, CronExpression, CronExpressionString, ExecutableAction, IntegrationId, QueryName, SchedulerAction, SchedulerId, SecureApiAction, SecureDatabaseAction, SecureExecutableAction, SecureGraphQLAction, SecureNamedQueryAction, TransformDatabaseAction, TriggerAction, TriggerId, WebhookAction, WebhookId } from '@squidcloud/common';
2
2
  export declare function secureDatabase<T extends ActionType>(type: T, integrationId?: IntegrationId): ActionMethodDecorator<SecureDatabaseAction<T>>;
3
3
  export declare function secureCollection<T extends ActionType>(collectionName: CollectionName, type: T, integrationId?: IntegrationId): ActionMethodDecorator<SecureDatabaseAction<T>>;
4
4
  export declare function secureExecutable(executable: string): ActionMethodDecorator<SecureExecutableAction>;
5
- export declare function secureApi<T extends SecureApiAction>(endpointId: ApiEndpointId, integrationId: IntegrationId): ActionMethodDecorator<SecureApiAction>;
5
+ export declare function secureApi<T extends SecureApiAction>(integrationId: IntegrationId, endpointId?: ApiEndpointId): ActionMethodDecorator<SecureApiAction>;
6
6
  export declare function secureGraphQL<T extends SecureGraphQLAction>(integrationId: IntegrationId): ActionMethodDecorator<SecureGraphQLAction>;
7
7
  export declare function transformCollection<T extends ActionType>(collectionName: CollectionName, type: T, integrationId?: IntegrationId): ActionMethodDecorator<TransformDatabaseAction<T>>;
8
8
  export declare function executable(): ActionMethodDecorator<ExecutableAction>;
9
9
  export declare function trigger(id: TriggerId, collectionName: CollectionName, integrationId?: IntegrationId): ActionMethodDecorator<TriggerAction>;
10
- export declare function scheduler(id: SchedulerId, cronExpression: CronExpression): ActionMethodDecorator<SchedulerAction>;
10
+ export declare function scheduler(id: SchedulerId, cronExpression: CronExpression | CronExpressionString): ActionMethodDecorator<SchedulerAction>;
11
11
  export declare function webhook(id: WebhookId): ActionMethodDecorator<WebhookAction>;
12
12
  export declare function namedQuery(integrationId: string, name: string): any;
13
13
  export declare function secureNamedQuery<T extends SecureNamedQueryAction>(integrationId: IntegrationId, queryName: QueryName): ActionMethodDecorator<SecureNamedQueryAction>;
@@ -1,4 +1,4 @@
1
- import { ActionType, ApiEndpointId, ApplicationBundleData, CollectionName, CronExpression, FunctionName, IntegrationId, QueryName, SchedulerId, ServiceFunctionName, TriggerId, WebhookId } from '@squidcloud/common';
1
+ import { ActionType, ApiEndpointId, ApplicationBundleData, CollectionName, FunctionName, IntegrationId, QueryName, SchedulerId, ServiceFunctionName, TriggerId, WebhookId } from '@squidcloud/common';
2
2
  declare class Meta {
3
3
  data: ApplicationBundleData;
4
4
  /**
@@ -55,7 +55,7 @@ declare class Meta {
55
55
  */
56
56
  secureExecutable(executable: FunctionName, serviceFunction: ServiceFunctionName): void;
57
57
  /**
58
- * @secureApi("myEndpoint", "ExampleIntegration")
58
+ * @secureApi("ExampleIntegration", "myEndpoint")
59
59
  *
60
60
  * Applying the decorator above to the myMethod method on the MyService
61
61
  * class will generate the following metadata:
@@ -70,7 +70,7 @@ declare class Meta {
70
70
  * }
71
71
  * }
72
72
  */
73
- secureApi(endpointId: ApiEndpointId, integrationId: IntegrationId, serviceFunction: ServiceFunctionName): void;
73
+ secureApi(integrationId: IntegrationId, endpointId: ApiEndpointId | undefined, serviceFunction: ServiceFunctionName): void;
74
74
  /**
75
75
  * @secureGraphQL("ExampleIntegration")
76
76
  *
@@ -177,7 +177,7 @@ declare class Meta {
177
177
  * }
178
178
  * }
179
179
  */
180
- scheduler(id: SchedulerId, cronExpression: CronExpression, serviceFunction: ServiceFunctionName): void;
180
+ scheduler(id: SchedulerId, cronExpression: string, serviceFunction: ServiceFunctionName): void;
181
181
  /**
182
182
  * @webhook("my-webhook")
183
183
  *
@@ -1,5 +1,5 @@
1
1
  import { Squid } from '@squidcloud/client';
2
- import { AuthWithApiKey, AuthWithBearer, Logger, RunContext, SecretKey, SecretValue, ServiceConfig, SquidRegion } from '@squidcloud/common';
2
+ import { AuthWithApiKey, AuthWithBearer, Logger, RunContext, SecretKey, SecretValue, ServiceConfig, SquidRegion, WebhookResponse } from '@squidcloud/common';
3
3
  export declare class SquidService {
4
4
  readonly secrets: Record<SecretKey, SecretValue>;
5
5
  readonly logger: Logger;
@@ -14,4 +14,5 @@ export declare class SquidService {
14
14
  getUserAuth(): AuthWithBearer | undefined;
15
15
  getApiKeyAuth(): AuthWithApiKey | undefined;
16
16
  isAuthenticated(): boolean;
17
+ createWebhookResponse(body?: any, statusCode?: number, headers?: Record<string, any>): WebhookResponse;
17
18
  }
@@ -6,7 +6,92 @@ export type WebhookId = string;
6
6
  export type QueryName = string;
7
7
  export type TriggerId = string;
8
8
  export type SchedulerId = string;
9
- export type CronExpression = string;
9
+ export type CronExpressionString = `${string} ${string} ${string} ${string} ${string}` | `${string} ${string} ${string} ${string}`;
10
+ export declare enum CronExpression {
11
+ EVERY_SECOND = "* * * * * *",
12
+ EVERY_5_SECONDS = "*/5 * * * * *",
13
+ EVERY_10_SECONDS = "*/10 * * * * *",
14
+ EVERY_30_SECONDS = "*/30 * * * * *",
15
+ EVERY_MINUTE = "*/1 * * * *",
16
+ EVERY_5_MINUTES = "0 */5 * * * *",
17
+ EVERY_10_MINUTES = "0 */10 * * * *",
18
+ EVERY_30_MINUTES = "0 */30 * * * *",
19
+ EVERY_HOUR = "0 0-23/1 * * *",
20
+ EVERY_2_HOURS = "0 0-23/2 * * *",
21
+ EVERY_3_HOURS = "0 0-23/3 * * *",
22
+ EVERY_4_HOURS = "0 0-23/4 * * *",
23
+ EVERY_5_HOURS = "0 0-23/5 * * *",
24
+ EVERY_6_HOURS = "0 0-23/6 * * *",
25
+ EVERY_7_HOURS = "0 0-23/7 * * *",
26
+ EVERY_8_HOURS = "0 0-23/8 * * *",
27
+ EVERY_9_HOURS = "0 0-23/9 * * *",
28
+ EVERY_10_HOURS = "0 0-23/10 * * *",
29
+ EVERY_11_HOURS = "0 0-23/11 * * *",
30
+ EVERY_12_HOURS = "0 0-23/12 * * *",
31
+ EVERY_DAY_AT_1AM = "0 01 * * *",
32
+ EVERY_DAY_AT_2AM = "0 02 * * *",
33
+ EVERY_DAY_AT_3AM = "0 03 * * *",
34
+ EVERY_DAY_AT_4AM = "0 04 * * *",
35
+ EVERY_DAY_AT_5AM = "0 05 * * *",
36
+ EVERY_DAY_AT_6AM = "0 06 * * *",
37
+ EVERY_DAY_AT_7AM = "0 07 * * *",
38
+ EVERY_DAY_AT_8AM = "0 08 * * *",
39
+ EVERY_DAY_AT_9AM = "0 09 * * *",
40
+ EVERY_DAY_AT_10AM = "0 10 * * *",
41
+ EVERY_DAY_AT_11AM = "0 11 * * *",
42
+ EVERY_DAY_AT_NOON = "0 12 * * *",
43
+ EVERY_DAY_AT_1PM = "0 13 * * *",
44
+ EVERY_DAY_AT_2PM = "0 14 * * *",
45
+ EVERY_DAY_AT_3PM = "0 15 * * *",
46
+ EVERY_DAY_AT_4PM = "0 16 * * *",
47
+ EVERY_DAY_AT_5PM = "0 17 * * *",
48
+ EVERY_DAY_AT_6PM = "0 18 * * *",
49
+ EVERY_DAY_AT_7PM = "0 19 * * *",
50
+ EVERY_DAY_AT_8PM = "0 20 * * *",
51
+ EVERY_DAY_AT_9PM = "0 21 * * *",
52
+ EVERY_DAY_AT_10PM = "0 22 * * *",
53
+ EVERY_DAY_AT_11PM = "0 23 * * *",
54
+ EVERY_DAY_AT_MIDNIGHT = "0 0 * * *",
55
+ EVERY_WEEK = "0 0 * * 0",
56
+ EVERY_WEEKDAY = "0 0 * * 1-5",
57
+ EVERY_WEEKEND = "0 0 * * 6,0",
58
+ EVERY_1ST_DAY_OF_MONTH_AT_MIDNIGHT = "0 0 1 * *",
59
+ EVERY_1ST_DAY_OF_MONTH_AT_NOON = "0 12 1 * *",
60
+ EVERY_2ND_HOUR = "0 */2 * * *",
61
+ EVERY_2ND_HOUR_FROM_1AM_THROUGH_11PM = "0 1-23/2 * * *",
62
+ EVERY_2ND_MONTH = "0 0 1 */2 *",
63
+ EVERY_QUARTER = "0 0 1 */3 *",
64
+ EVERY_6_MONTHS = "0 0 1 */6 *",
65
+ EVERY_YEAR = "0 0 1 0 *",
66
+ EVERY_30_MINUTES_BETWEEN_9AM_AND_5PM = "0 */30 9-17 * * *",
67
+ EVERY_30_MINUTES_BETWEEN_9AM_AND_6PM = "0 */30 9-18 * * *",
68
+ EVERY_30_MINUTES_BETWEEN_10AM_AND_7PM = "0 */30 10-19 * * *",
69
+ MONDAY_TO_FRIDAY_AT_1AM = "0 0 01 * * 1-5",
70
+ MONDAY_TO_FRIDAY_AT_2AM = "0 0 02 * * 1-5",
71
+ MONDAY_TO_FRIDAY_AT_3AM = "0 0 03 * * 1-5",
72
+ MONDAY_TO_FRIDAY_AT_4AM = "0 0 04 * * 1-5",
73
+ MONDAY_TO_FRIDAY_AT_5AM = "0 0 05 * * 1-5",
74
+ MONDAY_TO_FRIDAY_AT_6AM = "0 0 06 * * 1-5",
75
+ MONDAY_TO_FRIDAY_AT_7AM = "0 0 07 * * 1-5",
76
+ MONDAY_TO_FRIDAY_AT_8AM = "0 0 08 * * 1-5",
77
+ MONDAY_TO_FRIDAY_AT_9AM = "0 0 09 * * 1-5",
78
+ MONDAY_TO_FRIDAY_AT_09_30AM = "0 30 09 * * 1-5",
79
+ MONDAY_TO_FRIDAY_AT_10AM = "0 0 10 * * 1-5",
80
+ MONDAY_TO_FRIDAY_AT_11AM = "0 0 11 * * 1-5",
81
+ MONDAY_TO_FRIDAY_AT_11_30AM = "0 30 11 * * 1-5",
82
+ MONDAY_TO_FRIDAY_AT_12PM = "0 0 12 * * 1-5",
83
+ MONDAY_TO_FRIDAY_AT_1PM = "0 0 13 * * 1-5",
84
+ MONDAY_TO_FRIDAY_AT_2PM = "0 0 14 * * 1-5",
85
+ MONDAY_TO_FRIDAY_AT_3PM = "0 0 15 * * 1-5",
86
+ MONDAY_TO_FRIDAY_AT_4PM = "0 0 16 * * 1-5",
87
+ MONDAY_TO_FRIDAY_AT_5PM = "0 0 17 * * 1-5",
88
+ MONDAY_TO_FRIDAY_AT_6PM = "0 0 18 * * 1-5",
89
+ MONDAY_TO_FRIDAY_AT_7PM = "0 0 19 * * 1-5",
90
+ MONDAY_TO_FRIDAY_AT_8PM = "0 0 20 * * 1-5",
91
+ MONDAY_TO_FRIDAY_AT_9PM = "0 0 21 * * 1-5",
92
+ MONDAY_TO_FRIDAY_AT_10PM = "0 0 22 * * 1-5",
93
+ MONDAY_TO_FRIDAY_AT_11PM = "0 0 23 * * 1-5"
94
+ }
10
95
  export type OpenIdProviderType = 'auth0';
11
96
  export type CodeUrl = string;
12
97
  export interface TriggerConfig {
@@ -16,7 +101,7 @@ export interface TriggerConfig {
16
101
  }
17
102
  export interface SchedulerConfig {
18
103
  functionName: ServiceFunctionName;
19
- cronExpression: CronExpression;
104
+ cronExpression: string;
20
105
  }
21
106
  export interface WebhookConfig {
22
107
  functionName: ServiceFunctionName;
@@ -8,7 +8,9 @@ export type FunctionName = string;
8
8
  export type ServiceFunctionName = `${ServiceName}:${FunctionName}`;
9
9
  export interface ApplicationBundleData {
10
10
  databases: Record<IntegrationId, DatabaseMetadata>;
11
- apis: Record<ApiEndpointId, ApiMetadata>;
11
+ apis: Record<IntegrationId, {
12
+ endpoints: Record<ApiEndpointId, ApiMetadata>;
13
+ } & ApiMetadata>;
12
14
  graphql: Record<IntegrationId, GraphQLMetadata>;
13
15
  executables: Record<FunctionName, ExecutableMetadata>;
14
16
  triggers: Record<TriggerId, TriggerConfig>;
@@ -27,3 +27,9 @@ export type DocumentData = Record<FieldName, any | undefined>;
27
27
  export declare function parseSquidDocId(squidDocId: SquidDocId): SquidDocIdObj;
28
28
  export declare function getSquidDocId(squidDocIdObj: SquidDocIdObj): SquidDocId;
29
29
  export declare function getSquidDocId(docId: DocId, collectionName: CollectionName, integrationId: IntegrationId): SquidDocId;
30
+ /**
31
+ * Determines whether a beforeDoc and an afterDoc have the same properties.
32
+ * Our internal properties such as __docId__ and __ts__ are excluded from the
33
+ * comparison, as well as any primary keys changes.
34
+ */
35
+ export declare function hasDocumentDiff(beforeDoc: SquidDocument | undefined, afterDoc: SquidDocument | undefined): boolean;
@@ -1,13 +1,17 @@
1
+ export * from './api-call.context';
1
2
  export * from './api.types';
2
3
  export * from './application.schemas';
3
4
  export * from './application.types';
4
5
  export * from './backend-function.schemas';
5
6
  export * from './backend-function.types';
7
+ export * from './backend-run.types';
6
8
  export * from './bundle-api.types';
7
9
  export * from './bundle-data.types';
8
10
  export * from './communication.types';
9
11
  export * from './context.types';
10
12
  export * from './document.types';
13
+ export * from './executable.context';
14
+ export * from './graphql.context';
11
15
  export * from './graphql.types';
12
16
  export * from './http-status.enum';
13
17
  export * from './integration.types';
@@ -15,12 +19,9 @@ export * from './logger.types';
15
19
  export * from './metrics.schemas';
16
20
  export * from './metrics.types';
17
21
  export * from './mutation.context';
18
- export * from './named-query.context';
19
- export * from './graphql.context';
20
- export * from './executable.context';
21
- export * from './api-call.context';
22
22
  export * from './mutation.schemas';
23
23
  export * from './mutation.types';
24
+ export * from './named-query.context';
24
25
  export * from './named-query.schemas';
25
26
  export * from './named-query.types';
26
27
  export * from './query';
@@ -34,16 +35,16 @@ export * from './socket.schemas';
34
35
  export * from './socket.types';
35
36
  export * from './time-units';
36
37
  export * from './trigger.types';
37
- export * from './backend-run.types';
38
38
  export * from './types';
39
39
  export * from './utils/array';
40
40
  export * from './utils/assert';
41
41
  export * from './utils/error';
42
42
  export * from './utils/id';
43
- export * from './utils/isDefined';
44
43
  export * from './utils/lock.manager';
44
+ export * from './utils/nullish';
45
45
  export * from './utils/object';
46
46
  export * from './utils/serialization';
47
47
  export * from './utils/transforms';
48
48
  export * from './utils/url';
49
49
  export * from './utils/validation';
50
+ export * from './webhook-response';
@@ -10,7 +10,9 @@ export interface ExecuteMutationsResponse {
10
10
  idResolutionMap?: IdResolutionMap;
11
11
  afterDocs: Record<SquidDocId, SquidDocument>;
12
12
  }
13
- export type MutateResponse = Omit<ExecuteMutationsResponse, 'afterDocs'>;
13
+ export interface MutateResponse extends Omit<ExecuteMutationsResponse, 'afterDocs'> {
14
+ refreshList: Array<SquidDocId>;
15
+ }
14
16
  export type IdResolutionMap = Record<SquidDocId, SquidDocId>;
15
17
  export type Mutation<T = any> = UpdateMutation<T> | InsertMutation<T> | DeleteMutation;
16
18
  export type MutationType = 'insert' | 'update' | 'delete';
@@ -1,7 +1,7 @@
1
1
  import { IntegrationId } from '../communication.types';
2
2
  import { CollectionName, FieldName } from '../document.types';
3
3
  import { AllOperators, ContextCondition, ContextConditions, FieldSort, GeneralCondition, GeneralConditions, GenericValue, Query } from '../query.types';
4
- import { Paths } from '../types';
4
+ import { PartialBy, Paths } from '../types';
5
5
  export declare class QueryContext<T = any> {
6
6
  readonly query: Query<T>;
7
7
  private readonly parsedConditions;
@@ -9,8 +9,8 @@ export declare class QueryContext<T = any> {
9
9
  get integrationId(): IntegrationId;
10
10
  get collectionName(): CollectionName;
11
11
  get limit(): number;
12
- includesSorts(sorts: Array<FieldSort<T>>): boolean;
13
- matchesSorts(sorts: Array<FieldSort<T>>): boolean;
12
+ sortedBy(sorts: Array<PartialBy<FieldSort<T>, 'asc'>>): boolean;
13
+ sortedByExact(sorts: Array<PartialBy<FieldSort<T>, 'asc'>>): boolean;
14
14
  includes<F extends FieldName<T>, O extends AllOperators>(fieldName: F, operator: O, value: GenericValue<T, F, O>): boolean;
15
15
  includesCondition(condition: ContextCondition<T>): boolean;
16
16
  includesConditions(conditions: GeneralConditions<T>): boolean;
@@ -7,6 +7,7 @@ export declare const SUPPORTED_FIELD_TYPES_ARRAY: Array<SupportedFieldType>;
7
7
  type ConvertDeep<T extends JSONSchema> = Exclude<T, boolean> & {
8
8
  properties?: Record<string, ConvertDeep<JSONSchema>>;
9
9
  patternProperties?: Record<string, ConvertDeep<JSONSchema>>;
10
+ nullable?: boolean;
10
11
  /**
11
12
  * The default value will be applied (default to 'empty'):
12
13
  * 'always' - no matter what the client sent, both on update and insert. In case of readOnly - applies only on insert.
@@ -5,3 +5,4 @@ export interface Grouped<T> {
5
5
  [key: string]: T[];
6
6
  }
7
7
  export declare function asyncGroupBy<T>(arr: T[], groupNamer: (element: T) => Promise<string>): Promise<Grouped<T>>;
8
+ export declare const arrayMergeCustomizer: (a: any, b: any) => Array<any> | undefined;
@@ -1,8 +1,8 @@
1
1
  import { StatusCode } from './validation';
2
2
  export type AssertErrorProvider = () => Error | string;
3
3
  export declare function assertTruthy(value: unknown, error?: string | Error | AssertErrorProvider): asserts value;
4
- export declare function assertDefined(value: unknown, error?: string | Error | AssertErrorProvider): asserts value;
4
+ export declare function assertNotNullish(value: unknown, error?: string | Error | AssertErrorProvider): asserts value;
5
5
  export declare function assertValidateTruthy(value: unknown, message: string, statusCode?: StatusCode, details?: Record<string, any>): asserts value;
6
6
  export declare function truthy<T>(value: T, error?: string | Error | AssertErrorProvider): NonNullable<T>;
7
- export declare function defined<T>(value: T, error?: string | Error | AssertErrorProvider): NonNullable<T>;
7
+ export declare function notNullish<T>(value: T, error?: string | Error | AssertErrorProvider): NonNullable<T>;
8
8
  export declare function validateTruthy<T>(value: T, message: string, statusCode?: StatusCode, details?: Record<string, any>): NonNullable<T>;
@@ -0,0 +1 @@
1
+ export declare function isNotNullish<T>(t: T | undefined | null): t is T;
@@ -0,0 +1,7 @@
1
+ export interface WebhookResponse {
2
+ headers: Record<string, any>;
3
+ body: any;
4
+ statusCode: number;
5
+ __isWebhookResponse__: true;
6
+ }
7
+ export declare function isWebhookResponse(response: any): response is WebhookResponse;