Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7317316
document.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
document.ts
View Options
import
{
JDDContext
}
from
"./jdd-context.js"
;
import
{
Registry
}
from
"./registry.js"
;
export
const
JDDStatus
=
Symbol
();
export
type
ComponentData
=
{
component_name
:
string
;
args
:
Record
<
string
,
unknown
>
;
};
export
type
RawJDDocument
=
Array
<
ComponentData
>
;
export
type
JDDocumentContainer
<
Status
extends
"parsed"
|
"storage"
>
=
{
value
:
RawJDDocument
;
[
JDDStatus
]
:
Status
;
};
export
async
function
documentToStorage
(
registry
:
Registry
,
jdd_context
:
JDDContext
,
document_container
:
JDDocumentContainer
<
"parsed"
>
)
:
Promise
<
JDDocumentContainer
<
"storage"
>>
{
const
result
=
await
Promise
.
all
(
document_container
.
value
.
map
(
async
({
component_name
,
args
})
=>
{
const
component
=
registry
.
get
(
component_name
);
if
(
!
component
)
{
throw
new
Error
(
`Unknown component:
${
component_name
}
`
);
}
return
{
component_name
,
args
:
await
component
.
convertParsedToStorage
(
jdd_context
,
args
),
};
})
);
return
{
value
:
result
,
[
JDDStatus
]
:
"storage"
};
}
export
async
function
documentToParsed
(
registry
:
Registry
,
jdd_context
:
JDDContext
,
document_container
:
JDDocumentContainer
<
"storage"
>
,
handle_unknown_component
:
(
component_name
:
string
)
=>
void
=
(
component_name
)
=>
{
console
.
warn
(
`Unknown component when parsing a JDD document:
${
component_name
}
`
);
}
// you can pass a different function and e.g. throw an error here if you want
)
:
Promise
<
JDDocumentContainer
<
"parsed"
>>
{
const
result
=
(
await
Promise
.
all
(
document_container
.
value
.
map
(
async
({
component_name
,
args
})
=>
{
const
component
=
registry
.
get
(
component_name
);
if
(
!
component
)
{
handle_unknown_component
(
component_name
);
return
null
;
}
return
{
component_name
,
args
:
await
component
.
convertStorageToParsed
(
jdd_context
,
args
),
};
})
.
filter
((
e
)
=>
e
!==
null
)
))
as
RawJDDocument
;
return
{
value
:
result
,
[
JDDStatus
]
:
"parsed"
};
}
export
function
documentContainerFromParsed
(
document
:
RawJDDocument
)
:
JDDocumentContainer
<
"parsed"
>
{
return
{
value
:
[...
document
],
[
JDDStatus
]
:
"parsed"
};
}
export
function
documentContainerFromStorage
(
document
:
RawJDDocument
)
:
JDDocumentContainer
<
"storage"
>
{
return
{
value
:
[...
document
],
[
JDDStatus
]
:
"storage"
};
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sun, Jul 13, 04:33 (20 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
625130
Default Alt Text
document.ts (2 KB)
Attached To
Mode
rJDD jdd
Attached
Detach File
Event Timeline
Log In to Comment