@@ -20,6 +20,7 @@ import {
2020 isQueryResultForDereferencing ,
2121 QueryResultInternals ,
2222} from "./query-result-proxy.ts" ;
23+ import { type IMemoryAddress } from "./storage/interface.ts" ;
2324
2425/**
2526 * Normalized link structure returned by parsers
@@ -28,22 +29,19 @@ export type NormalizedLink = {
2829 id ?: URI ; // URI format with "of:" prefix
2930 path : string [ ] ;
3031 space ?: MemorySpace ;
32+ type ?: string ; // Default is "application/json"
3133 schema ?: JSONSchema ;
3234 rootSchema ?: JSONSchema ;
3335 overwrite ?: "redirect" ; // "this" gets normalized away to undefined
3436} ;
3537
3638/**
37- * Normalized link with required id and space (when base Cell is provided)
39+ * Full normalized link that from a complete link, i.e. with required id, space
40+ * and type. Gets created by parseLink if a base is provided.
41+ *
42+ * Any such link can be used as a memory address.
3843 */
39- export type NormalizedFullLink = {
40- id : URI ; // URI format with "of:" prefix
41- path : string [ ] ;
42- space : MemorySpace ;
43- schema ?: JSONSchema ;
44- rootSchema ?: JSONSchema ;
45- overwrite ?: "redirect" ; // "this" gets normalized away to undefined
46- } ;
44+ export type NormalizedFullLink = NormalizedLink & IMemoryAddress ;
4745
4846/**
4947 * A type reflecting all possible link formats, including cells themselves.
@@ -175,6 +173,7 @@ export function isNormalizedFullLink(value: any): value is NormalizedFullLink {
175173 isRecord ( value ) &&
176174 typeof value . id === "string" &&
177175 typeof value . space === "string" &&
176+ typeof value . type === "string" &&
178177 Array . isArray ( value . path )
179178 ) ;
180179}
@@ -248,6 +247,7 @@ export function parseLink(
248247 id : toURI ( value . getDoc ( ) . entityId ) ,
249248 path : value . path . map ( ( p ) => p . toString ( ) ) ,
250249 space : value . space ,
250+ type : "application/json" ,
251251 schema : value . schema ,
252252 rootSchema : value . rootSchema ,
253253 } ;
@@ -259,6 +259,7 @@ export function parseLink(
259259 id : toURI ( value . entityId ) ,
260260 path : [ ] ,
261261 space : value . space ,
262+ type : "application/json" ,
262263 } ;
263264 }
264265
@@ -280,6 +281,7 @@ export function parseLink(
280281 id : id ,
281282 path : path . map ( ( p ) => p . toString ( ) ) ,
282283 space : resolvedSpace ,
284+ type : "application/json" ,
283285 schema : link . schema ,
284286 rootSchema : link . rootSchema ,
285287 overwrite : link . overwrite === "redirect" ? "redirect" : undefined ,
@@ -292,6 +294,7 @@ export function parseLink(
292294 id : toURI ( value . cell . entityId ) ,
293295 path : value . path . map ( ( p ) => p . toString ( ) ) ,
294296 space : value . cell . space ,
297+ type : "application/json" ,
295298 schema : value . schema ,
296299 rootSchema : value . rootSchema ,
297300 } ;
@@ -303,6 +306,7 @@ export function parseLink(
303306 id : toURI ( value . cell [ "/" ] ) ,
304307 path : value . path . map ( ( p ) => p . toString ( ) ) ,
305308 space : base ?. space , // Space must come from context for JSON links
309+ type : "application/json" ,
306310 } ;
307311 }
308312
@@ -311,6 +315,7 @@ export function parseLink(
311315 id : toURI ( value [ "/" ] ) ,
312316 path : [ ] ,
313317 space : base ?. space , // Space must come from context for JSON links
318+ type : "application/json" ,
314319 } ;
315320 }
316321
@@ -341,6 +346,7 @@ export function parseLink(
341346 ? alias . path . map ( ( p ) => p . toString ( ) )
342347 : [ ] ,
343348 space : resolvedSpace ,
349+ type : "application/json" ,
344350 schema : alias . schema as JSONSchema | undefined ,
345351 rootSchema : alias . rootSchema as JSONSchema | undefined ,
346352 } ;
@@ -503,7 +509,8 @@ export function areNormalizedLinksSame(
503509 link2 : NormalizedLink ,
504510) : boolean {
505511 return link1 . id === link2 . id && link1 . space === link2 . space &&
506- arrayEqual ( link1 . path , link2 . path ) ;
512+ arrayEqual ( link1 . path , link2 . path ) &&
513+ ( link1 . type ?? "application/json" ) === ( link2 . type ?? "application/json" ) ;
507514}
508515
509516export function createSigilLinkFromParsedLink (
0 commit comments