-
Notifications
You must be signed in to change notification settings - Fork 12
Allow specifying path to schema-sync folder with SCHEMA_SYNC_PATH #72
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,10 @@ import { ExportCollectionConfig, IExporterConfig, IGetItemsService } from './typ | |||||
| export class ExportManager { | ||||||
| protected exporters: IExporterConfig[] = []; | ||||||
|
|
||||||
| constructor(protected logger: ApiExtensionContext['logger']) {} | ||||||
| constructor( | ||||||
| protected path: string, | ||||||
| protected logger: ApiExtensionContext['logger'] | ||||||
| ) { } | ||||||
|
||||||
| ) { } | |
| ) {} |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,67 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { createHash } from 'crypto'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { readFile, readdir, writeFile } from 'fs/promises'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { resolve } from 'path'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export class ExportMeta { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public schemaDir: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor(schemaDir?: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.schemaDir = resolve(process.cwd(), schemaDir ?? 'schema-sync') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+6
to
+10
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public schemaDir: string; | |
| constructor(schemaDir?: string) { | |
| this.schemaDir = resolve(process.cwd(), schemaDir ?? 'schema-sync') | |
| } | |
| public schemaDir: string; | |
| constructor(schemaDir?: string) { | |
| this.schemaDir = resolve(process.cwd(), schemaDir ?? 'schema-sync') | |
| } |
Copilot
AI
Jan 11, 2026
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.
Inconsistent indentation detected. The code uses spaces instead of tabs. The entire class body (lines 20-61) should use tabs for indentation to match the project's style.
| public schemaDir: string; | |
| constructor(schemaDir?: string) { | |
| this.schemaDir = resolve(process.cwd(), schemaDir ?? 'schema-sync') | |
| } | |
| get dataDir() { | |
| return resolve(this.schemaDir, 'data'); | |
| } | |
| get hashFile() { | |
| return resolve(this.schemaDir, 'hash.txt'); | |
| } | |
| async updateExportMeta() { | |
| const hasher = createHash('sha256'); | |
| const files = await readdir(this.dataDir); | |
| for (const file of files) { | |
| if (file.endsWith('.json')) { | |
| const json = await readFile(`${this.dataDir}/${file}`, { encoding: 'utf8' }); | |
| hasher.update(json); | |
| } | |
| } | |
| const hash = hasher.digest('hex'); | |
| const { hash: previousHash } = await this.getExportMeta() || {}; | |
| // Only update hash file if it has changed | |
| if (hash === previousHash) return false; | |
| const ts = utcTS(); | |
| const txt = hash + '@' + ts; | |
| await writeFile(this.hashFile, txt); | |
| return { | |
| hash, | |
| ts, | |
| }; | |
| } | |
| async getExportMeta() { | |
| try { | |
| const content = await readFile(this.hashFile, { encoding: 'utf8' }); | |
| const [hash, ts] = content.split('@'); | |
| if (hash && ts && new Date(ts).toString() !== 'Invalid Date') { | |
| return { | |
| hash, | |
| ts, | |
| }; | |
| } | |
| } catch { | |
| // ignore | |
| } | |
| return null; | |
| } | |
| public schemaDir: string; | |
| constructor(schemaDir?: string) { | |
| this.schemaDir = resolve(process.cwd(), schemaDir ?? 'schema-sync') | |
| } | |
| get dataDir() { | |
| return resolve(this.schemaDir, 'data'); | |
| } | |
| get hashFile() { | |
| return resolve(this.schemaDir, 'hash.txt'); | |
| } | |
| async updateExportMeta() { | |
| const hasher = createHash('sha256'); | |
| const files = await readdir(this.dataDir); | |
| for (const file of files) { | |
| if (file.endsWith('.json')) { | |
| const json = await readFile(`${this.dataDir}/${file}`, { encoding: 'utf8' }); | |
| hasher.update(json); | |
| } | |
| } | |
| const hash = hasher.digest('hex'); | |
| const { hash: previousHash } = await this.getExportMeta() || {}; | |
| // Only update hash file if it has changed | |
| if (hash === previousHash) return false; | |
| const ts = utcTS(); | |
| const txt = hash + '@' + ts; | |
| await writeFile(this.hashFile, txt); | |
| return { | |
| hash, | |
| ts, | |
| }; | |
| } | |
| async getExportMeta() { | |
| try { | |
| const content = await readFile(this.hashFile, { encoding: 'utf8' }); | |
| const [hash, ts] = content.split('@'); | |
| if (hash && ts && new Date(ts).toString() !== 'Invalid Date') { | |
| return { | |
| hash, | |
| ts, | |
| }; | |
| } | |
| } catch { | |
| // ignore | |
| } | |
| return null; | |
| } |
Copilot
AI
Jan 11, 2026
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.
Inconsistent indentation detected. The function uses spaces instead of tabs. Line 66 should use tabs for indentation to match the project's style.
| return isoTimestamp.replace('T', ' ').replace(/\.\d*Z/, ''); | |
| return isoTimestamp.replace('T', ' ').replace(/\.\d*Z/, ''); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -41,6 +41,9 @@ export type CollectionExporterOptions = { | |||||
| // Specify additional query options to filter, sort and limit the exported items | ||||||
| query?: Pick<Query, 'filter' | 'sort' | 'limit'>; | ||||||
|
|
||||||
| // Path to the export folder | ||||||
| path?: string, | ||||||
|
||||||
| path?: string, | |
| path?: string; |
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.
The parameter should accept
string | undefinedinstead of juststring. The valueenv.SCHEMA_SYNC_PATHbeing passed can be undefined when the environment variable is not set, which should be a valid scenario based on the documentation showing the default value.