-
Notifications
You must be signed in to change notification settings - Fork 8
Codex/blazegraph safe rdf literals #1322
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,7 @@ import { | |
| sharedMemoryReadBothFilter, | ||
| partitionCatalogQuads, | ||
| } from '@origintrail-official/dkg-core'; | ||
| import { normalizeLargeRdfLiteralsForBlazegraph } from '@origintrail-official/dkg-core'; | ||
| import { GraphManager, PrivateContentStore, createTripleStore, type TripleStore, type TripleStoreConfig, type Quad, type LargeLiteralStorageConfig } from '@origintrail-official/dkg-storage'; | ||
| import { EVMChainAdapter, NoChainAdapter, enrichEvmError, buildKnowledgeAssetUal, type EVMAdapterConfig, type ChainAdapter, type CreateContextGraphParams, type CreateOnChainContextGraphParams, type CreateOnChainContextGraphResult, type TxResult, type V10PublishingConvictionAccountInfo } from '@origintrail-official/dkg-chain'; | ||
| import { | ||
|
|
@@ -1267,6 +1268,10 @@ export class PublishMethods extends DKGAgentBase { | |
| ): Promise<PublishResult> { | ||
| const ctx = opts?.operationCtx ?? createOperationContext('publish'); | ||
| const onPhase = opts?.onPhase; | ||
| quads = normalizeLargeRdfLiteralsForBlazegraph(quads).quads as Quad[]; | ||
| if (privateQuads) { | ||
| privateQuads = normalizeLargeRdfLiteralsForBlazegraph(privateQuads).quads as Quad[]; | ||
| } | ||
| this.log.info(ctx, `Starting publish to context graph "${contextGraphId}" with ${quads.length} triples`); | ||
|
|
||
| const isSystem = contextGraphId === SYSTEM_CONTEXT_GRAPHS.AGENTS || contextGraphId === SYSTEM_CONTEXT_GRAPHS.ONTOLOGY; | ||
|
|
@@ -2567,6 +2572,10 @@ export class PublishMethods extends DKGAgentBase { | |
| privateQuads?: Quad[]; | ||
| }, | ||
| ): Promise<PublishOptions['precomputedAttestation']> { | ||
| quads = normalizeLargeRdfLiteralsForBlazegraph(quads).quads as Quad[]; | ||
|
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. 🟡 Issue: This normalization feeds |
||
| const normalizedPrivateQuads = opts?.privateQuads | ||
| ? normalizeLargeRdfLiteralsForBlazegraph(opts.privateQuads).quads as Quad[] | ||
| : undefined; | ||
| if ( | ||
| opts?.authorAgentAddress != null && | ||
| opts?.preSignedAuthorAttestation != null | ||
|
|
@@ -2595,7 +2604,7 @@ export class PublishMethods extends DKGAgentBase { | |
| // KC merkle. The order MUST follow the publisher's manifest | ||
| // iteration over `kaMap`, which is the insertion order — same map | ||
| // we built two lines up. | ||
| const privateQuads = opts?.privateQuads ?? []; | ||
| const privateQuads = normalizedPrivateQuads ?? []; | ||
| const privateRoots: Uint8Array[] = []; | ||
| for (const rootEntity of kaMap.keys()) { | ||
| if (privateQuads.length === 0) break; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,19 @@ export function payloadTooLargeResponseBody(err: unknown): Record<string, unknow | |
| return body; | ||
| } | ||
|
|
||
| export function isRdfLiteralSizeError(err: unknown): boolean { | ||
| if (!err || typeof err !== 'object') return false; | ||
| const shaped = err as { name?: unknown; code?: unknown }; | ||
| return shaped.name === 'RdfLiteralSizeError' || shaped.code === 'RDF_LITERAL_TOO_LARGE'; | ||
| } | ||
|
|
||
|
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. 🟡 Issue: |
||
| export function rdfLiteralSizeResponseBody(err: unknown): Record<string, unknown> { | ||
| return { | ||
| error: err instanceof Error ? err.message : String(err ?? 'RDF literal exceeds size limit'), | ||
| code: 'RDF_LITERAL_TOO_LARGE', | ||
| }; | ||
| } | ||
|
|
||
| export async function resolveNameToPeerId( | ||
| agent: DKGAgent, | ||
| nameOrId: string, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,8 +27,10 @@ | |
| import type { RequestContext } from "./context.js"; | ||
| import { | ||
| isPayloadTooLargeError, | ||
| isRdfLiteralSizeError, | ||
| jsonResponse, | ||
| payloadTooLargeResponseBody, | ||
| rdfLiteralSizeResponseBody, | ||
| readBody, | ||
| safeParseJson, | ||
| validateEntities, | ||
|
|
@@ -650,6 +652,9 @@ export async function handleKnowledgeAssetsRoutes(ctx: RequestContext): Promise< | |
| if (isPayloadTooLargeError(e)) { | ||
| return jsonResponse(res, 413, payloadTooLargeResponseBody(e)); | ||
| } | ||
| if (isRdfLiteralSizeError(e)) { | ||
|
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. 🟡 Issue: The daemon now maps |
||
| return jsonResponse(res, 400, rdfLiteralSizeResponseBody(e)); | ||
| } | ||
| return jsonResponse(res, 500, { error: e?.message ?? String(e) }); | ||
| } | ||
| } | ||
|
|
||
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.
🔵 Nit:
normalizeLargeRdfLiteralsForBlazegraphis imported from@origintrail-official/dkg-corein its own statement immediately after an existing import from the same package. Consolidating it into the existing import matches the local pattern and avoids needless import drift as more core symbols are added.