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

Add pidFromStringID function to interface easier with resolve #40

Merged
merged 1 commit into from
Feb 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
16 changes: 14 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,22 @@ jobs:
check-latest: false
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm --workspace packages/composedb publish --access public
- run: |
if ! npm --workspace packages/composedb view .@${npm_package_version} > /dev/null; then
echo "New version of composedb package; running publish..."
npm --workspace packages/composedb publish --access public
else
echo "This version of the composedb package already exists on npm; doing nothing."
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: npm --workspace packages/lib run build
- run: npm --workspace packages/lib publish --access public
- run: |
if ! npm --workspace packages/lib view .@${npm_package_version} > /dev/null; then
echo "New version of lib package; running publish..."
npm --workspace packages/lib publish --access public
else
echo "This version of the lib package already exists on npm; doing nothing."
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5 changes: 3 additions & 2 deletions packages/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@desci-labs/desci-codex-lib",
"version": "1.0.4",
"version": "1.0.6",
"description": "Codex interaction primitives",
"license": "MIT",
"author": "Edvard Hübinette",
Expand All @@ -10,7 +10,8 @@
"scripts": {
"build": "rm -rf ./dist && tsc --project tsconfig.build.json",
"populate": "node --no-warnings=ExperimentalWarning --loader ts-node/esm scripts/populate.ts",
"test": "export ADMIN_SEED=$(<../composedb/admin_seed.txt) && vitest --run --config vitest.config.ts"
"test": "export ADMIN_SEED=$(<../composedb/admin_seed.txt) && vitest --run --config vitest.config.ts",
"doPublish": "npm run build && cd ../.. && npm publish --workspace packages/lib --access public --dry-run"
},
"devDependencies": {
"ts-node": "^10.9.1",
Expand Down
26 changes: 22 additions & 4 deletions packages/lib/src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,31 @@ export const resolveState = async (
* necessary to discern between multiple updates under the same anchor.
*
* @param client - A Ceramic client instance.
* @param pid - The address of a node state.
* @param id - The address of a node state.
* @param includeAnchors - Optionally include anchor commits in the log.
* @returns an array of the historical events of the stream.
*/
export const resolveHistory = async (
client: CeramicClient,
pid: RootNode,
id: StreamID | string,
includeAnchors: boolean = false,
): Promise<LogWithCommits> =>
await loadID(client, pid.id).then((s) => getVersionLog(s, includeAnchors));
): Promise<LogWithCommits> => {
if (typeof id === "string") {
id = StreamID.fromString(id);
}
return await loadID(client, id).then((s) => getVersionLog(s, includeAnchors));
};

export const pidFromStringID = (stringID: string): RootNode | VersionedNode => {
const commit = CommitID.fromStringNoThrow(stringID);
if (commit instanceof CommitID) {
return { tag: "versioned", id: commit };
}

const stream = StreamID.fromStringNoThrow(stringID);
if (stream instanceof StreamID) {
return { tag: "root", id: stream };
}

throw new Error("Passed string is neither a stream nor a commit ID");
};
Loading