@squidcloud/backend 1.0.0

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.
Files changed (77) hide show
  1. package/dist/backend/src/actions.d.ts +13 -0
  2. package/dist/backend/src/index.d.ts +3 -0
  3. package/dist/backend/src/metadata.d.ts +234 -0
  4. package/dist/backend/src/project.d.ts +4 -0
  5. package/dist/backend/src/service.d.ts +10 -0
  6. package/dist/common/src/api.types.d.ts +10 -0
  7. package/dist/common/src/application.schemas.d.ts +608 -0
  8. package/dist/common/src/application.types.d.ts +120 -0
  9. package/dist/common/src/backend-function.schemas.d.ts +3 -0
  10. package/dist/common/src/backend-function.types.d.ts +7 -0
  11. package/dist/common/src/bundle-api.types.d.ts +86 -0
  12. package/dist/common/src/bundle-data.types.d.ts +45 -0
  13. package/dist/common/src/communication.types.d.ts +4 -0
  14. package/dist/common/src/context.types.d.ts +22 -0
  15. package/dist/common/src/document.types.d.ts +29 -0
  16. package/dist/common/src/graphql.types.d.ts +8 -0
  17. package/dist/common/src/http-status.enum.d.ts +50 -0
  18. package/dist/common/src/index.d.ts +40 -0
  19. package/dist/common/src/integration.types.d.ts +247 -0
  20. package/dist/common/src/logger.types.d.ts +22 -0
  21. package/dist/common/src/metrics.schemas.d.ts +3 -0
  22. package/dist/common/src/metrics.types.d.ts +52 -0
  23. package/dist/common/src/mutation.context.d.ts +14 -0
  24. package/dist/common/src/mutation.schemas.d.ts +5 -0
  25. package/dist/common/src/mutation.types.d.ts +66 -0
  26. package/dist/common/src/named-query.schemas.d.ts +3 -0
  27. package/dist/common/src/named-query.types.d.ts +9 -0
  28. package/dist/common/src/query/index.d.ts +2 -0
  29. package/dist/common/src/query/query-context.d.ts +41 -0
  30. package/dist/common/src/query/simple-query-builder.d.ts +14 -0
  31. package/dist/common/src/query.schemas.d.ts +5 -0
  32. package/dist/common/src/query.types.d.ts +118 -0
  33. package/dist/common/src/schema/schema.types.d.ts +34 -0
  34. package/dist/common/src/secret.schemas.d.ts +6 -0
  35. package/dist/common/src/secret.types.d.ts +30 -0
  36. package/dist/common/src/socket.schemas.d.ts +3 -0
  37. package/dist/common/src/socket.types.d.ts +68 -0
  38. package/dist/common/src/time-units.d.ts +5 -0
  39. package/dist/common/src/trigger.types.d.ts +17 -0
  40. package/dist/common/src/types.d.ts +15 -0
  41. package/dist/common/src/utils/array.d.ts +7 -0
  42. package/dist/common/src/utils/assert.d.ts +6 -0
  43. package/dist/common/src/utils/error.d.ts +4 -0
  44. package/dist/common/src/utils/lock.manager.d.ts +14 -0
  45. package/dist/common/src/utils/object.d.ts +4 -0
  46. package/dist/common/src/utils/serialization.d.ts +5 -0
  47. package/dist/common/src/utils/url.d.ts +1 -0
  48. package/dist/common/src/utils/validation.d.ts +30 -0
  49. package/dist/index.js +12 -0
  50. package/dist/index.js.LICENSE.txt +38 -0
  51. package/dist/node_modules/json-schema-typed/draft-2020-12.d.ts +1239 -0
  52. package/dist/typescript-client/src/api.manager.d.ts +14 -0
  53. package/dist/typescript-client/src/backend-function.manager.d.ts +13 -0
  54. package/dist/typescript-client/src/collection-reference.d.ts +16 -0
  55. package/dist/typescript-client/src/collection-reference.factory.d.ts +11 -0
  56. package/dist/typescript-client/src/data.manager.d.ts +140 -0
  57. package/dist/typescript-client/src/db.dao.d.ts +20 -0
  58. package/dist/typescript-client/src/destruct.manager.d.ts +7 -0
  59. package/dist/typescript-client/src/document-reference.d.ts +18 -0
  60. package/dist/typescript-client/src/document-reference.factory.d.ts +9 -0
  61. package/dist/typescript-client/src/graphql-client.d.ts +9 -0
  62. package/dist/typescript-client/src/graphql-client.factory.d.ts +9 -0
  63. package/dist/typescript-client/src/index.d.ts +4 -0
  64. package/dist/typescript-client/src/mutation/mutation-sender.d.ts +11 -0
  65. package/dist/typescript-client/src/named-query.manager.d.ts +13 -0
  66. package/dist/typescript-client/src/query/query-builder.factory.d.ts +41 -0
  67. package/dist/typescript-client/src/query/query-subscription.manager.d.ts +55 -0
  68. package/dist/typescript-client/src/query/query.types.d.ts +7 -0
  69. package/dist/typescript-client/src/rpc.manager.d.ts +23 -0
  70. package/dist/typescript-client/src/socket.manager.d.ts +27 -0
  71. package/dist/typescript-client/src/squid.d.ts +48 -0
  72. package/dist/typescript-client/src/state/action.applier.d.ts +7 -0
  73. package/dist/typescript-client/src/state/actions.d.ts +29 -0
  74. package/dist/typescript-client/src/state/path_trie.d.ts +27 -0
  75. package/dist/typescript-client/src/state/state.service.d.ts +22 -0
  76. package/dist/typescript-client/src/types.d.ts +2 -0
  77. package/package.json +26 -0
