-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from Fibii/charef/feat/add-types
add types
- Loading branch information
Showing
19 changed files
with
9,469 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare module "@friggframework/database/mongo" { | ||
export function connectToDatabase(): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" /> |
Oops, something went wrong.