-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: Add SDK Adapter #10256
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
dblythy
wants to merge
10
commits into
parse-community:alpha
Choose a base branch
from
dblythy:feature/sdk-adapter
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.
Open
feat: Add SDK Adapter #10256
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eb653a6
feat: Add SDK adapter
dblythy cc7d8b2
add triggerStore
dblythy 0c6b64f
Merge upstream changes, resolve conflict by keeping Parse.Cloud.js de…
dblythy eee657a
coderabbit comments
dblythy 3363158
Update triggers.js
dblythy 6cb61ce
resolve coderabit comments
dblythy de0d965
test: Add e2e tests for TriggerStore, validator cleanup, and _PushSta…
dblythy d6b4443
Merge branch 'alpha' into feature/sdk-adapter
dblythy a7aafe9
fix: Remove unused import and isolate liveQuery handler errors
dblythy 94077a7
Update TriggerStore.ts
dblythy 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
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
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 |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /** | ||
| * CloudCodeRegistrar defines the contract for registering cloud code hooks. | ||
| * | ||
| * Parse Server creates one during startup. BYO SDKs implement this to | ||
| * register their own hooks without depending on parse/node. | ||
| * | ||
| * Usage from any JS SDK: | ||
| * | ||
| * import { CloudCodeRegistrar, TriggerType } from 'parse-server/cloud'; | ||
| * const registrar = CloudCodeRegistrar.getInstance('myAppId'); | ||
| * registrar.define(HookType.function, 'hello', handler); | ||
| * registrar.defineTrigger(TriggerType.beforeSave, 'GameScore', handler); | ||
| */ | ||
|
|
||
| import type { TriggerHandlerMap, HookHandlerMap } from './types'; | ||
|
|
||
| export const TriggerType = { | ||
| beforeSave: 'beforeSave', | ||
| afterSave: 'afterSave', | ||
| beforeDelete: 'beforeDelete', | ||
| afterDelete: 'afterDelete', | ||
| beforeFind: 'beforeFind', | ||
| afterFind: 'afterFind', | ||
| beforeLogin: 'beforeLogin', | ||
| afterLogin: 'afterLogin', | ||
| afterLogout: 'afterLogout', | ||
| beforePasswordResetRequest: 'beforePasswordResetRequest', | ||
| beforeConnect: 'beforeConnect', | ||
| beforeSubscribe: 'beforeSubscribe', | ||
| afterEvent: 'afterEvent', | ||
| } as const; | ||
|
|
||
| export type TriggerType = typeof TriggerType[keyof typeof TriggerType]; | ||
|
|
||
| export const HookType = { | ||
| function: 'function', | ||
| job: 'job', | ||
| } as const; | ||
|
|
||
| export type HookType = typeof HookType[keyof typeof HookType]; | ||
|
|
||
| export abstract class CloudCodeRegistrar { | ||
| private static _instances: Map<string, CloudCodeRegistrar> = new Map(); | ||
|
|
||
| abstract get appId(): string; | ||
|
|
||
| abstract initialize(config: RegistrarConfig): void; | ||
|
|
||
| /** | ||
| * Register a cloud function or job. | ||
| * | ||
| * The handler type is derived from the `HookType` constant: | ||
| * - `HookType.function` → `FunctionHandler<P>` | ||
| * - `HookType.job` → `JobHandler<P>` | ||
| */ | ||
| abstract define< | ||
| K extends HookType, | ||
| P extends Record<string, unknown> = Record<string, unknown>, | ||
| >(type: K, name: string, handler: HookHandlerMap<P>[K], validator?: unknown): void; | ||
|
|
||
| /** | ||
| * Register a trigger on a class (beforeSave, afterDelete, etc.), | ||
| * a connect trigger (beforeConnect with className '@Connect'), | ||
| * or a live query handler (afterEvent, beforeSubscribe, etc.). | ||
| * | ||
| * The handler type is derived from the `TriggerType` constant: | ||
| * - `TriggerType.beforeSave` → `ObjectTriggerHandler<T>` | ||
| * - `TriggerType.beforeFind` → `QueryTriggerHandler` | ||
| * - `TriggerType.afterFind` → `AfterFindHandler<T>` | ||
| * - etc. | ||
| */ | ||
| abstract defineTrigger< | ||
| K extends TriggerType, | ||
| T extends Record<string, unknown> = Record<string, unknown>, | ||
| >(type: K, className: string, handler: TriggerHandlerMap<T>[K], validator?: unknown): void; | ||
|
|
||
| /** | ||
| * Remove all registered hooks. | ||
| */ | ||
| abstract removeAllHooks(): void; | ||
|
|
||
| static getInstance(appId: string): CloudCodeRegistrar { | ||
| const instance = CloudCodeRegistrar._instances.get(appId); | ||
| if (!instance) { | ||
| throw new Error(`CloudCodeRegistrar not found for appId "${appId}".`); | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
| static setInstance(registrar: CloudCodeRegistrar): void { | ||
| CloudCodeRegistrar._instances.set(registrar.appId, registrar); | ||
| } | ||
|
|
||
| static removeInstance(appId: string): void { | ||
| CloudCodeRegistrar._instances.delete(appId); | ||
| } | ||
|
|
||
| static clearInstances(): void { | ||
| CloudCodeRegistrar._instances.clear(); | ||
| } | ||
| } | ||
|
|
||
| export interface RegistrarConfig { | ||
| appId: string; | ||
| masterKey: string; | ||
| javascriptKey?: string; | ||
| serverURL: string; | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.