Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ jobs:
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@0.0.9
needs: install-swiftly
with:
api_breakage_check_allowlist_path: "api-breakages.txt"
api_breakage_check_container_image: "swift:${{ needs.install-swiftly.outputs.current_version }}-noble"
docs_check_enabled: false
format_check_container_image: "swift:${{ needs.install-swiftly.outputs.current_version }}-noble"
Expand Down
2 changes: 1 addition & 1 deletion Sources/JSONLD/Algorithms/ExpansionAlgorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct ExpansionAlgorithm {

static func run(
_ input: Input,
loader: any JSONLDDocumentLoader
loader: (any JSONLDDocumentLoader)?
) async throws(JSONLDError) -> JSONLDValues<Expanded> {
_ = input.normative

Expand Down
20 changes: 9 additions & 11 deletions Sources/JSONLD/Context/ContextResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,11 @@ struct ContextResolver {
)
}

let result = await loader.load(url: resolvedIRI)
let remoteDocument: RemoteDocument =
switch result {
case .success(let doc):
doc
case .failure(let error):
throw .code(
.loadingRemoteContextFailed,
debugInfo: .init(url: resolvedIRI, message: String(describing: error))
)
}
let remoteDocument = try await RemoteDocument.load(
url: resolvedIRI,
using: loader,
requestProfile: RemoteDocument.contextProfile
)

guard case .object(let object) = remoteDocument.document,
let innerContext = object[.context]
Expand All @@ -101,11 +95,15 @@ struct ContextResolver {
var subContext = activeContext
subContext.baseIRI = remoteDocument.documentURL

let previousBaseIRI = activeContext.baseIRI
let previousOriginalBaseIRI = activeContext.originalBaseIRI
activeContext = try await self.process(
contexts: remoteContext,
activeContext: subContext,
remoteContexts: updatedRemoteContexts
)
activeContext.baseIRI = previousBaseIRI
activeContext.originalBaseIRI = previousOriginalBaseIRI

case .contextDefinition(let definition):
try self.apply(contextDefinition: definition, to: &activeContext)
Expand Down
31 changes: 19 additions & 12 deletions Sources/JSONLD/Context/Contexts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ extension Contexts: ExpressibleByNilLiteral {
extension Contexts: ExpressibleByStringLiteral {
/// Creates a context literal from an IRI string.
public init(stringLiteral value: String) {
do {
self = .single(try .init(iri: value))
} catch {
preconditionFailure("Invalid @context literal: \(error)")
}
self = .single(.init(iri: value))
}
}

Expand All @@ -75,6 +71,21 @@ extension Contexts: ExpressibleByDictionaryLiteral {
}
}

extension Contexts {
static func + (lhs: Self, rhs: Self) -> Self {
switch (lhs, rhs) {
case (.null, .null): .null
case (.null, let context), (let context, .null): context

case (.single(let lhsElement), .single(let rhsElement)): .array([lhsElement, rhsElement])

case (.array(let lhsElements), .single(let rhsElement)): .array(lhsElements + [rhsElement])
case (.single(let lhsElement), .array(let rhsElements)): .array([lhsElement] + rhsElements)
case (.array(let lhsElements), .array(let rhsElements)): .array(lhsElements + rhsElements)
}
}
}

extension Contexts {
/// A single `@context` element.
public enum Element: CustomJSONValueConvertible, Equatable, Sendable {
Expand All @@ -87,11 +98,7 @@ extension Contexts {
extension Contexts.Element: ExpressibleByStringLiteral {
/// Creates a context element literal from an IRI string.
public init(stringLiteral value: String) {
do {
try self.init(iri: value)
} catch {
preconditionFailure("Invalid @context literal: \(error)")
}
self.init(iri: value)
}
}

Expand All @@ -111,7 +118,7 @@ extension Contexts.Element {
}
}

init(iri value: String) throws(JSONLDError) {
init(iri value: String) {
self =
if value.contains(":") {
.absoluteIRI(value)
Expand All @@ -130,7 +137,7 @@ extension Contexts.Element {
self =
switch jsonValue {
case .object(let jsonObject): try .init(from: jsonObject)
case .string(let value): try .init(iri: value)
case .string(let value): .init(iri: value)
default: throw .code(.invalidLocalContext)
}
}
Expand Down
Loading
Loading