Skip to content
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

build(deps-dev): bump @linzjs/style from 4.2.0 to 5.1.0 #1349

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module.exports = {
...require('@linzjs/style/.eslintrc.cjs'),
rules: {
'@typescript-eslint/require-await': 0,
},
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"license": "ISC",
"description": "",
"devDependencies": {
"@linzjs/style": "^4.0.0",
"@linzjs/style": "^5.2.0",
"lerna": "^8.0.0"
},
"workspaces": {
Expand Down
2 changes: 1 addition & 1 deletion packages/__tests__/e2e.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async function testPrefix(prefix, fs) {
});

describe('read', () => {
it('should read a file', async (t) => {
it('should read a file', async () => {
const file = await fsa.read(new URL(TestFiles[0].path, prefix));
assert.equal(file.toString(), TestFiles[0].buffer.toString());
});
Expand Down
10 changes: 5 additions & 5 deletions packages/fs-aws/src/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export function isPromise<T>(t: AwsCredentialProvider | Promise<T>): t is Promis

/** Basic JSON validation of the configuration */
export function validateConfig(cfg: AwsCredentialProvider, loc: URL): AwsCredentialProvider {
if (cfg == null) throw new Error('Unknown configuration from:' + loc);
if (cfg.v !== 2) throw new Error('Configuration is not v2 from:' + loc);
if (!Array.isArray(cfg.prefixes)) throw new Error('Configuration prefixes invalid from:' + loc);
if (cfg == null) throw new Error('Unknown configuration from:' + loc.href);
if (cfg.v !== 2) throw new Error('Configuration is not v2 from:' + loc.href);
if (!Array.isArray(cfg.prefixes)) throw new Error('Configuration prefixes invalid from:' + loc.href);

return cfg;
}
Expand All @@ -33,7 +33,7 @@ export class FsConfigFetcher {
if (this._config != null) return this._config;
this._config = this.fs
.read(this.loc)
.then((f) => JSON.parse(f.toString()))
.then((f) => JSON.parse(f.toString()) as AwsCredentialProvider)
.then((cfg) => validateConfig(cfg, this.loc));

return this._config;
Expand All @@ -53,7 +53,7 @@ let PublicClient: S3Client | undefined;
/** Creating a public s3 client is somewhat hard, where the signing method needs to be overriden */
export function getPublicS3(): S3Client {
if (PublicClient) return PublicClient;
PublicClient = new S3Client({ signer: { sign: async (req) => req } });
PublicClient = new S3Client({ signer: { sign: (req) => Promise.resolve(req) } });
return PublicClient;
}

Expand Down
18 changes: 9 additions & 9 deletions packages/fs-aws/src/fs.s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { SourceAwsS3 } from '@chunkd/source-aws';

import { AwsS3CredentialProvider } from './credentials.js';

function isReadable(r: any): r is Readable {
return r != null && typeof r['read'] === 'function';
function isReadable(r: unknown): r is Readable {
return r != null && typeof (r as { read: unknown })['read'] === 'function';
}

export function toFsError(e: unknown, msg: string, url: URL, action: FileSystemAction, system: FileSystem): FsError {
Expand Down Expand Up @@ -127,7 +127,7 @@ export class FsAwsS3 implements FileSystem {
ContinuationToken = res.NextContinuationToken;
}
} catch (e) {
const ce = toFsError(e, `Failed to list: "${loc}"`, loc, 'list', this);
const ce = toFsError(e, `Failed to list: "${loc.href}"`, loc, 'list', this);

if (this.credentials != null && ce.code === 403) {
const newFs = await this.credentials.find(loc);
Expand All @@ -152,7 +152,7 @@ export class FsAwsS3 implements FileSystem {

return Buffer.from(await new Response(res.Body as BodyInit).arrayBuffer());
} catch (e) {
const ce = toFsError(e, `Failed to read: "${loc}"`, loc, 'read', this);
const ce = toFsError(e, `Failed to read: "${loc.href}"`, loc, 'read', this);
if (this.credentials != null && ce.code === 403) {
const newFs = await this.credentials.find(loc);
if (newFs) return newFs.read(loc);
Expand Down Expand Up @@ -183,7 +183,7 @@ export class FsAwsS3 implements FileSystem {
// Suffix was added so cleanup the file
if (this.writeTestSuffix !== '') await this.delete(loc);
} catch (e) {
const ce = toFsError(e, `Failed to write to "${loc}"`, loc, 'write', this);
const ce = toFsError(e, `Failed to write to "${loc.href}"`, loc, 'write', this);
if (ce.code === 403) {
const newFs = await this.credentials.find(testPath);
if (newFs) return newFs;
Expand Down Expand Up @@ -220,7 +220,7 @@ export class FsAwsS3 implements FileSystem {
},
}).done();
} catch (e) {
const ce = toFsError(e, `Failed to write: "${loc}"`, loc, 'write', this);
const ce = toFsError(e, `Failed to write: "${loc.href}"`, loc, 'write', this);
if (this.credentials != null && ce.code === 403) {
const newFs = await this.credentials.find(loc);
if (newFs) return newFs.write(loc, buf, ctx);
Expand All @@ -240,7 +240,7 @@ export class FsAwsS3 implements FileSystem {
);
return;
} catch (e) {
const ce = toFsError(e, `Failed to delete: "${loc}"`, loc, 'delete', this);
const ce = toFsError(e, `Failed to delete: "${loc.href}"`, loc, 'delete', this);
if (ce.code === 404) return;
if (this.credentials != null && ce.code === 403) {
const newFs = await this.credentials.find(loc);
Expand Down Expand Up @@ -268,7 +268,7 @@ export class FsAwsS3 implements FileSystem {
if (r.Body) (r.Body as Readable).pipe(pt);
else pt.end();
})
.catch((e) => pt.emit('error', toFsError(e, `Failed to readStream: ${loc}`, loc, 'readStream', this)));
.catch((e) => pt.emit('error', toFsError(e, `Failed to readStream: ${loc.href}`, loc, 'readStream', this)));
return pt;
}

Expand All @@ -293,7 +293,7 @@ export class FsAwsS3 implements FileSystem {
} catch (e) {
if (isRecord(e) && e.code === 'NotFound') return null;

const ce = toFsError(e, `Failed to head: ${loc}`, loc, 'head', this);
const ce = toFsError(e, `Failed to head: ${loc.href}`, loc, 'head', this);
if (ce.code === 404) return null;

if (this.credentials != null && ce.code === 403) {
Expand Down
11 changes: 6 additions & 5 deletions packages/fs/src/__test__/fs.abstraction.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { FsFile } from '../systems/file.js';
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { FileSystemAbstraction } from '../file.system.abstraction.js';
import { describe, it } from 'node:test';
import { gzipSync } from 'node:zlib';

import { FileSystemAbstraction } from '../file.system.abstraction.js';
import { FsFile } from '../systems/file.js';
import { FsMemory } from '../systems/memory.js';

export class FakeSystem extends FsFile {
Expand Down Expand Up @@ -91,7 +92,7 @@ describe('FileSystemAbstraction', () => {
assert.equal(fsa.systems[0].system, fakeB);
});

it('should stream files between systems', (t) => {
it('should stream files between systems', async (t) => {
const fakeA = new FakeSystem('fake');
const fakeB = new FakeSystem('fakeSpecific');
const fsa = new FileSystemAbstraction();
Expand All @@ -102,7 +103,7 @@ describe('FileSystemAbstraction', () => {
fsa.register('fake-a://', fakeA);
fsa.register('fake-b://', fakeB);

fsa.write(new URL('fake-b://bar.js'), fsa.readStream(new URL('fake-a://foo.js')));
await fsa.write(new URL('fake-b://bar.js'), fsa.readStream(new URL('fake-a://foo.js')));

assert.equal(streamStub.mock.callCount(), 1);
assert.equal(writeStub.mock.callCount(), 1);
Expand Down
2 changes: 2 additions & 0 deletions packages/fs/src/__test__/generator.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import assert from 'node:assert';
import { describe, it } from 'node:test';

import { toArray, toFirst } from '../generator.js';

// eslint-disable-next-line @typescript-eslint/require-await
async function* generator(iMax = 10): AsyncGenerator<number> {
for (let i = 0; i < iMax; i++) yield i;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fs/src/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FileSystemAction, FileSystem } from './file.system.js';
import { FileSystem, FileSystemAction } from './file.system.js';

export class FsError extends Error {
/** Status code for the error eg 403 - Forbidden vs 404 Not found */
Expand Down
15 changes: 8 additions & 7 deletions packages/fs/src/file.system.abstraction.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Source, SourceMiddleware, SourceView } from '@chunkd/source';
import type { Readable } from 'node:stream';
import { pathToFileURL } from 'node:url';
import { gunzip } from 'node:zlib';
import { promisify } from 'node:util';
import { gunzip } from 'node:zlib';

import { Source, SourceMiddleware, SourceView } from '@chunkd/source';

import { FileInfo, FileSystem, FileWriteTypes, ListOptions, WriteOptions } from './file.system.js';
import { Flag } from './flags.js';
import { FsFile } from './systems/file.js';
import { toArray } from './generator.js';
import { FsFile } from './systems/file.js';

const gunzipProm = promisify(gunzip);

Expand Down Expand Up @@ -93,9 +95,9 @@ export class FileSystemAbstraction implements FileSystem {
const obj = await this.read(loc);
if (loc.pathname.endsWith('.gz') || isGzip(obj)) {
const data = await gunzipProm(obj);
return JSON.parse(data.toString());
return JSON.parse(data.toString()) as T;
}
return JSON.parse(obj.toString());
return JSON.parse(obj.toString()) as T;
}

/**
Expand Down Expand Up @@ -193,7 +195,6 @@ export class FileSystemAbstraction implements FileSystem {

/** Find the filesystem that would be used for a given path */
get(loc: URL, flag: Flag): FileSystem {
if (loc.href == null) throw new Error(`Invalid URL: ${loc}`);
this.sortSystems();
const fileHref = loc.href;
for (const cfg of this.systems) {
Expand All @@ -204,7 +205,7 @@ export class FileSystemAbstraction implements FileSystem {
}
}

throw new Error(`Unable to find file system for location: ${loc}`);
throw new Error(`Unable to find file system for location: ${loc.href}`);
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/fs/src/file.system.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Source } from '@chunkd/source';
import { Readable } from 'node:stream';

import { Source } from '@chunkd/source';

export type FileWriteTypes = Buffer | Readable | string;

export interface FileInfo {
Expand Down
2 changes: 1 addition & 1 deletion packages/fs/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export async function toArray<T>(generator: AsyncGenerator<T>): Promise<T[]> {
/** Grab the first value from a async generator */
export async function toFirst<T>(generator: AsyncGenerator<T>): Promise<T> {
const first = await generator.next();
return first.value;
return first.value as T;
}
10 changes: 5 additions & 5 deletions packages/fs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export { FileSystem, ListOptions, WriteOptions, FileInfo, FileWriteTypes, FileSystemAction } from './file.system.js';
export { FsError } from './error.js';
export { fsa } from './file.system.abstraction.js';
export { FileInfo, FileSystem, FileSystemAction, FileWriteTypes, ListOptions, WriteOptions } from './file.system.js';
export { Flag, FlagRead, FlagReadWrite } from './flags.js';
export { toArray, toFirst } from './generator.js';
export { FsMemory } from './systems/memory.js';
export { FsFile } from './systems/file.js';
export { FsHttp } from './systems/http.js';
export { FsError } from './error.js';
export { FileSystemProvider } from './provider.js';
export { FsFile } from './systems/file.js';
export { isRecord } from './systems/file.js';
export { FsHttp } from './systems/http.js';
export { FsMemory } from './systems/memory.js';
7 changes: 4 additions & 3 deletions packages/fs/src/systems/__test__/file.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import assert from 'node:assert';
import { describe, it } from 'node:test';
import { FsFile } from '../file.js';

import { FsError } from '../../error.js';
import { FsFile } from '../file.js';

async function toArray<T>(generator: AsyncGenerator<T>): Promise<T[]> {
const output: T[] = [];
Expand Down Expand Up @@ -64,8 +65,8 @@ describe('LocalFileSystem', () => {
fs.readStream(new URL('missing-file-goes-here.txt', import.meta.url)),
);
assert.fail('should throw');
} catch (e: any) {
assert.equal(e.code, 404);
} catch (e: unknown) {
assert.equal((e as { code: number }).code, 404);
assert.equal(String(e), 'Error: Failed to write: ' + new URL('fs.test', import.meta.url).href);
}
});
Expand Down
5 changes: 3 additions & 2 deletions packages/fs/src/systems/__test__/memory.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import assert from 'node:assert';
import { describe, it, afterEach } from 'node:test';
import { FsMemory } from '../memory.js';
import { afterEach, describe, it } from 'node:test';

import { toArray } from '../../generator.js';
import { FsMemory } from '../memory.js';

function toHref(s: URL[]): string[] {
return s.map((url) => url.href);
Expand Down
32 changes: 19 additions & 13 deletions packages/fs/src/systems/file.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { SourceFile } from '@chunkd/source-file';
import fs from 'node:fs';
import { Readable } from 'node:stream';

import { SourceFile } from '@chunkd/source-file';

import { FsError } from '../error.js';
import { FileInfo, FileSystem, ListOptions } from '../file.system.js';
export function isRecord<T = unknown>(value: unknown): value is Record<string, T> {
Expand Down Expand Up @@ -41,7 +43,7 @@ export class FsFile implements FileSystem {

// Trying to list a folder but doesn't exist
if (stat == null && loc.href.endsWith('/')) {
throw new FsError(`Failed to list: ${loc}`, 404, loc, 'list', this);
throw new FsError(`Failed to list: ${loc.href}`, 404, loc, 'list', this);
}

// Prefix search, list the parent folder and filter for the filename
Expand Down Expand Up @@ -71,7 +73,7 @@ export class FsFile implements FileSystem {
}
} catch (e) {
if (FsError.is(e)) throw e;
throw new FsError(`Failed to list: ${loc}`, getCode(e), loc, 'list', this, e);
throw new FsError(`Failed to list: ${loc.href}`, getCode(e), loc, 'list', this, e);
}
}

Expand All @@ -89,15 +91,15 @@ export class FsFile implements FileSystem {
return { url: loc, size: stat.size, isDirectory: stat.isDirectory() };
} catch (e) {
if (isRecord(e) && e.code === 'ENOENT') return null;
throw new FsError(`Failed to stat ${loc}`, getCode(e), loc, 'head', this, e);
throw new FsError(`Failed to stat ${loc.href}`, getCode(e), loc, 'head', this, e);
}
}

async read(loc: URL): Promise<Buffer> {
try {
return await fs.promises.readFile(loc);
} catch (e) {
throw new FsError(`Failed to read: ${loc}`, getCode(e), loc, 'read', this, e);
throw new FsError(`Failed to read: ${loc.href}`, getCode(e), loc, 'read', this, e);
}
}

Expand All @@ -107,17 +109,21 @@ export class FsFile implements FileSystem {
await fs.promises.mkdir(new URL('.', loc), { recursive: true });
await fs.promises.writeFile(loc, buf);
} else {
await new Promise(async (resolve, reject) => {
await new Promise((resolve, reject) => {
buf.once('error', reject); // Has to be run before any awaits
await fs.promises.mkdir(new URL('.', loc), { recursive: true });
const st = fs.createWriteStream(loc);
st.on('finish', resolve);
st.on('error', reject);
buf.pipe(st);
fs.promises
.mkdir(new URL('.', loc), { recursive: true })
.then(() => {
const st = fs.createWriteStream(loc);
st.on('finish', resolve);
st.on('error', reject);
buf.pipe(st);
})
.catch(reject);
});
}
} catch (e) {
throw new FsError(`Failed to write: ${loc}`, getCode(e), loc, 'write', this, e);
throw new FsError(`Failed to write: ${loc.href}`, getCode(e), loc, 'write', this, e);
}
}

Expand All @@ -129,7 +135,7 @@ export class FsFile implements FileSystem {
const code = getCode(e);
if (code === 404) return;

throw new FsError(`Failed to delete: ${loc}`, getCode(e), loc, 'delete', this, e);
throw new FsError(`Failed to delete: ${loc.href}`, getCode(e), loc, 'delete', this, e);
}
}

Expand Down
Loading