Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add types #165

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# types

This package exports the `types` used in [Frigg](https://friggframework.org) packages.


### Get Started
Install the package with `npm` or `yarn`:

```bash
npm install @friggframework/types
```
or
```bash
yarn add @friggframework/types
```

Make sure to reference the types in your `tsconfig.json`

```json
"typeRoots": [
"./node_modules/@types",
"./node_modules/@friggframework/types"
]
```
83 changes: 83 additions & 0 deletions packages/types/assertions/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
declare module "@friggframework/assertions" {
type TypeOfType =
| "undefined"
| "object"
| "boolean"
| "number"
| "string"
| "function"
| "symbol"
| "bigint";

export function get<TObject extends object, TKey extends string, TDefault>(
object: TObject,
key: TKey | undefined,
defaultValue: Exclude<TDefault, undefined>
): TKey extends keyof TObject ? TObject[TKey] : TDefault;

export function get<TObject extends object, TKey extends keyof TObject>(
object: TObject,
key: TKey
): TObject[TKey];

export function getAll<TObject extends object, TKey extends keyof TObject>(
object: TObject,
requiredKeys: TKey[]
): Partial<TObject>;

export function verifyType(value: unknown, paramType: TypeOfType): void;

export function getParamAndVerifyParamType<
TObject extends object,
TKey extends string,
TKeyType extends TypeOfType,
TDefault
>(
params: TObject,
key: TKey,
type: TKeyType,
defaultValue: TDefault
): TDefault;

export function getParamAndVerifyParamType<
TObject extends object,
TKey extends keyof TObject,
TKeyType extends TypeOfType
>(params: TObject, key: TKey, type: TKeyType): TObject[TKey];

export function getArrayParamAndVerifyParamType<
TObject extends object,
TKey extends string,
TKeyType extends TypeOfType,
TDefault
>(
params: TObject,
key: TKey,
type: TKeyType,
defaultValue: TDefault
): TDefault;

export function getArrayParamAndVerifyParamType<
TObject extends object,
TKey extends keyof TObject,
TKeyType extends TypeOfType
>(params: TObject, key: TKey, type: TKeyType): TObject[TKey];

export function getAndVerifyType<
TObject extends object,
TKey extends keyof TObject,
TClassType extends unknown
>(object: TObject, key: TKey, classType: TClassType): TObject[TKey];

export function getAndVerifyType<
TObject extends object,
TKey extends string,
TClassType extends unknown,
TDefault
>(
object: TObject,
key: TKey,
classType: TClassType,
defaultValue: TDefault
): TKey extends keyof TObject ? TObject[TKey] : TDefault;
}
74 changes: 74 additions & 0 deletions packages/types/associations/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
declare module "@friggframework/associations/model" {
import { Model } from "mongoose";

export class Association extends Model {
integrationId: string;
name: string;
type: string;
primaryObject: string;
objects: {
entityId: string;
objectType: string;
objId: string;
metadata?: object;
}[];
}
}

declare module "@friggframework/associations/association" {
export default class Association implements IFriggAssociation {
data: any;
dataIdentifier: any;
dataIdentifierHash: string;
matchHash: string;
moduleName: any;
syncId: any;

static Config: {
name: "Association";
reverseModuleMap: {};
};

constructor(params: AssociationConstructor);

dataKeyIsReplaceable(key: string): boolean;

equals(syncObj: any): boolean;

getHashData(): string;

getName(): any;

hashJSON(data: any): string;

isModuleInMap(moduleName: any): any;

reverseModuleMap(moduleName: any): any;

setSyncId(syncId: string): any;
}

interface IFriggAssociation {
data: any;
moduleName: any;
dataIdentifier: any;
dataIdentifierHash: string;
matchHash: string;
syncId: any;

equals(syncObj: any): boolean;
dataKeyIsReplaceable(key: string): boolean;
isModuleInMap(moduleName: any): any;
getName(): any;
getHashData(): string;
setSyncId(syncId: string): any;
reverseModuleMap(moduleName: any): any;
hashJSON(data: any): string;
}

type AssociationConstructor = {
data: any;
moduleName: any;
dataIdentifier: any;
};
}
54 changes: 54 additions & 0 deletions packages/types/core/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
declare module "@friggframework/core" {
import { SQS } from "aws-sdk";

export class Delegate implements IFriggDelegate {
delegate: any;
delegateTypes: any[];

constructor(params: Record<string, unknown> & { delegate?: unknown });
notify(delegateString: string, object?: any): Promise<any>;
receiveNotification(
notifier: any,
delegateString: string,
object?: any
): Promise<any>;
}

interface IFriggDelegate {
delegate: any;
delegateTypes: any[];

notify(delegateString: string, object?: any): Promise<any>;
receiveNotification(
notifier: any,
delegateString: string,
object?: any
): Promise<any>;
}

export class Worker implements IWorker {
getQueueURL(params: GetQueueURLParams): Promise<string | undefined>;

run(params: { Records: any }): Promise<void>;

send(params: object & { QueueUrl: any }, delay?: number): Promise<string>;

sendAsyncSQSMessage(params: SendSQSMessageParams): Promise<string>;
}

interface IWorker {
getQueueURL(params: GetQueueURLParams): Promise<string | undefined>;
run(params: { Records: any }): Promise<void>;
send(params: object & { QueueUrl: any }, delay?: number): Promise<string>;
sendAsyncSQSMessage(params: SendSQSMessageParams): Promise<string>;
}

export function loadInstalledModules(): any[];

type GetQueueURLParams = {
QueueName: string;
QueueOwnerAWSAccountId?: string;
};

type SendSQSMessageParams = SQS.SendMessageRequest;
}
3 changes: 3 additions & 0 deletions packages/types/database/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module "@friggframework/database/mongo" {
export function connectToDatabase(): Promise<void>;
}
5 changes: 5 additions & 0 deletions packages/types/encrypt/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module "@friggframework/encrypt" {
import { Schema } from "mongoose";

export function Encrypt(schema: Schema, options: any): void;
}
66 changes: 66 additions & 0 deletions packages/types/errors/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
declare module "@friggframework/errors" {
export class BaseError extends Error {
constructor(message?: string, options?: ErrorOptions, ...otherOptions: any);
}

export class FetchError extends BaseError {
constructor(options?: FetchErrorConstructor);

static create(options?: CreateFetchErrorParams): Promise<FetchError>;
}

type FetchErrorConstructor = {
resource?: string;
init?: Partial<{
method: string;
credentials: string;
headers: object;
query: object;
body: URLSearchParams | any;
returnFullRes: false;
}>;
response?: {
headers?: object;
status?: number;
statusText?: string;
text?: () => Promise<string>;
};
responseBody?: any;
};

type CreateFetchErrorParams = Omit<FetchErrorConstructor, "responseBody"> & {
body: any;
};

export class HaltError extends BaseError {
isHaltError: boolean;
}

export class RequiredPropertyError extends BaseError {
constructor(
options: RequiredPropertyErrorOptions,
otherOptions?: ErrorOptions
);
}

type RequiredPropertyErrorOptions = {
parent?: new () => Class;
key: string;
};

export class ParameterTypeError extends BaseError {
constructor(
options: ParameterTypeErrorOptions,
otherOptions?: ErrorOptions
);
}

type ParameterTypeErrorOptions = {
parent?: new () => Class;
key: string;
value: string;
expectedType: new () => Class;
};

type Class<T = any> = new (...args: any[]) => T;
}
41 changes: 41 additions & 0 deletions packages/types/eslint-config/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
declare module "@friggframework/eslint-config" {
const config: {
env: {
commonjs: true,
es2020: true,
jest: true,
},
extends: ["prettier", "plugin:markdown/recommended"],
parser: "@babel/eslint-parser",
parserOptions: {
ecmaVersion: 11,
requireConfigFile: false,
},
plugins: ["no-only-tests"],
ignorePatterns: ["coverage/", ".nyc_output/"],
overrides: [
{
files: ["*.json"],
plugins: ["json"],
extends: ["plugin:json/recommended"],
},
{
files: ["*.yaml", "*.yml"],
plugins: ["yaml"],
extends: ["plugin:yaml/recommended"],
},
],
rules: {
"no-only-tests/no-only-tests": ["error", { fix: false }],
"no-unused-vars": [
"warn",
{ vars: "all", args: "after-used", ignoreRestSiblings: false },
],
"no-console": ["warn"],
camelcase: ["warn"],
"no-mixed-requires": ["warn"],
"no-warning-comments": ["warn"],
},
};
export default config;
}
14 changes: 14 additions & 0 deletions packages/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path="./assertions/index.d.ts" />
/// <reference path="./core/index.d.ts" />
/// <reference path="./integrations/index.d.ts" />
/// <reference path="./encrypt/index.d.ts" />
/// <reference path="./errors/index.d.ts" />
/// <reference path="./module-plugin/index.d.ts" />
/// <reference path="./database/index.d.ts" />
/// <reference path="./lambda/index.d.ts" />
/// <reference path="./logs/index.d.ts" />
/// <reference path="./test-environment/index.d.ts" />
/// <reference path="./prettier-config/index.d.ts" />
/// <reference path="./eslint-config/index.d.ts" />
/// <reference path="./associations/index.d.ts" />
/// <reference path="./syncs/index.d.ts" />
Loading