forked from fireproof-storage/fireproof
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request fireproof-storage#144 from fireproof-storage/dev
cleanup file/table-name generation
- Loading branch information
Showing
20 changed files
with
320 additions
and
361 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ smoke/package.json | |
smoke/pnpm-lock.yaml | ||
smoke/react/package.json | ||
smoke/react/pnpm-lock.yaml | ||
**/__screenshots__/ |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* eslint no-console: "off" */ | ||
import { $ } from "zx"; | ||
import { SemVer } from "semver"; | ||
import fs from "fs"; | ||
|
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
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 |
---|---|---|
@@ -1,34 +1,31 @@ | ||
import { Logger, getStore } from "../utils.js"; | ||
import { SysContainer } from "./sys-container.js"; | ||
|
||
export async function getPath(url: URL, logger: Logger): Promise<string> { | ||
export function getPath(url: URL, logger: Logger): string { | ||
const basePath = url | ||
.toString() | ||
.replace(new RegExp(`^${url.protocol}//`), "") | ||
.replace(/\?.*$/, ""); | ||
const name = url.searchParams.get("name"); | ||
if (name) { | ||
const version = url.searchParams.get("version"); | ||
if (!version) throw logger.Error().Str("url", url.toString()).Msg(`version not found`).AsError(); | ||
if (!version) throw logger.Error().Url(url).Msg(`version not found`).AsError(); | ||
return SysContainer.join(basePath, version, name); | ||
} | ||
return SysContainer.join(basePath); | ||
} | ||
|
||
export function getFileName(url: URL, key: string, logger: Logger): string { | ||
switch (getStore(url, logger, (...a: string[]) => a.join("/"))) { | ||
export function getFileName(url: URL, logger: Logger): string { | ||
const key = url.searchParams.get("key"); | ||
if (!key) throw logger.Error().Url(url).Msg(`key not found`).AsError(); | ||
const res = getStore(url, logger, (...a: string[]) => a.join("-")); | ||
switch (res.store) { | ||
case "data": | ||
return key + ".car"; | ||
return SysContainer.join(res.name, key + ".car"); | ||
case "wal": | ||
case "meta": | ||
return key + ".json"; | ||
return SysContainer.join(res.name, key + ".json"); | ||
default: | ||
throw logger.Error().Str("url", url.toString()).Msg(`unsupported store type`).AsError(); | ||
throw logger.Error().Url(url).Msg(`unsupported store type`).AsError(); | ||
} | ||
} | ||
|
||
export function ensureIndexName(url: URL, name: string): string { | ||
if (url.searchParams.has("index")) { | ||
name = (url.searchParams.get("index")?.replace(/[^a-zA-Z0-9]/g, "") || "idx") + "-" + name; | ||
} | ||
return name; | ||
} |
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
Oops, something went wrong.