-
Notifications
You must be signed in to change notification settings - Fork 455
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
feat: add support for merging strategy into the runner sdk #3420
base: master
Are you sure you want to change the base?
Conversation
905b0c8
to
b1c0f9a
Compare
@@ -70,15 +70,18 @@ class ParserService { | |||
'triggerAction' | |||
]; | |||
|
|||
const disallowedActionCalls = ['batchSend', 'batchSave', 'batchDelete']; | |||
const disallowedActionCalls = ['batchSend', 'batchSave', 'batchDelete', 'batchUpdate']; |
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.
unrelated but batchUpdate
was missing
); | ||
usedCorrectly = false; | ||
} | ||
} |
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.
adding support for functions like setMergingStrategy
that take multiple models as argument
Success: { | ||
cursor?: string; | ||
}; | ||
Success: GetCursorSuccess; |
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.
moving the type to types
package so it can be used by the runner-sdk
@@ -8,7 +8,7 @@ const mergingStrategySchema = z.discriminatedUnion('strategy', [ | |||
}), | |||
z.object({ | |||
strategy: z.literal('ignore_if_modified_after_cursor'), | |||
cursor: z.string() | |||
cursor: z.string().optional() |
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.
forgot the scenario in my previous PR where there is not records yet (first sync or after emptying the cache). In this case there is no cursor yet
@@ -31,8 +32,7 @@ export const validateRecords = <E extends Endpoint<any>>() => | |||
environmentId: z.coerce.number().int().positive(), | |||
nangoConnectionId: z.coerce.number().int().positive(), | |||
syncId: z.string(), | |||
syncJobId: z.coerce.number().int().positive(), | |||
merging: mergingStrategySchema.default({ strategy: 'override' }) | |||
syncJobId: z.coerce.number().int().positive() |
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.
🤦
.orderBy([ | ||
{ column: 'updated_at', order: 'asc' }, | ||
{ column: 'id', order: 'asc' } | ||
]); |
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.
insertion order is different from cursor order since cursor is based on id which is a generated uuid. so we need to order based on cursor to get the latest cursor below
|
||
export type MergingStrategy = { strategy: 'override' } | { strategy: 'ignore_if_modified_after_cursor'; cursor: string }; | ||
|
||
export type CursorOffset = 'first' | 'last'; |
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.
moved to types
package
return value; | ||
}); | ||
} | ||
|
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.
not necessary anymore. Was used by the persistApi related code in NangoSync
runner-sdk class.
PersistApi related code now lives in its own file and the secret is not logged anymore
import type { Result } from '@nangohq/utils'; | ||
import type { CursorOffset, DeleteRecordsSuccess, GetCursorSuccess, MergingStrategy, PostRecordsSuccess, PutRecordsSuccess } from '@nangohq/types'; | ||
|
||
export interface PersistApi { |
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.
persist related code in runner-sdk NangoSync
was starting to get out of control. Moving all the persist related code to its own file
|
||
export interface DeleteRecordsSuccess { | ||
nextMerging: MergingStrategy; | ||
} |
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 could have a single one. wdyt?
b1c0f9a
to
b5c60d6
Compare
const callsReferencingModelsToCheck = callsBatchingRecords.concat('setMergingStrategy'); | ||
const proxyLines: number[] = []; | ||
const batchingRecordsLines: number[] = []; | ||
const setMergingStrategyLines: number[] = []; |
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.
see below. addressing footguns by raising compilation errors and enforce a couple of rules:
- setMergingStrategy must be called only once
- setMergingStrategy must be called before any batch operation
- setMergingStrategy must be called before any proxy/get/post/...
setMergingStrategy
runnder-sdk functionignore-if-modified-since
the function calls persist/cursor
and store it in a private variable. Its value is then forwarded when callingbatchSave/Update/Delete
which are now sending the next cursor. Again the updated cursor is forwarded to batchSave...