Skip to content

Commit

Permalink
Merge pull request #199 from runlightyear/incremental-sync
Browse files Browse the repository at this point in the history
Incremental sync
  • Loading branch information
ebouck authored Dec 9, 2024
2 parents 729402e + c6912a1 commit 8e015b3
Show file tree
Hide file tree
Showing 36 changed files with 315 additions and 47 deletions.
7 changes: 7 additions & 0 deletions packages/@runlightyear/airtable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @runlightyear/airtable

## 1.2.12

### Patch Changes

- Updated dependencies [494972892]
- @runlightyear/lightyear@1.17.0

## 1.2.11

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/airtable/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/airtable",
"version": "1.2.11",
"version": "1.2.12",
"publishConfig": {
"access": "public"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/@runlightyear/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @runlightyear/cli

## 1.6.1

### Patch Changes

- Updated dependencies [494972892]
- @runlightyear/lightyear@1.17.0

## 1.6.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/cli",
"version": "1.6.0",
"version": "1.6.1",
"publishConfig": {
"access": "public"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/@runlightyear/gcal/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @runlightyear/gcal

## 0.11.12

### Patch Changes

- Updated dependencies [494972892]
- @runlightyear/lightyear@1.17.0

## 0.11.11

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/gcal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/gcal",
"version": "0.11.11",
"version": "0.11.12",
"publishConfig": {
"access": "public"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/@runlightyear/github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @runlightyear/github

## 1.3.12

### Patch Changes

- Updated dependencies [494972892]
- @runlightyear/lightyear@1.17.0

## 1.3.11

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/github/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/github",
"version": "1.3.11",
"version": "1.3.12",
"publishConfig": {
"access": "public"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/@runlightyear/gmail/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @runlightyear/gmail

## 0.6.13

### Patch Changes

- Updated dependencies [494972892]
- @runlightyear/lightyear@1.17.0

## 0.6.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/gmail/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/gmail",
"version": "0.6.12",
"version": "0.6.13",
"publishConfig": {
"access": "public"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/@runlightyear/gsheets/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @runlightyear/gsheets

## 0.8.12

### Patch Changes

- Updated dependencies [494972892]
- @runlightyear/lightyear@1.17.0

## 0.8.11

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/gsheets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/gsheets",
"version": "0.8.11",
"version": "0.8.12",
"publishConfig": {
"access": "public"
},
Expand Down
11 changes: 11 additions & 0 deletions packages/@runlightyear/hubspot/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @runlightyear/hubspot

## 0.12.0

### Minor Changes

- 086243822: Throw an error if there is an attempt to create a user/owner during sync

### Patch Changes

- Updated dependencies [494972892]
- @runlightyear/lightyear@1.17.0

## 0.11.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/hubspot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/hubspot",
"version": "0.11.0",
"version": "0.12.0",
"publishConfig": {
"access": "public"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,22 @@ export class UserSynchronizer extends ModelSynchronizer<any> {

return this.mapToObject(response.data);
}

async create(object: any): Promise<string> {
throw new Error(
"HubSpot does not support creating new users/owners from the API"
);
}

async update(object: any) {
throw new Error(
"HubSpot does not support updating users/owners from the API"
);
}

async delete(id: string) {
throw new Error(
"HubSpot does not support deleting users/owners from the API"
);
}
}
6 changes: 6 additions & 0 deletions packages/@runlightyear/lightyear/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @runlightyear/lightyear

## 1.17.0

### Minor Changes

- 494972892: Model synchronizer uses updated sync api

## 1.16.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/lightyear/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/lightyear",
"version": "1.16.0",
"version": "1.17.0",
"publishConfig": {
"access": "public"
},
Expand Down
137 changes: 137 additions & 0 deletions packages/@runlightyear/lightyear/src/base/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,38 @@ export async function getDelta(props: GetDeltaProps) {
}
}

export interface RetrieveDeltaProps {
collectionName: string;
syncId: string;
modelName?: string;
limit?: number;
}

export async function retrieveDelta(props: RetrieveDeltaProps) {
const { collectionName, syncId, modelName, limit } = props;

const envName = getEnvName();

const response = await baseRequest({
method: "POST",
uri: `/api/v1/envs/${envName}/collections/${collectionName}/delta`,
data: {
syncId,
modelName,
limit,
},
});

if (response.ok) {
const json = await response.json();
return {
changes: json.changes,
};
} else {
throw new Error("Unable to get delta");
}
}

export interface StartSyncProps {
collection: string;
app: string | null;
Expand Down Expand Up @@ -333,6 +365,111 @@ export async function upsertObjectBatch(props: UpsertObjectBatchProps) {
return response;
}

export interface ConfirmChangeProps {
collectionName: string;
modelName: string;
syncId: string;
changeId: string;
localObjectId: string;
localUpdatedAt: string | null;
}

export async function confirmObject(props: ConfirmChangeProps) {
const {
collectionName,
modelName,
syncId,
changeId,
localObjectId,
localUpdatedAt,
} = props;

const envName = getEnvName();

const response = await baseRequest({
method: "POST",
uri: `/api/v1/envs/${envName}/collections/${collectionName}/models/${modelName}/objects/confirm`,
data: {
syncId,
changeId,
localObjectId,
localUpdatedAt,
},
});

console.info(
"Confirm",
collectionName,
modelName,
syncId,
changeId,
localObjectId,
localUpdatedAt,
response.status,
response.statusText
);

return response;
}

export interface ConfirmChangeBatchProps {
collection: string;
syncId: string;
model: string;
app: string | undefined;
customApp: string | undefined;
managedUserId?: string | null;
objects: Array<{
objectId?: string;
localObjectId: string;
localUpdatedAt: string | null;
data: unknown;
}>;
overwrite?: boolean;
async?: boolean;
}

export async function confirmObjectBatch(props: ConfirmChangeBatchProps) {
const {
collection,
syncId,
model,
app,
customApp,
managedUserId,
objects,
overwrite,
async,
} = props;

const envName = getEnvName();

const response = await baseRequest({
method: "POST",
uri: `/api/v1/envs/${envName}/collections/${collection}/models/${model}/objects/confirm/batch`,
data: {
syncId,
appName: app,
customAppName: customApp,
managedUserId,
objects,
overwrite,
async,
},
});

console.info(
"Confirm",
collection,
model,
objects.length,
response.status,
response.statusText
);

return response;
}

export interface DeleteObjectProps {
collection: string;
model: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/@runlightyear/lightyear/src/base/syncAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ export function defineSyncAction(props: DefineSyncActionProps) {
customApp: props.customApp ?? null,
managedUserExternalId: runProps.managedUser?.externalId ?? null,
});
console.info("Started sync");
console.debug(startSyncResponse);
const { sync, prevFullSync } = startSyncResponse;
console.info(`Started sync ${sync.id}`);
console.debug(startSyncResponse);

let syncType: "FULL" | "INCREMENTAL" = "INCREMENTAL";
if (!prevFullSync) {
Expand Down
Loading

0 comments on commit 8e015b3

Please sign in to comment.