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

refactor: Specify common types TDE-1030 #849

Closed
wants to merge 40 commits into from
Closed

refactor: Specify common types TDE-1030 #849

wants to merge 40 commits into from

Conversation

l0b0
Copy link
Contributor

@l0b0 l0b0 commented Feb 1, 2024

Motivation

Strengthen type limitations to make it easier to understand where a "string" is actually a URL and where it's really a local path.

Checklist

Refactor; none of the checklist is applicable.

src/utils/types.ts Outdated Show resolved Hide resolved
src/commands/copy/copy.ts Outdated Show resolved Hide resolved
@l0b0 l0b0 requested a review from blacha February 2, 2024 01:48
@l0b0 l0b0 changed the title refactor: Specify common branded types refactor: Specify common types Feb 2, 2024
const obj = await fsa.read(config);
if (config.endsWith('.gz') || isGzip(obj)) {
async function readConfig(config: URL): Promise<ConfigBundled> {
const obj = await fsa.read(config.href);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not safe to use .href here. If its a file url it has to be converted with path.fileURLToPath.

does fsa.read not accept a URL? would imply fsa is out of date?

Copy link
Contributor Author

@l0b0 l0b0 Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not safe to use .href here. If its a file url it has to be converted with path.fileURLToPath.

I'd rather upgrade fsa, but:

does fsa.read not accept a URL? would imply fsa is out of date?

Yep; that PR needs a bunch of fixes, though.

if (baseFile) {
target = fsa.joinAll(targetPath, transformFunc ? transformFunc(baseFile) : baseFile);
target = new URL(fsa.joinAll(targetUrl.href, transformFunc ? transformFunc(baseFile) : baseFile));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

joinAll does a very similar job to new URL(input, base) in most use cases it should be a direct swap.

I believe the one caveat is joinAll("foo.com/bar", "baz") would make "foo.com/bar/baz" where as new URL("baz", "foo.com/bar") would make "foo.com/baz"

Copy link
Contributor Author

@l0b0 l0b0 Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, new URL('sub-path', 's3://bucket/path').href === "s3://bucket/sub-path" . But I don't know what to do about that info. I would expect most of our base URLs to be arbitrary non-root ones, in which case new URL(input, base) would not do what we want. Which means joinAll is the safer alternative. Or are you saying the base URLs will always end with a slash, so that both solutions do the same thing?

We also have a normaliseHref in src/commands/stac-validate/stac.validate.ts and tryParseUrl in src/commands/common.ts which should probably be removed.

src/utils/action.storage.ts Outdated Show resolved Hide resolved
@l0b0 l0b0 requested a review from blacha February 7, 2024 00:34
l0b0 and others added 6 commits February 7, 2024 13:37
Bumps the chunkd group with 3 updates: [@chunkd/fs](https://github.com/blacha/chunkd/tree/HEAD/packages/fs), [@cogeotiff/core](https://github.com/blacha/cogeotiff/tree/HEAD/packages/core) and [@chunkd/source-memory](https://github.com/blacha/chunkd/tree/HEAD/packages/source-memory).


Updates `@chunkd/fs` from 10.0.9 to 11.2.0
- [Release notes](https://github.com/blacha/chunkd/releases)
- [Changelog](https://github.com/blacha/chunkd/blob/master/packages/fs/CHANGELOG.md)
- [Commits](https://github.com/blacha/chunkd/commits/fs-v11.2.0/packages/fs)

Updates `@cogeotiff/core` from 8.1.1 to 9.0.3
- [Release notes](https://github.com/blacha/cogeotiff/releases)
- [Changelog](https://github.com/blacha/cogeotiff/blob/master/packages/core/CHANGELOG.md)
- [Commits](https://github.com/blacha/cogeotiff/commits/cli-v9.0.3/packages/core)

Updates `@chunkd/source-memory` from 10.1.0 to 11.0.2
- [Release notes](https://github.com/blacha/chunkd/releases)
- [Changelog](https://github.com/blacha/chunkd/blob/master/packages/source-memory/CHANGELOG.md)
- [Commits](https://github.com/blacha/chunkd/commits/fs-v11.0.2/packages/source-memory)

---
updated-dependencies:
- dependency-name: "@chunkd/fs"
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: chunkd
- dependency-name: "@cogeotiff/core"
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: chunkd
- dependency-name: "@chunkd/source-memory"
  dependency-type: direct:development
  update-type: version-update:semver-major
  dependency-group: chunkd
...

Signed-off-by: dependabot[bot] <support@github.com>
@@ -6,7 +6,7 @@ export interface CopyContractArgs {
/** Copy ID for tracing */
id: string;
/** List of files that need to be copied */
manifest: { source: string; target: string }[];
manifest: { source: URL; target: URL }[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can worker threads actually pass URLS? I thought everything was meant to be a POJO for passing around?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you mean either JSON or JS object, not "Plain old Java object". I have no idea how WorkerRpc works; I guess since you ask we don't have tests for this message passing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worker_threads are a mechanisim of using small scripts to add more threads to do processing, they are limited to posting messages to/from the thread using a rpc type mechanisim, WorkerRpc wraps the posting so it is somewhat typesafe.

I am not sure we can pass a URL between threads as its not really a easily searliazable thing, just like you cant pass a date but you can pass a ISO string.

src/utils/action.storage.ts Outdated Show resolved Hide resolved
@l0b0 l0b0 requested a review from blacha February 13, 2024 20:15
Copy link
Member

@blacha blacha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These issues could have prevented the commands from running, it is slightly concerning that they are this deep in the pull request chain and I have likely missed other spots where things are broken.

Have you run any of the commands before making this PR?

logger.info({ config }, 'MapSheet:LoadConfig');
const configJson = await readConfig(config);
const mem = ConfigProviderMemory.fromJson(configJson);

const rest = fgb.deserialize(buf) as FeatureCollection;
const featuresWritePromise = fsa.write('features.json', JSON.stringify(rest));
const featuresWritePromise = fsa.write(new URL(fsa.toUrl('./features.json').href), JSON.stringify(rest));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const featuresWritePromise = fsa.write(new URL(fsa.toUrl('./features.json').href), JSON.stringify(rest));
const featuresWritePromise = fsa.write(fsa.toUrl('./features.json'), JSON.stringify(rest));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using the wrong interpreter; please ignore the deleted comment.

src/commands/stac-validate/stac.validate.ts Outdated Show resolved Hide resolved
@l0b0
Copy link
Contributor Author

l0b0 commented Feb 19, 2024

These issues could have prevented the commands from running, it is slightly concerning that they are this deep in the pull request chain and I have likely missed other spots where things are broken.

Have you run any of the commands before making this PR?

No, because making heaps of manual smoke tests for each refactor is tedious, error-prone, and slow. If it's worth testing we should have automated tests for it.

@l0b0 l0b0 requested a review from blacha February 19, 2024 00:16
@l0b0 l0b0 closed this Feb 23, 2024
auto-merge was automatically disabled February 23, 2024 01:52

Pull request was closed

@l0b0 l0b0 deleted the refactor/types branch March 17, 2024 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants