-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: add kinesis log stream #86
Changes from all commits
f0655d6
b4d7efb
51bf234
31a4aed
cd197e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
import * as CAR from '@ucanto/transport/car' | ||
import * as UCAN from '@ipld/dag-ucan' | ||
import * as Link from 'multiformats/link' | ||
|
||
/** | ||
* @typedef {object} UcanInvocation | ||
* @property {UCAN.Capabilities} att | ||
* @property {`did:${string}:${string}`} aud | ||
* @property {`did:${string}:${string}`} iss | ||
* | ||
* @typedef {object} UcanInvocationWrapper | ||
* @property {string} carCid | ||
* @property {Uint8Array} bytes | ||
* @property {UcanInvocation} value | ||
*/ | ||
|
||
/** | ||
* Persist successful UCAN invocations handled by the router. | ||
* | ||
* @param {import('aws-lambda').APIGatewayProxyEventV2} request | ||
* @param {UcanInvocationWrapper} ucanInvocation | ||
* @param {import('./service/types').UcanBucket} ucanStore | ||
*/ | ||
export async function persistUcanInvocation (request, ucanStore) { | ||
const { carCid, bytes } = await parseUcanInvocationRequest(request) | ||
|
||
await ucanStore.put(carCid, bytes) | ||
export async function persistUcanInvocation (ucanInvocation, ucanStore) { | ||
await ucanStore.put(ucanInvocation.carCid, ucanInvocation.bytes) | ||
} | ||
|
||
/** | ||
* @param {import('aws-lambda').APIGatewayProxyEventV2} request | ||
* @returns {Promise<UcanInvocationWrapper>} | ||
*/ | ||
export async function parseUcanInvocationRequest (request) { | ||
if (!request.body) { | ||
|
@@ -24,8 +37,57 @@ export async function parseUcanInvocationRequest (request) { | |
const car = await CAR.codec.decode(bytes) | ||
const carCid = car.roots[0].cid.toString() | ||
|
||
// @ts-expect-error 'ByteView<unknown>' is not assignable to parameter of type 'ByteView<UCAN<Capabilities>>' | ||
const dagUcan = UCAN.decode(car.roots[0].bytes) | ||
|
||
return { | ||
bytes, | ||
carCid | ||
carCid, | ||
value: { | ||
// Workaround for: | ||
// https://github.com/web3-storage/ucanto/issues/171 | ||
// https://github.com/multiformats/js-multiformats/issues/228 | ||
// @ts-ignore missing types | ||
att: dagUcan.att.map(replaceAllLinkValues), | ||
aud: dagUcan.aud.did(), | ||
iss: dagUcan.iss.did(), | ||
prf: replaceAllLinkValues(dagUcan.prf) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param {any} value | ||
*/ | ||
export const replaceAllLinkValues = (value) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looked into npm modules available, but could not get something useful for it. If there are suggestions of modules you know that could help please let me know. This small function goes through the Object through all its depth and replaces all Once this lands in |
||
// Array with Links? | ||
if (Array.isArray(value)) { | ||
for (let i = 0; i < value.length; i++) { | ||
if (Link.isLink(value[i])) { | ||
value[i] = toJSON(value[i]) | ||
} else { | ||
replaceAllLinkValues(value[i]) | ||
} | ||
} | ||
} | ||
// Object with Links? | ||
else if (typeof value === 'object') { | ||
for (const key of Object.keys(value)) { | ||
if (Link.isLink(value[key])) { | ||
value[key] = toJSON(value[key]) | ||
} | ||
replaceAllLinkValues(value[key]) | ||
} | ||
} | ||
|
||
return value | ||
} | ||
|
||
/** | ||
* @template {import('multiformats').UnknownLink} Link | ||
* @param {Link} link | ||
*/ | ||
export const toJSON = link => | ||
/** @type {import('./service/types').LinkJSON<Link>} */ ({ | ||
'/': link.toString(), | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on proposal there.