Skip to content

Commit

Permalink
Add pidFromStringID function to interface easier with resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
m0ar committed Feb 5, 2024
1 parent a09ea29 commit 89dc470
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
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");
};

0 comments on commit 89dc470

Please sign in to comment.