Skip to content

Commit c138c58

Browse files
committed
Add filename to PnP instance
1 parent 90b551e commit c138c58

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

src/components/pnp/pnp.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
import { WorkBook } from '~/common/xlsx.util';
2-
import { type Downloadable } from '../file/dto';
2+
import { type Downloadable, type FileVersion } from '../file/dto';
33
import { PlanningSheet } from './planning-sheet';
44
import { ProgressSheet } from './progress-sheet';
55

66
const ParsedPnp = Symbol('Parsed PnP');
77

88
export class Pnp {
9-
constructor(protected workbook: WorkBook) {}
9+
constructor(protected workbook: WorkBook, protected fileName?: string) {}
1010

1111
/**
1212
* Create PnP from Downloadable.
1313
* Will reuse an existing instance from a previous call.
1414
*/
15-
static async fromDownloadable(obj: Downloadable<unknown>) {
15+
static async fromDownloadable(obj: Downloadable<FileVersion>) {
1616
const promise = obj.download() as Promise<Buffer> & { [ParsedPnp]?: Pnp };
1717
if (!promise[ParsedPnp]) {
18-
promise[ParsedPnp] = Pnp.fromBuffer(await promise);
18+
promise[ParsedPnp] = Pnp.fromBuffer(await promise, obj.name);
1919
}
2020
return promise[ParsedPnp]!;
2121
}
2222

23-
static fromBuffer(buffer: Buffer) {
23+
static fromBuffer(buffer: Buffer, name?: string) {
2424
const book = WorkBook.fromBuffer(buffer);
2525
PlanningSheet.register(book);
2626
ProgressSheet.register(book);
27-
return new Pnp(book);
27+
return new Pnp(book, name);
2828
}
2929

3030
get planning() {

src/components/product-progress/step-progress-extractor.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { entries } from '@seedcompany/common';
33
import { assert } from 'ts-essentials';
44
import type { MergeExclusive } from 'type-fest';
55
import type { Cell, Column, Row } from '~/common/xlsx.util';
6-
import type { Downloadable } from '../file/dto';
6+
import type { Downloadable, FileVersion } from '../file/dto';
77
import {
88
extractScripture,
99
findStepColumns,
@@ -45,7 +45,7 @@ type ExtractedRow = MergeExclusive<
4545
@Injectable()
4646
export class StepProgressExtractor {
4747
async extract(
48-
file: Downloadable<unknown>,
48+
file: Downloadable<FileVersion>,
4949
result: PnpProgressExtractionResult,
5050
) {
5151
const pnp = await Pnp.fromDownloadable(file);

src/components/product/product.extractor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { assert } from 'ts-essentials';
55
import { type MergeExclusive } from 'type-fest';
66
import { type CalendarDate, type DateInterval } from '~/common';
77
import { type Cell, type Column, type Row } from '~/common/xlsx.util';
8-
import { type Downloadable } from '../file/dto';
8+
import { type Downloadable, type FileVersion } from '../file/dto';
99
import {
1010
extractScripture,
1111
findStepColumns,
@@ -31,7 +31,7 @@ import { type ProductStep, type ProductStep as Step } from './dto';
3131
@Injectable()
3232
export class ProductExtractor {
3333
async extract(
34-
file: Downloadable<unknown>,
34+
file: Downloadable<FileVersion>,
3535
engagementRange: DateInterval | null,
3636
availableSteps: readonly ProductStep[],
3737
result: PnpPlanningExtractionResult,

src/components/progress-summary/progress-summary.extractor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
fiscalYear,
99
} from '~/common';
1010
import { type Column, type Row } from '~/common/xlsx.util';
11-
import { type Downloadable } from '../file/dto';
11+
import { type Downloadable, type FileVersion } from '../file/dto';
1212
import { Pnp, type ProgressSheet } from '../pnp';
1313
import {
1414
PnpProblemType,
@@ -19,7 +19,7 @@ import { type ProgressSummary as Progress } from './dto';
1919
@Injectable()
2020
export class ProgressSummaryExtractor {
2121
async extract(
22-
file: Downloadable<unknown>,
22+
file: Downloadable<FileVersion>,
2323
date: CalendarDate,
2424
result: PnpProgressExtractionResult,
2525
) {

src/repl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as fs from 'fs/promises';
66
// eslint-disable-next-line no-restricted-imports
77
import * as lodash from 'lodash';
88
import { DateTime, Duration, Interval } from 'luxon';
9+
import { basename } from 'node:path';
910
import { CalendarDate, DateInterval } from '~/common';
1011
import * as common from '~/common';
1112
import './polyfills';
@@ -46,7 +47,8 @@ runRepl({
4647
session,
4748
sessionFor: session.withRoles,
4849
Resources,
49-
loadPnp: (filepath: string) => Pnp.fromBuffer(readFileSync(filepath)),
50+
loadPnp: (filepath: string) =>
51+
Pnp.fromBuffer(readFileSync(filepath), basename(filepath)),
5052
};
5153
},
5254
});

0 commit comments

Comments
 (0)