MCPcopy Create free account
hub / github.com/AlexErrant/Pentive / templateEntityToDomain

Function templateEntityToDomain

app/src/sqlite/util.ts:89–114  ·  view source on GitHub ↗
(
	template: TemplateEntity,
	remotes: RemoteTemplate[],
)

Source from the content-addressed store, hash-verified

87export const parseTemplateFields: (_: string) => Field[] = JSON.parse
88
89export function templateEntityToDomain(
90 template: TemplateEntity,
91 remotes: RemoteTemplate[],
92) {
93 return {
94 id: fromLDbId(template.id),
95 name: template.name,
96 created: new Date(template.created),
97 edited: new Date(template.edited),
98 fields: parseTemplateFields(template.fields),
99 css: template.css,
100 templateType: JSON.parse(template.templateType) as TemplateType,
101 remotes: Object.fromEntries(
102 remotes.map((r) => {
103 const value =
104 r.remoteId == null || r.uploadDate == null
105 ? null
106 : ({
107 remoteTemplateId: fromLDbId(r.remoteId),
108 uploadDate: new Date(r.uploadDate),
109 } satisfies Template['remotes'][NookId])
110 return [r.nook, value]
111 }),
112 ),
113 } satisfies Template
114}
115
116export function noteEntityToDomain(
117 note: NoteEntity & { template_fields: string },

Callers 2

toTemplatesFunction · 0.90
getTemplateFunction · 0.70

Calls 2

fromLDbIdFunction · 0.90
parseMethod · 0.45

Tested by

no test coverage detected