@@ -0,0 +1,22 @@
1
+ export type LoggerContext = Record<string, any>;
2
+ export interface Logger {
3
+ trace(message: string, context?: LoggerContext): void;
4
+ debug(message: string, context?: LoggerContext): void;
5
+ info(message: string, context?: LoggerContext): void;
6
+ warn(message: string, context?: LoggerContext): void;
7
+ error(message: string, context?: LoggerContext): void;
8
+ child(context: LoggerContext): Logger;
9
+ log(record: LogRecord): void;
10
+ }
11
+ export declare enum LogLevel {
12
+ TRACE = "trace",
13
+ DEBUG = "debug",
14
+ INFO = "info",
15
+ WARN = "warn",
16
+ ERROR = "error"
17
+ }
18
+ export interface LogRecord {
19
+ level?: LogLevel;
20
+ message?: string;
21
+ [key: string]: any;
22
+ }
@@ -0,0 +1,3 @@
1
+ import { JSONSchemaType } from 'ajv';
2
+ import { GetMetricDataRequest } from './metrics.types';
3
+ export declare const GetMetricDataRequestSchema: JSONSchemaType<GetMetricDataRequest>;
@@ -0,0 +1,52 @@
1
+ export type MetricRate = '1m' | '5m' | '1h' | '3h' | '1d';
2
+ export type MetricStep = string | number;
3
+ export type MetricTimeWindow = {
4
+ startTime?: number;
5
+ endTime?: number;
6
+ };
7
+ export type MetricName = 'backendBootstrapLatencySum' | 'backendFailureCount' | 'backendFailureFunctionCallCount' | 'backendSuccessFunctionCallCount' | 'backendFunctionCallCount' | 'backendFunctionCallLatencySum';
8
+ export type MetricAggregationFunction = 'sum' | 'avg';
9
+ export type MetricAggregation = 'none' | {
10
+ groupByFields: string[];
11
+ functionName: MetricAggregationFunction;
12
+ };
13
+ /**
14
+ * By default, metrics are aggregated by `avg` function so if the `aggregation`
15
+ * is set as `null`, the `avg` aggregation function will be applied. In the case
16
+ * _no_ aggregation is to be applied then `aggregation` must be set to `"none"`.
17
+ */
18
+ export interface GetMetricDataRequest {
19
+ metricNames: MetricName[];
20
+ rate?: MetricRate;
21
+ step?: MetricStep;
22
+ timeWindow?: MetricTimeWindow;
23
+ aggregation?: MetricAggregation;
24
+ }
25
+ export type MetricQueryResultStatus = 'success' | 'error';
26
+ export type MetricQueryResultType = 'matrix';
27
+ export type MetricQueryDate = Date | number | string;
28
+ export interface MetricQueryResultDataEntry<V> {
29
+ metric: {
30
+ __name__: string | undefined;
31
+ [key: string]: string | undefined;
32
+ };
33
+ values: V;
34
+ }
35
+ export interface MetricQueryResultData<T extends MetricQueryResultType, V> {
36
+ resultType: T;
37
+ result: MetricQueryResultDataEntry<V>[];
38
+ }
39
+ export interface MetricQueryResult<T extends MetricQueryResultType, V> {
40
+ status: MetricQueryResultStatus;
41
+ data: MetricQueryResultData<T, V>;
42
+ errorType?: string;
43
+ error?: string;
44
+ warnings?: string;
45
+ }
46
+ export type MetricMatrixResult = MetricQueryResult<'matrix', [number, string]>;
47
+ export type GetMetricDataResponse<T extends MetricQueryResult<any, any>> = {
48
+ results: Array<{
49
+ metricName: MetricName;
50
+ result: T;
51
+ }>;
52
+ };
@@ -0,0 +1,14 @@
1
+ import { Mutation, MutationType } from './mutation.types';
2
+ import { BeforeAndAfterDocs } from './document.types';
3
+ import { Paths } from './types';
4
+ import { Auth, AuthWithBearer } from './context.types';
5
+ export declare class MutationContext<T = any> {
6
+ readonly mutation: Mutation<T>;
7
+ readonly beforeAndAfterDocs: BeforeAndAfterDocs<T>;
8
+ readonly serverTimeStamp: Date;
9
+ private readonly auth;
10
+ constructor(mutation: Mutation<T>, beforeAndAfterDocs: BeforeAndAfterDocs<T>, serverTimeStamp: Date, auth: Auth | undefined);
11
+ getUserAuth(): AuthWithBearer | undefined;
12
+ getMutationType(): MutationType;
13
+ affectsPath(path: Paths<T>): boolean;
14
+ }
@@ -0,0 +1,5 @@
1
+ import { JSONSchemaType } from 'ajv';
2
+ import { MutateRequest } from './mutation.types';
3
+ type DocumentBase = Record<string, any>;
4
+ export declare const MutationRequestSchema: JSONSchemaType<MutateRequest<DocumentBase>>;
5
+ export {};
@@ -0,0 +1,66 @@
1
+ import { ClientId, IntegrationId } from './communication.types';
2
+ import { DocTimestamp, DocType, FieldName, FullDocId } from './document.types';
3
+ export interface MutateRequest<T = any> {
4
+ clientId: ClientId;
5
+ integrationId: IntegrationId;
6
+ mutations: Array<Mutation<T>>;
7
+ }
8
+ export interface MutateResponse {
9
+ timestamp: DocTimestamp;
10
+ }
11
+ export type Mutation<T = any> = UpdateMutation<T> | InsertMutation<T> | DeleteMutation;
12
+ export type MutationType = 'insert' | 'update' | 'delete';
13
+ interface BaseMutation {
14
+ type: MutationType;
15
+ fullDocId: FullDocId;
16
+ }
17
+ export interface DeleteMutation extends BaseMutation {
18
+ type: 'delete';
19
+ }
20
+ export interface UpdateMutation<T = any> extends BaseMutation {
21
+ type: 'update';
22
+ properties: {
23
+ [key in keyof T & string]?: Array<PropertyMutation<T[key]>>;
24
+ };
25
+ }
26
+ export interface InsertMutation<T = any> extends BaseMutation {
27
+ type: 'insert';
28
+ properties: T;
29
+ }
30
+ export type PropertyMutation<Value = any> = ApplyNumericFnPropertyMutation | ApplyStringFnPropertyMutation | ValueUpdatePropertyMutation<Value> | RemovePropertyMutation;
31
+ export interface ValueUpdatePropertyMutation<Value = any> {
32
+ type: 'update';
33
+ value: Value;
34
+ }
35
+ export interface ApplyNumericFnPropertyMutation {
36
+ type: 'applyNumericFn';
37
+ fn: 'increment';
38
+ value: number;
39
+ }
40
+ export interface RemovePropertyMutation {
41
+ type: 'removeProperty';
42
+ }
43
+ interface ApplyExtendString {
44
+ type: 'applyStringFn';
45
+ fn: 'extendString';
46
+ value: string;
47
+ }
48
+ interface ApplyTrimString {
49
+ type: 'applyStringFn';
50
+ fn: 'trim';
51
+ }
52
+ export type ApplyStringFnPropertyMutation = ApplyExtendString | ApplyTrimString;
53
+ /**
54
+ * Sorts the update mutation properties in the order the properties should be applied. If the update mutation has
55
+ * updates for both 'a' and 'a.b', the update should be applied first to 'a' and then to 'a.b'.
56
+ */
57
+ export declare function sortUpdateMutationProperties(updateMutation: UpdateMutation): Array<[FieldName, Array<PropertyMutation>]>;
58
+ export declare function mergeMutations(mutationA: Mutation, mutationB: Mutation): Mutation;
59
+ export declare function applyUpdateMutation<T extends DocType>(doc: T, updateMutation: UpdateMutation<T>): T | undefined;
60
+ export declare function convertInsertToUpdate(insertMutation: InsertMutation): UpdateMutation;
61
+ /**
62
+ * Reduces the list of mutations such that each document will have a single mutation. If for example there are multiple
63
+ * updates to the same document, those will be merged and a single update will be returned.
64
+ */
65
+ export declare function reduceMutations(mutations: Array<Mutation<unknown>>): Array<Mutation<unknown>>;
66
+ export {};
@@ -0,0 +1,3 @@
1
+ import { JSONSchemaType } from 'ajv';
2
+ import { ExecuteNamedQueryRequest } from './named-query.types';
3
+ export declare const ExecuteNamedQueryRequestSchema: JSONSchemaType<ExecuteNamedQueryRequest>;
@@ -0,0 +1,9 @@
1
+ import { ClientId, ClientRequestId, IntegrationId } from './communication.types';
2
+ import { QueryName } from './application.types';
3
+ export interface ExecuteNamedQueryRequest {
4
+ integrationId: IntegrationId;
5
+ queryName: QueryName;
6
+ paramsRecordStr: string;
7
+ clientRequestId: ClientRequestId;
8
+ clientId: ClientId;
9
+ }
@@ -0,0 +1,2 @@
1
+ export * from './query-context';
2
+ export * from './simple-query-builder';
@@ -0,0 +1,41 @@
1
+ import { IntegrationId } from '../communication.types';
2
+ import { CollectionName, FieldName } from '../document.types';
3
+ import { AllOperators, ContextCondition, ContextConditions, FieldSort, GeneralCondition, GeneralConditions, GenericValue, Query } from '../query.types';
4
+ import { Paths } from '../types';
5
+ import { Auth, AuthWithBearer } from '../context.types';
6
+ export declare class QueryContext<T = any> {
7
+ readonly query: Query<T>;
8
+ private readonly auth;
9
+ private readonly parsedConditions;
10
+ constructor(query: Query<T>, auth: Auth | undefined);
11
+ getUserAuth(): AuthWithBearer | undefined;
12
+ get integrationId(): IntegrationId;
13
+ get collectionName(): CollectionName;
14
+ get limit(): number;
15
+ includesSorts(sorts: Array<FieldSort<T>>): boolean;
16
+ matchesSorts(sorts: Array<FieldSort<T>>): boolean;
17
+ includes<F extends FieldName<T>, O extends AllOperators>(fieldName: F, operator: O, value: GenericValue<T, F, O>): boolean;
18
+ includesCondition(condition: ContextCondition<T>): boolean;
19
+ includesConditions(conditions: GeneralConditions<T>): boolean;
20
+ matchesConditions(conditions: GeneralConditions<T>): boolean;
21
+ matchesQuery(query: Query<T>): boolean;
22
+ isSubsetOf<F extends FieldName<T>, O extends AllOperators>(fieldName: F, operator: O, value: GenericValue<T, F, O> | null): boolean;
23
+ isSubsetOfCondition(condition: GeneralCondition<T>): boolean;
24
+ isSubsetOfConditions(conditions: GeneralConditions<T>): boolean;
25
+ isSubsetOfQuery(query: Query<T>): boolean;
26
+ getConditionsFor<K extends FieldName<T>>(...fieldNames: K[]): ContextConditions<T, K>;
27
+ getConditionsForField<K extends Paths<T>>(fieldName: K): ContextConditions<T>;
28
+ /**
29
+ * Compares a condition against a given operator and value to determine if the
30
+ * provided condition is a subset of the operator and value. A condition is
31
+ * considered a subset if all values that satisfy (return true for) the
32
+ * condition also satisfy the operator and value.
33
+ *
34
+ * This is done using the underlying CompareTable, which provides a comparison
35
+ * function for each operator pair, or undefined if the comparison would
36
+ * always be false, regardless of the values.
37
+ */
38
+ private evaluateSubset;
39
+ private evaluateIncludes;
40
+ private parseConditions;
41
+ }
@@ -0,0 +1,14 @@
1
+ import { IntegrationId } from '../communication.types';
2
+ import { CollectionName, FieldName, PrimitiveFieldType, UserFacingDocType } from '../document.types';
3
+ import { Operator, Query } from '../query.types';
4
+ export declare class SimpleQueryBuilder<MyDocType extends UserFacingDocType> {
5
+ protected readonly collectionName: CollectionName;
6
+ protected readonly integrationId: IntegrationId;
7
+ protected readonly query: Query<MyDocType>;
8
+ constructor(collectionName: CollectionName, integrationId: IntegrationId);
9
+ where(fieldName: (keyof MyDocType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
10
+ limit(limit: number): this;
11
+ sortBy(fieldName: keyof MyDocType & FieldName, asc?: boolean): this;
12
+ build(): Query;
13
+ private mergeConditions;
14
+ }
@@ -0,0 +1,5 @@
1
+ import { JSONSchemaType } from 'ajv';
2
+ import { Query, QueryRequest, QueryUnsubscribeRequest } from './query.types';
3
+ export declare const QuerySchema: JSONSchemaType<Query>;
4
+ export declare const QueryRequestSchema: JSONSchemaType<QueryRequest>;
5
+ export declare const QueryUnsubscribeRequestSchema: JSONSchemaType<QueryUnsubscribeRequest>;
@@ -0,0 +1,118 @@
1
+ import { TriggerId } from './application.types';
2
+ import { AppId, ClientId, ClientRequestId, IntegrationId } from './communication.types';
3
+ import { CollectionName, DocType, FieldName, PrimitiveFieldType } from './document.types';
4
+ export type Conditions<Doc = any, F extends FieldName<Doc> = any> = Array<Condition<Doc, F>>;
5
+ export interface Condition<Doc = any, F extends FieldName<Doc> = any> {
6
+ fieldName: F;
7
+ operator: Operator;
8
+ value: Doc[F] | null;
9
+ }
10
+ export type Operator = '==' | '>=' | '<=' | '>' | '<' | '!=';
11
+ export type ContextConditions<Doc = any, F extends FieldName<Doc> = any> = Array<ContextCondition<Doc, F>>;
12
+ export type GenericValue<Doc = any, F extends FieldName<Doc> = any, O extends AllOperators = any> = O extends 'in' ? Array<Doc[F]> | null : O extends 'not in' ? Array<Doc[F]> | null : Doc[F] | null;
13
+ export type ContextCondition<Doc = any, F extends FieldName<Doc> = any> = InContextCondition<Doc, F> | NotInContextCondition<Doc, F> | OtherContextCondition<Doc, F>;
14
+ interface InContextCondition<Doc = any, F extends FieldName<Doc> = any> extends Omit<Condition<Doc, F>, 'operator' | 'value'> {
15
+ operator: 'in';
16
+ value: Array<Doc[F]>;
17
+ }
18
+ interface NotInContextCondition<Doc = any, F extends FieldName<Doc> = any> extends Omit<Condition<Doc, F>, 'operator' | 'value'> {
19
+ operator: 'not in';
20
+ value: Array<Doc[F]>;
21
+ }
22
+ interface OtherContextCondition<Doc = any, F extends FieldName<Doc> = any> extends Omit<Condition<Doc, F>, 'operator'> {
23
+ operator: Exclude<ContextOperator, 'in' | 'not in'>;
24
+ }
25
+ export interface GeneralCondition<Doc = any, F extends FieldName<Doc> = any> extends Omit<Condition<Doc, F>, 'operator' | 'value'> {
26
+ operator: AllOperators;
27
+ value: any;
28
+ }
29
+ export type GeneralConditions<Doc = any, F extends FieldName<Doc> = any> = Array<GeneralCondition<Doc, F>>;
30
+ export type ContextOperator = Exclude<Operator, '==' | '!='> | 'in' | 'not in';
31
+ export type AllOperators = Operator | 'in' | 'not in';
32
+ export interface FieldSort<Doc> {
33
+ fieldName: FieldName<Doc>;
34
+ asc: boolean;
35
+ }
36
+ interface RegularQueryKey {
37
+ queryType: 'query';
38
+ clientId: string;
39
+ clientRequestId: string;
40
+ }
41
+ interface TriggerKey {
42
+ queryType: 'trigger';
43
+ triggerId: TriggerId;
44
+ }
45
+ export type QueryKey = RegularQueryKey | TriggerKey;
46
+ export interface Query<Doc = any> {
47
+ collectionName: CollectionName;
48
+ integrationId: string;
49
+ conditions: Conditions<Doc>;
50
+ sortOrder: Array<FieldSort<Doc>>;
51
+ limit: number;
52
+ }
53
+ export type QuerySubscriptionId = `${ClientId}_${ClientRequestId}`;
54
+ export interface QueryRequest {
55
+ clientId: ClientId;
56
+ clientRequestId: ClientRequestId;
57
+ query: Query;
58
+ subscribe: boolean;
59
+ }
60
+ export interface QueryUnsubscribeRequest {
61
+ clientId: ClientId;
62
+ clientRequestId: ClientRequestId;
63
+ }
64
+ interface QueryMetadata {
65
+ condCount: number;
66
+ }
67
+ /**
68
+ * Example query mapping:
69
+ * {
70
+ * unconditional: ['cid_123'],
71
+ * conditional: {
72
+ * age: {
73
+ * '==': {
74
+ * 10: ['cid2_321'],
75
+ * 11: ['cid2_321'],
76
+ * 12: ['cid2_321'],
77
+ * },
78
+ * '>': {
79
+ * 20: ['cid_456']
80
+ * }
81
+ * }
82
+ * },
83
+ * queriesMetadata: {
84
+ * 'cid_123': {
85
+ * condCount: 0
86
+ * },
87
+ * 'cid2_321': {
88
+ * condCount: 1
89
+ * },
90
+ * 'cid2_456': {
91
+ * condCount: 1
92
+ * }
93
+ * }
94
+ * }
95
+ */
96
+ export type QueryMapping<T extends string> = {
97
+ unconditional: Array<T>;
98
+ conditional: Record<FieldName, Record<Operator, Record<PrimitiveFieldType & string, Array<T>>>>;
99
+ queriesMetadata: Record<T, QueryMetadata>;
100
+ };
101
+ export declare abstract class QueryMappingManager<T> {
102
+ abstract addQuery(appId: AppId, query: Query, key: T): Promise<void>;
103
+ abstract removeQuery(appId: AppId, key: T): Promise<Query | undefined>;
104
+ abstract findQueriesForDocument(appId: AppId, doc: DocType, collectionName: CollectionName, integrationId: IntegrationId): Promise<Array<T> | undefined>;
105
+ }
106
+ export declare abstract class SimpleQueryMappingManager<T extends string> extends QueryMappingManager<T> {
107
+ abstract getMapping(appId: AppId, collectionName: CollectionName, integrationId: IntegrationId): Promise<QueryMapping<T> | undefined> | (QueryMapping<T> | undefined);
108
+ findQueriesForDocument(appId: AppId, doc: DocType, collectionName: CollectionName, integrationId: IntegrationId): Promise<Array<T>>;
109
+ }
110
+ export declare function findQueriesForDocumentSync<T extends string>(mapping: QueryMapping<T>, doc: DocType): Array<T>;
111
+ export declare function compareOperator(conditionValue: PrimitiveFieldType, valueInDocument: PrimitiveFieldType, operator: Operator): boolean;
112
+ /** Returns a unique identifier for the query which includes both the client id and the client request id. */
113
+ export declare function getQuerySubscriptionId(clientId: string, clientRequestId: string): QuerySubscriptionId;
114
+ export declare function parseQuerySubscriptionId(querySubscriptionId: QuerySubscriptionId): {
115
+ clientId: string;
116
+ clientRequestId: string;
117
+ };
118
+ export {};
@@ -0,0 +1,34 @@
1
+ import { JSONSchema } from 'json-schema-typed';
2
+ export type FieldPlaceholder = '__SQUID_SERVER_TIMESTAMP__' | '__SQUID_CLIENT_IP__' | '__SQUID_USER_ID__' | '__SQUID_API_KEY__';
3
+ export type SupportedFieldType = 'string' | 'integer' | 'number' | 'date' | 'boolean' | 'map' | 'array' | 'any';
4
+ export declare const SUPPORTED_FIELD_TYPES_ARRAY: Array<SupportedFieldType>;
5
+ type ConvertDeep<T extends JSONSchema> = Exclude<T, boolean> & {
6
+ properties?: Record<string, ConvertDeep<JSONSchema>>;
7
+ patternProperties?: Record<string, ConvertDeep<JSONSchema>>;
8
+ /**
9
+ * The default value will be applied (default to 'empty'):
10
+ * 'always' - no matter what the client sent, both on update and insert. In case of readOnly - applies only on insert.
11
+ * 'empty' - only if the value of the filed is empty (undefined)
12
+ * 'updateOrEmpty' - no matter what the client sent, updating the record will use the default value
13
+ */
14
+ applyDefaultValueOn?: 'always' | 'empty' | 'updateOrEmpty';
15
+ isDate?: boolean;
16
+ /**
17
+ * Applies to the top level schema, a record in a nested object, or a regular property.
18
+ * Basically, whether this property can participate in an insert mutation.
19
+ */
20
+ insertable?: boolean;
21
+ /** Applies to the top level schema or a record in a nested object. */
22
+ deletable?: boolean;
23
+ };
24
+ export type PropertySchema = ConvertDeep<JSONSchema>;
25
+ export type TopLevelPropertySchema = PropertySchema & {
26
+ primaryKey?: boolean;
27
+ };
28
+ export type CollectionSchema = ConvertDeep<JSONSchema> & {
29
+ properties?: Record<string, TopLevelPropertySchema>;
30
+ };
31
+ export declare function compileSchema<S extends CollectionSchema>(schema: S): any;
32
+ export declare function validateSchema<S extends CollectionSchema>(schema: S, data: any, updatedPaths?: Array<string>, dataBefore?: any): void;
33
+ export declare function findMatchingPropertiesForKey<S extends CollectionSchema | PropertySchema>(schema: S, key: string): Array<PropertySchema>;
34
+ export {};
@@ -0,0 +1,6 @@
1
+ import { JSONSchemaType } from 'ajv';
2
+ import { DeleteApiKeyRequest, DeleteCustomSecretRequest, GenerateNewApiKeyRequest, SetCustomSecretRequest } from './secret.types';
3
+ export declare const SetCustomSecretRequestSchema: JSONSchemaType<SetCustomSecretRequest>;
4
+ export declare const DeleteCustomSecretRequestSchema: JSONSchemaType<DeleteCustomSecretRequest>;
5
+ export declare const DeleteApiKeyRequestSchema: JSONSchemaType<DeleteApiKeyRequest>;
6
+ export declare const GenerateNewApiKeyRequestSchema: JSONSchemaType<GenerateNewApiKeyRequest>;
@@ -0,0 +1,30 @@
1
+ export type SecretKey = string;
2
+ export type SecretValue = string | number | boolean;
3
+ export type SecretTimestamp = number;
4
+ export type ApiKeyName = string;
5
+ export type ApiKey = string;
6
+ export interface ApplicationSecrets {
7
+ custom: Record<SecretKey, SecretEntry>;
8
+ apiKeys: Record<SecretKey, SecretEntry>;
9
+ }
10
+ export interface SystemSecrets {
11
+ sharedMongo: Record<SecretKey, SecretValue>;
12
+ }
13
+ export interface SecretMetadata {
14
+ key: SecretKey;
15
+ lastUpdated: SecretTimestamp;
16
+ }
17
+ export interface SecretEntry extends SecretMetadata {
18
+ value: SecretValue;
19
+ }
20
+ export type SetCustomSecretRequest = Omit<SecretEntry, 'lastUpdated'>;
21
+ export type DeleteCustomSecretRequest = Pick<SecretMetadata, 'key'>;
22
+ export type DeleteApiKeyRequest = Pick<SecretMetadata, 'key'>;
23
+ export interface ListApplicationSecretMetadataResponse {
24
+ custom: SecretMetadata[];
25
+ apiKeys: SecretMetadata[];
26
+ }
27
+ export type GenerateNewApiKeyRequest = Pick<SecretMetadata, 'key'>;
28
+ export interface GenerateNewApiKeyResponse {
29
+ apiKey: string;
30
+ }
@@ -0,0 +1,3 @@
1
+ import { JSONSchemaType } from 'ajv';
2
+ import { MessageFromClient } from './socket.types';
3
+ export declare const MessageFromClientSchema: JSONSchemaType<MessageFromClient>;
@@ -0,0 +1,68 @@
1
+ import { ClientId, ClientRequestId, IntegrationId } from './communication.types';
2
+ import { CollectionName, DocTimestamp, DocType, FullDocIdStr } from './document.types';
3
+ import { MutationType } from './mutation.types';
4
+ export type MessageId = string;
5
+ export type MessageFromClientType = 'acknowledge' | 'catchup' | 'kill';
6
+ interface BaseMessageFromClient {
7
+ type: MessageFromClientType;
8
+ payload?: unknown;
9
+ }
10
+ export interface AcknowledgeMessage extends BaseMessageFromClient {
11
+ type: 'acknowledge';
12
+ payload: Array<MessageId>;
13
+ }
14
+ export interface CatchupMessage extends BaseMessageFromClient {
15
+ type: 'catchup';
16
+ }
17
+ export interface KillMessage extends BaseMessageFromClient {
18
+ type: 'kill';
19
+ }
20
+ export type MessageFromClient = AcknowledgeMessage | CatchupMessage | KillMessage;
21
+ export type MessageToClientType = 'mutations' | 'query' | 'backendFunction' | 'api' | 'namedQuery';
22
+ interface BaseMessageToClient {
23
+ type: MessageToClientType;
24
+ messageId: MessageId;
25
+ payload: unknown;
26
+ }
27
+ export interface BackendFunctionMessageToClient extends BaseMessageToClient {
28
+ type: 'backendFunction';
29
+ clientRequestId: ClientRequestId;
30
+ payload: string;
31
+ }
32
+ export interface NamedQueryMessageToClient extends BaseMessageToClient {
33
+ type: 'namedQuery';
34
+ clientRequestId: ClientRequestId;
35
+ payload: string;
36
+ }
37
+ export interface ApiResponseMessageToClient extends BaseMessageToClient {
38
+ type: 'api';
39
+ clientRequestId: ClientRequestId;
40
+ success: boolean;
41
+ httpStatus: number;
42
+ payload: string;
43
+ }
44
+ export type MessageToClient = MutationsMessageToClient | QueryResultMessageToClient | BackendFunctionMessageToClient | NamedQueryMessageToClient | ApiResponseMessageToClient;
45
+ export interface MutationsMessageToClient extends BaseMessageToClient {
46
+ type: 'mutations';
47
+ payload: Array<MutationResultData>;
48
+ }
49
+ export interface MutationResultData {
50
+ fullDocIdStr: FullDocIdStr;
51
+ clientRequestId: ClientRequestId;
52
+ mutationType: MutationType;
53
+ mutationTimestamp: DocTimestamp;
54
+ doc: DocType | undefined;
55
+ }
56
+ export interface QueryResultData {
57
+ docs: Array<DocType>;
58
+ integrationId: IntegrationId;
59
+ collectionName: CollectionName;
60
+ clientRequestId: ClientRequestId;
61
+ }
62
+ export interface QueryResultMessageToClient extends BaseMessageToClient {
63
+ type: 'query';
64
+ payload: QueryResultData;
65
+ }
66
+ export type PendingMessage = Omit<MessageToClient, 'messageId'>;
67
+ export type PendingMessages = Record<ClientId, Array<PendingMessage>>;
68
+ export {};
@@ -0,0 +1,5 @@
1
+ export declare const SECONDS_PER_MINUTE = 60;
2
+ export declare const SECONDS_PER_HOUR: number;
3
+ export declare const SECONDS_PER_DAY: number;
4
+ export declare const SECONDS_PER_WEEK: number;
5
+ export declare const SECONDS_PER_MONTH: number;
@@ -0,0 +1,17 @@
1
+ import { ServiceFunctionName } from './bundle-data.types';
2
+ import { AppId } from './communication.types';
3
+ import { Auth } from './context.types';
4
+ import { DocType, FullDocIdStr } from './document.types';
5
+ import { MutationType } from './mutation.types';
6
+ export interface DocTriggerParams {
7
+ fullDocId: FullDocIdStr;
8
+ mutationType: MutationType;
9
+ docBefore?: DocType;
10
+ docAfter?: DocType;
11
+ auth: Auth | undefined;
12
+ }
13
+ export interface TriggerMessage {
14
+ params: DocTriggerParams;
15
+ functionName: ServiceFunctionName;
16
+ appId: AppId;
17
+ }
@@ -0,0 +1,15 @@
1
+ export interface Type<T> extends Function {
2
+ new (...args: any[]): T;
3
+ }
4
+ export type Replace<TypeToBeChecked, KeyToBeReplaced extends keyof TypeToBeChecked, NewValueToUse> = Omit<TypeToBeChecked, KeyToBeReplaced> & {
5
+ [P in KeyToBeReplaced]: NewValueToUse;
6
+ };
7
+ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
8
+ export type WithRequired<T, K extends keyof T> = T & {
9
+ [P in K]-?: T[P];
10
+ };
11
+ type Pred = [0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
12
+ export type Paths<T, RemainingDepth extends number & keyof Pred = 5, Prefix extends string = ''> = RemainingDepth extends 0 ? `${Prefix}${string}` : {
13
+ [k in keyof T]-?: k extends string | number ? `${Prefix}${k}` | (Required<T>[k] extends any[] ? never : Required<T>[k] extends object ? Paths<Required<T>[k], Pred[RemainingDepth], `${Prefix}${k}.`> : never) : never;
14
+ }[keyof T];
15
+ export {};
@@ -0,0 +1,7 @@
1
+ export declare function binarySearch<T>(arr: T[], key: T, comparator?: (a: T, b: T) => number, low?: number, high?: number): number;
2
+ export declare function insertSorted<T>(arr: T[], key: T, comparator?: (a: T, b: T) => number): void;
3
+ export declare function removeSorted<T>(arr: T[], key: T, comparator?: (a: T, b: T) => number): void;
4
+ export interface Grouped<T> {
5
+ [key: string]: T[];
6
+ }
7
+ export declare function asyncGroupBy<T>(arr: T[], groupNamer: (element: T) => Promise<string>): Promise<Grouped<T>>;
@@ -0,0 +1,6 @@
1
+ import { StatusCode } from './validation';
2
+ export type AssertErrorProvider = () => Error | string;
3
+ export declare function assertTruthy(value: unknown, error?: string | Error | AssertErrorProvider): asserts value;
4
+ export declare function assertValidateTruthy(value: unknown, message: string, statusCode?: StatusCode, details?: Record<string, any>): asserts value;
5
+ export declare function truthy<T>(value: T, error?: string | Error | AssertErrorProvider): NonNullable<T>;
6
+ export declare function validateTruthy<T>(value: T, message: string, statusCode?: StatusCode, details?: Record<string, any>): NonNullable<T>;
@@ -0,0 +1,4 @@
1
+ export declare class CodeExecutionError extends Error {
2
+ readonly details?: string | undefined;
3
+ constructor(error: string, details?: string | undefined);
4
+ }
@@ -0,0 +1,14 @@
1
+ type LockMutex = string;
2
+ /**
3
+ * A simple lock manager that locks a list of mutexes.
4
+ * When locking a list of mutexes, the lock will start only when all the mutexes are available - preventing partial lock
5
+ * and potential deadlocks.
6
+ */
7
+ export declare class LockManager {
8
+ private readonly locks;
9
+ lock(...mutexes: LockMutex[]): Promise<void>;
10
+ release(...mutexes: LockMutex[]): void;
11
+ canGetLock(...mutexes: LockMutex[]): boolean;
12
+ lockSync(...mutexes: LockMutex[]): void;
13
+ }
14
+ export {};
@@ -0,0 +1,4 @@
1
+ export declare function getInPath(obj: any, path: string): any;
2
+ export declare function setInPath(obj: any, path: string, value: any): void;
3
+ export declare function deleteInPath(obj: any, path: string): void;
4
+ export declare function deepReplace(obj: any, keyName: string, replacer: (from: any) => any): void;
@@ -0,0 +1,5 @@
1
+ export declare function normalizeJsonAsString(json: any): string;
2
+ export declare function serializeObj(obj: any): string;
3
+ export declare function deserializeObj<T = any>(serializedObj: string): T;
4
+ export declare function encodeValueForMapping(value: any): string;
5
+ export declare function decodeValueForMapping(encodedString: string): any;
@@ -0,0 +1 @@
1
+ export declare function getApplicationUrl(baseUrl: string, appId: string): string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * This file contains general validators for the different objects being received from the client. The parameters are
3
+ * usually of type 'any' to make sure there are no assumptions that the object has the correct type.
4
+ * Also, this file should avoid importing from other files that are not for validation to avoid circular deps.
5
+ */
6
+ import { OpenIdProvider } from '../application.types';
7
+ import { HttpStatus } from '../http-status.enum';
8
+ export type StatusCode = HttpStatus.BAD_REQUEST | HttpStatus.NOT_FOUND | HttpStatus.FORBIDDEN | HttpStatus.UNAUTHORIZED;
9
+ export declare class ValidationError extends Error {
10
+ readonly statusCode: StatusCode;
11
+ readonly details?: any;
12
+ constructor(error: string, statusCode: StatusCode, details?: Record<string, any>);
13
+ }
14
+ export declare function validateFieldSort(fieldSort: any): void;
15
+ export declare function validateOpenIdProvider(openIdProvider: OpenIdProvider | undefined): OpenIdProvider;
16
+ export declare function validateOpenIdProviderType(providerType: any): void;
17
+ export declare function validateMutations(mutations: any): void;
18
+ export declare function validateQueryLimit(limit: any): void;
19
+ /** Returns true if the value is not an empty string (undefined/null are considered empty). */
20
+ export declare function isNotEmpty(value: string | undefined | null): value is string;
21
+ /**
22
+ * All type names returned by 'typeof' supported by JavaScript:
23
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof.
24
+ * and a few other supported types.
25
+ */
26
+ export type JavascriptTypeName = 'undefined' | 'object' | 'boolean' | 'number' | 'bigint' | 'string' | 'symbol' | 'function';
27
+ /** Returns true if 'typeof' of the 'value' is 'type' or 'type[]'. */
28
+ export declare function isRightType(value: unknown, type: JavascriptTypeName): boolean;
29
+ /** Returns true if 'obj' has only keys listed in the 'keys'. Object can't be an array. */
30
+ export declare function hasOnlyKeys(obj: object, keys: string[]): boolean;