-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
170 additions
and
117 deletions.
There are no files selected for viewing
This file contains 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 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 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,2 @@ | ||
export const amends: unique symbol = Symbol('amends'); | ||
export const amendedBy: unique symbol = Symbol('amendedBy'); |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains 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,2 @@ | ||
export * from './EntitySyncOperation'; | ||
export * from './IdSyncOperation'; |
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
export * from './GSheets2Git'; | ||
export * from './words'; |
This file contains 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,77 @@ | ||
import type { MultilingualSynsetRepository } from '@interslavic/database-engine-fs'; | ||
|
||
import type { WordsDTO, WordsSheet } from '../../google'; | ||
import { toMultiSynset } from '../../google'; | ||
import { amends, amendedBy } from '../../symbols'; | ||
import { IdSyncOperation } from '../core'; | ||
|
||
export type GSheets2GitOptions = { | ||
readonly beta: boolean; | ||
readonly fs: MultilingualSynsetRepository; | ||
readonly gsheets: WordsSheet; | ||
}; | ||
|
||
export class GSheets2Git extends IdSyncOperation<number> { | ||
private _gmap?: Map<number, WordsDTO>; | ||
private readonly fs: MultilingualSynsetRepository; | ||
private readonly gsheets: WordsSheet; | ||
private readonly beta: boolean; | ||
|
||
constructor(options: GSheets2GitOptions) { | ||
super(); | ||
|
||
this.fs = options.fs; | ||
this.gsheets = options.gsheets; | ||
this.beta = options.beta; | ||
} | ||
|
||
protected async delete(id: number): Promise<void> { | ||
// TODO: think about the future when lemma IDs and synset IDs diverge | ||
await this.fs.deleteById(id); | ||
} | ||
|
||
protected async getAfterIds(): Promise<number[]> { | ||
return this._grecords().then((r) => [...r.keys()]); | ||
} | ||
|
||
protected async getBeforeIds(): Promise<number[]> { | ||
return this.fs.keys(); | ||
} | ||
|
||
protected async insert(id: number): Promise<void> { | ||
const dto = await this._grecords().then((r) => r.get(id)); | ||
const multisynset = toMultiSynset(dto!); | ||
await this.fs.insert(multisynset); | ||
} | ||
|
||
protected async update(id: number): Promise<void> { | ||
const dto = await this._grecords().then((r) => r.get(id)); | ||
const multisynset = toMultiSynset(dto!); | ||
await this.fs.upsert(multisynset); | ||
} | ||
|
||
private async _grecords(): Promise<Map<number, WordsDTO>> { | ||
if (!this._gmap) { | ||
const dtos = await this.gsheets.getValues(); | ||
const stable = dtos.filter((dto: WordsDTO) => dto.id > 0); | ||
const grecords = (this._gmap = new Map<number, WordsDTO>( | ||
stable.map((dto: WordsDTO) => [Number(dto.id), dto]), | ||
)); | ||
|
||
if (this.beta) { | ||
const beta = dtos.filter((dto: WordsDTO) => dto.id < 0); | ||
for (const record of beta) { | ||
const id = (record.id = -record.id); | ||
const base = grecords.get(id) as WordsDTO; | ||
if (base) { | ||
base[amendedBy] = record; | ||
record[amends] = base; | ||
} | ||
grecords.set(id, record); | ||
} | ||
} | ||
} | ||
|
||
return this._gmap; | ||
} | ||
} |
This file contains 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 @@ | ||
export * from './GSheets2Git'; |
This file contains 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 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 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 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 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,2 @@ | ||
export { symbols as ArrayMapperSymbols } from './createArrayMapperClass'; | ||
export type { ArrayMapped } from './createArrayMapperClass'; |