Skip to content

Commit

Permalink
Adding sync state service to get latest row version based on given ro…
Browse files Browse the repository at this point in the history
…w ids (#3128)

* add row version service

* add row version service

* use syncStateService
  • Loading branch information
ebo-codaio authored Dec 11, 2024
1 parent e4fcbd5 commit 1a4d5b9
Show file tree
Hide file tree
Showing 21 changed files with 198 additions and 14 deletions.
38 changes: 38 additions & 0 deletions api_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,29 @@ export interface TemporaryBlobStorage {
): Promise<string>;
}


/**
* A service for retrieving the sync state in Coda Brain.
* @hidden
*
* TODO(ebo): unhide this
*/
export interface SyncStateService {
/**
* Retrieve the latest version of rows with the given row ids and returns a mapping of row ids to
* their latest version, e.g. {"Id-123": "1.0.0"}.
*
* If the row id is not found, it will not be included in the response.
*
* If the row version is not defined, it will be set to an empty string.
*
* @hidden
*
* TODO(ebo): unhide this
*/
getLatestRowVersions(rowIds: string[]): Promise<{[rowId: string]: string}>;
}

/**
* TODO(patrick): Unhide this
* @hidden
Expand Down Expand Up @@ -1062,6 +1085,21 @@ export interface SyncExecutionContext<
* Information about state of the current sync.
*/
readonly sync: Sync<ContinuationT, IncrementalContinuationT, IncrementalSyncContinuationT>;

/**
* A service for retrieving the sync state in Coda Brain.
* @hidden
*
* TODO(ebo): unhide this
*/
readonly syncStateService: SyncStateService;
}

/**
* A function to check if a given {@link ExecutionContext} is a {@link SyncExecutionContext}.
*/
export function isSyncExecutionContext(context: ExecutionContext): context is SyncExecutionContext {
return context.hasOwnProperty('sync') && context.hasOwnProperty('syncStateService');
}

/**
Expand Down
34 changes: 34 additions & 0 deletions dist/api_types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion dist/api_types.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions dist/bundle.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion dist/runtime/bootstrap/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion dist/runtime/bootstrap/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions dist/testing/execution.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion dist/testing/fetcher.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/testing/ivm_helper.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/testing/ivm_helper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions dist/testing/mocks.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion dist/testing/mocks.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions docs/reference/sdk/interfaces/testing.MockSyncExecutionContext.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export type {SyncExecutionContext} from './api_types';
export type {SyncFormulaResult} from './api';
export type {SyncTableDef} from './api';
export type {SyncTableOptions} from './api';
export type {SyncStateService} from './api_types';
export type {TemporaryBlobStorage} from './api_types';
export {Type} from './api_types';
export type {TypedPackFormula} from './api';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codahq/packs-sdk",
"version": "1.8.6-prerelease.2",
"version": "1.8.6-prerelease.3",
"license": "MIT",
"workspaces": [
"dev/eslint"
Expand Down
12 changes: 12 additions & 0 deletions runtime/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {Logger} from '../../api_types';
import type {PackFunctionResponse} from '../types';
import type {ParamDefs} from '../../api_types';
import type {ParamValues} from '../../api_types';
import type {SyncStateService} from '../../api_types';
import type {SyncUpdate} from '../../api';
import type {TemporaryBlobStorage} from '../../api_types';
import {ensureNever} from '../../helpers/ensure';
Expand Down Expand Up @@ -228,6 +229,7 @@ export async function injectExecutionContext({
context,
fetcher,
temporaryBlobStorage,
syncStateService,
logger,
endpoint,
invocationLocation,
Expand All @@ -242,13 +244,15 @@ export async function injectExecutionContext({
context: Context;
fetcher: Fetcher;
temporaryBlobStorage: TemporaryBlobStorage;
syncStateService: SyncStateService | undefined;
logger: Logger;
} & ExecutionContextPrimitives): Promise<void> {
ensureNever<keyof typeof rest>();
// Inject all of the primitives into a global we'll access when we execute the pack function.
const executionContextPrimitives = {
fetcher: {},
temporaryBlobStorage: {},
syncStateService: {},
logger: {},
endpoint,
invocationLocation,
Expand Down Expand Up @@ -286,6 +290,14 @@ export async function injectExecutionContext({
'executionContext.temporaryBlobStorage.storeUrl',
temporaryBlobStorage.storeUrl.bind(temporaryBlobStorage),
);

if (syncStateService) {
await injectAsyncFunction(
context,
'executionContext.syncStateService.getLatestRowVersions',
syncStateService.getLatestRowVersions.bind(syncStateService),
);
}
}

export async function registerBundle(
Expand Down
Loading

0 comments on commit 1a4d5b9

Please sign in to comment.