Is it guaranteed that getSchema will be run before the execute for dynamic sync tables?

The documentation states that:

The function is first run when the user drags the sync table into the document, and then again before every sync.
Creating sync tables with dynamic schemas - Coda Pack SDK

However, the type of the context.sync.schema is possibly undefined (Sync.schema?: coda.ArraySchema<coda.Schema> | undefined) as passed into the execute async hook. Why is this the case? Is it safe to assert it as defined?

Related, is it safe to assume that before every invocation of the execute hook, the getSchema hook has always been ran with the same arguments passed in as the params (to avoid having to perform validation on those params twice, assuming that an error thrown in getSchema prevents execute from running)?

Hi @louca.developer - I think it’s marked as possibly undefined because a context object is also passed into listDynamicUrls and getSchema itself, and the schema isn’t yet defined at that point. By the time you get to execute it should always be defined.

I think it’s probably safe to assume that the parameters have been validated in getSchema before execute is run, because it’s how it works today and not likely to change. That said, a little extra validation never hurt, and it would probably be fairly straightforward to move the validation into a helper method that is called in each location.

2 Likes