-
-
Notifications
You must be signed in to change notification settings - Fork 600
fix: Add server-side Cloud Code types for parse/node #2855
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
Open
hajjarjoseph
wants to merge
9
commits into
parse-community:alpha
Choose a base branch
from
hajjarjoseph:fix/cloud-server-types
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,082
−510
Open
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2b70e4a
fix: Add server-side Cloud Code types for parse/node
hajjarjoseph 51fab0a
fix: Add missing generic and export in node.d.ts
hajjarjoseph 08766ab
fix: Add missing exports and context property to find requests
hajjarjoseph b09807b
refactor: Move Cloud types to source and add comprehensive tests
hajjarjoseph 0cc5c26
fix: ESLint errors in Cloud Code tests
hajjarjoseph 62ff1f1
fix: ESLint errors in CloudCode.ts
hajjarjoseph 17da4a8
refactor: Move JSDoc to functions and clean up Cloud Code tests
hajjarjoseph 469b4db
fix: Add missing JSDoc params for sendEmail function
hajjarjoseph 685cf2d
chore: Regenerate type definitions
hajjarjoseph File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,3 +1,306 @@ | ||
| import type ParseObject from './ParseObject'; | ||
| import type ParseUser from './ParseUser'; | ||
| import type ParseFile from './ParseFile'; | ||
| import type ParseQuery from './ParseQuery'; | ||
|
|
||
| // ============================================================================ | ||
| // Request Interfaces | ||
| // ============================================================================ | ||
|
|
||
| export interface FunctionRequest<T = Record<string, any>> { | ||
| installationId?: string; | ||
| master: boolean; | ||
| user?: ParseUser; | ||
| params: T; | ||
| ip: string; | ||
| headers: Record<string, string>; | ||
| log: any; | ||
| functionName: string; | ||
| context: Record<string, unknown>; | ||
| config: any; | ||
| } | ||
|
|
||
| export interface FunctionResponse { | ||
| success: (result?: any) => void; | ||
| error: (message?: string) => void; | ||
| status: (code: number) => FunctionResponse; | ||
| header: (name: string, value: string) => FunctionResponse; | ||
| } | ||
|
|
||
| export interface TriggerRequest<T extends ParseObject = ParseObject> { | ||
| installationId?: string; | ||
| master: boolean; | ||
| isChallenge: boolean; | ||
| user?: ParseUser; | ||
| object: T; | ||
| original?: T; | ||
| ip: string; | ||
| headers: Record<string, string>; | ||
| triggerName: string; | ||
| log: any; | ||
| context: Record<string, unknown>; | ||
| config: any; | ||
| } | ||
|
|
||
| export type BeforeSaveRequest<T extends ParseObject = ParseObject> = TriggerRequest<T>; | ||
| export type AfterSaveRequest<T extends ParseObject = ParseObject> = TriggerRequest<T>; | ||
| export type BeforeDeleteRequest<T extends ParseObject = ParseObject> = TriggerRequest<T>; | ||
| export type AfterDeleteRequest<T extends ParseObject = ParseObject> = TriggerRequest<T>; | ||
|
|
||
| export interface BeforeFindRequest<T extends ParseObject = ParseObject> { | ||
| installationId?: string; | ||
| master: boolean; | ||
| user?: ParseUser; | ||
| query: ParseQuery<T>; | ||
| ip: string; | ||
| headers: Record<string, string>; | ||
| triggerName: string; | ||
| log: any; | ||
| isGet: boolean; | ||
| config: any; | ||
| context: Record<string, unknown>; | ||
| readPreference?: string; | ||
| count?: boolean; | ||
| } | ||
|
|
||
| export interface AfterFindRequest<T extends ParseObject = ParseObject> { | ||
| installationId?: string; | ||
| master: boolean; | ||
| user?: ParseUser; | ||
| query: ParseQuery<T>; | ||
| results: T[]; | ||
| ip: string; | ||
| headers: Record<string, string>; | ||
| triggerName: string; | ||
| log: any; | ||
| config: any; | ||
| context: Record<string, unknown>; | ||
| } | ||
|
|
||
| export interface FileTriggerRequest { | ||
| installationId?: string; | ||
| master: boolean; | ||
| user?: ParseUser; | ||
| file: ParseFile; | ||
| fileSize: number; | ||
| contentLength: number; | ||
| ip: string; | ||
| headers: Record<string, string>; | ||
| triggerName: string; | ||
| log: any; | ||
| config: any; | ||
| } | ||
|
|
||
| export interface ConnectTriggerRequest { | ||
| installationId?: string; | ||
| useMasterKey: boolean; | ||
| user?: ParseUser; | ||
| clients: number; | ||
| subscriptions: number; | ||
| sessionToken?: string; | ||
| } | ||
|
|
||
| export interface LiveQueryEventTrigger<T extends ParseObject = ParseObject> { | ||
| installationId?: string; | ||
| useMasterKey: boolean; | ||
| user?: ParseUser; | ||
| sessionToken?: string; | ||
| event: string; | ||
| object: T; | ||
| original?: T; | ||
| clients: number; | ||
| subscriptions: number; | ||
| sendEvent: boolean; | ||
| } | ||
|
|
||
| export interface JobRequest { | ||
| params: Record<string, any>; | ||
| message: (message: string) => void; | ||
| config: any; | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // Validator Types | ||
| // ============================================================================ | ||
|
|
||
| export interface ValidatorField { | ||
| type?: any; | ||
| constant?: boolean; | ||
| default?: any; | ||
| options?: any[] | (() => any[]) | any; | ||
| required?: boolean; | ||
| error?: string; | ||
| } | ||
|
|
||
| export interface ValidatorObject { | ||
| requireUser?: boolean; | ||
| requireMaster?: boolean; | ||
| validateMasterKey?: boolean; | ||
| skipWithMasterKey?: boolean; | ||
| requireAnyUserRoles?: string[] | (() => string[]); | ||
| requireAllUserRoles?: string[] | (() => string[]); | ||
| requireUserKeys?: string[] | Record<string, ValidatorField>; | ||
| fields?: string[] | Record<string, ValidatorField>; | ||
| rateLimit?: { | ||
| requestPath?: string; | ||
| requestMethods?: string | string[]; | ||
| requestTimeWindow?: number; | ||
| requestCount?: number; | ||
| errorResponseMessage?: string; | ||
| includeInternalRequests?: boolean; | ||
| includeMasterKey?: boolean; | ||
| }; | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // HTTP Types | ||
| // ============================================================================ | ||
|
|
||
| export interface HTTPOptions { | ||
| body?: string | object; | ||
| error?: (response: HTTPResponse) => void; | ||
| followRedirects?: boolean; | ||
| headers?: Record<string, string>; | ||
| method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS'; | ||
| params?: string | Record<string, string>; | ||
| success?: (response: HTTPResponse) => void; | ||
| url: string; | ||
| } | ||
|
|
||
| export interface HTTPResponse { | ||
| buffer?: Buffer; | ||
| cookies?: Record<string, any>; | ||
| data?: any; | ||
| headers?: Record<string, string>; | ||
| status: number; | ||
| text?: string; | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // Enum | ||
| // ============================================================================ | ||
|
|
||
| export enum ReadPreferenceOption { | ||
| Primary = 'PRIMARY', | ||
| PrimaryPreferred = 'PRIMARY_PREFERRED', | ||
| Secondary = 'SECONDARY', | ||
| SecondaryPreferred = 'SECONDARY_PREFERRED', | ||
| Nearest = 'NEAREST', | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // Function Declarations (server-side only, implemented by Parse Server) | ||
| // ============================================================================ | ||
|
|
||
| export declare function define<T extends Record<string, any> = Record<string, any>>( | ||
| name: string, | ||
| handler: (request: FunctionRequest<T>) => any, | ||
| validator?: ValidatorObject | ((request: FunctionRequest<T>) => any) | ||
| ): void; | ||
|
|
||
| export declare function job(name: string, handler: (request: JobRequest) => any): void; | ||
|
|
||
| export declare function beforeSave<T extends ParseObject = ParseObject>( | ||
| className: string | (new () => T), | ||
| handler: (request: BeforeSaveRequest<T>) => T | undefined | Promise<T | undefined>, | ||
| validator?: ValidatorObject | ((request: BeforeSaveRequest<T>) => any) | ||
| ): void; | ||
|
|
||
| export declare function afterSave<T extends ParseObject = ParseObject>( | ||
| className: string | (new () => T), | ||
| handler: (request: AfterSaveRequest<T>) => Promise<void> | undefined, | ||
| validator?: ValidatorObject | ((request: AfterSaveRequest<T>) => any) | ||
| ): void; | ||
|
|
||
| export declare function beforeDelete<T extends ParseObject = ParseObject>( | ||
| className: string | (new () => T), | ||
| handler: (request: BeforeDeleteRequest<T>) => Promise<void> | undefined, | ||
| validator?: ValidatorObject | ((request: BeforeDeleteRequest<T>) => any) | ||
| ): void; | ||
|
|
||
| export declare function afterDelete<T extends ParseObject = ParseObject>( | ||
| className: string | (new () => T), | ||
| handler: (request: AfterDeleteRequest<T>) => Promise<void> | undefined, | ||
| validator?: ValidatorObject | ((request: AfterDeleteRequest<T>) => any) | ||
| ): void; | ||
|
|
||
| export declare function beforeFind<T extends ParseObject = ParseObject>( | ||
| className: string | (new () => T), | ||
| handler: (request: BeforeFindRequest<T>) => ParseQuery<T> | undefined | Promise<ParseQuery<T> | undefined>, | ||
| validator?: ValidatorObject | ((request: BeforeFindRequest<T>) => any) | ||
| ): void; | ||
|
|
||
| export declare function afterFind<T extends ParseObject = ParseObject>( | ||
| className: string | (new () => T), | ||
| handler: (request: AfterFindRequest<T>) => T[] | undefined | Promise<T[] | undefined>, | ||
| validator?: ValidatorObject | ((request: AfterFindRequest<T>) => any) | ||
| ): void; | ||
|
|
||
| export declare function beforeLogin( | ||
| handler: (request: TriggerRequest<ParseUser>) => Promise<void> | undefined, | ||
| validator?: ValidatorObject | ((request: TriggerRequest<ParseUser>) => any) | ||
| ): void; | ||
|
|
||
| export declare function afterLogin( | ||
| handler: (request: TriggerRequest<ParseUser>) => Promise<void> | undefined | ||
| ): void; | ||
|
|
||
| export declare function afterLogout( | ||
| handler: (request: TriggerRequest) => Promise<void> | undefined | ||
| ): void; | ||
|
|
||
| export declare function beforePasswordResetRequest( | ||
| handler: (request: TriggerRequest<ParseUser>) => Promise<void> | undefined, | ||
| validator?: ValidatorObject | ((request: TriggerRequest<ParseUser>) => any) | ||
| ): void; | ||
|
|
||
| export declare function beforeSaveFile( | ||
| handler: (request: FileTriggerRequest) => ParseFile | undefined | Promise<ParseFile | undefined> | ||
| ): void; | ||
|
|
||
| export declare function afterSaveFile( | ||
| handler: (request: FileTriggerRequest) => Promise<void> | undefined | ||
| ): void; | ||
|
|
||
| export declare function beforeDeleteFile( | ||
| handler: (request: FileTriggerRequest) => Promise<void> | undefined | ||
| ): void; | ||
|
|
||
| export declare function afterDeleteFile( | ||
| handler: (request: FileTriggerRequest) => Promise<void> | undefined | ||
| ): void; | ||
|
|
||
| export declare function beforeConnect( | ||
| handler: (request: ConnectTriggerRequest) => Promise<void> | undefined, | ||
| validator?: ValidatorObject | ((request: ConnectTriggerRequest) => any) | ||
| ): void; | ||
|
|
||
| export declare function beforeSubscribe<T extends ParseObject = ParseObject>( | ||
| className: string | (new () => T), | ||
| handler: (request: TriggerRequest<T>) => Promise<void> | undefined, | ||
| validator?: ValidatorObject | ((request: TriggerRequest<T>) => any) | ||
| ): void; | ||
|
|
||
| export declare function afterLiveQueryEvent<T extends ParseObject = ParseObject>( | ||
| className: string | (new () => T), | ||
| handler: (request: LiveQueryEventTrigger<T>) => Promise<void> | undefined, | ||
| validator?: ValidatorObject | ((request: LiveQueryEventTrigger<T>) => any) | ||
| ): void; | ||
|
|
||
| export declare function sendEmail(data: { | ||
| from?: string; | ||
| to: string; | ||
| subject?: string; | ||
| text?: string; | ||
| html?: string; | ||
| }): Promise<void>; | ||
|
|
||
| export declare function httpRequest(options: HTTPOptions): Promise<HTTPResponse>; | ||
|
|
||
| // ============================================================================ | ||
| // JSDoc Documentation (for documentation generation) | ||
| // ============================================================================ | ||
|
||
|
|
||
| /** | ||
| * Defines a Cloud Function. | ||
| * | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove these type / style of comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done