MCPcopy Index your code
hub / github.com/callumalpass/tasknotes / createTaskWithCompat

Function createTaskWithCompat

src/core/createCompat.ts:38–82  ·  view source on GitHub ↗
(
	collection: CreateCollectionLike,
	mapping: SpecFieldMapping,
	roleFrontmatter: UnknownRecord,
	body?: string,
	now?: Date
)

Source from the content-addressed store, hash-verified

36};
37
38export async function createTaskWithCompat(
39 collection: CreateCollectionLike,
40 mapping: SpecFieldMapping,
41 roleFrontmatter: UnknownRecord,
42 body?: string,
43 now?: Date
44): Promise<CreateResultLike> {
45 const taskType = getTaskTypeDef(collection);
46 const denormalized = denormalizeFrontmatter(roleFrontmatter, mapping);
47 const effectiveNow = now instanceof Date && !Number.isNaN(now.getTime()) ? now : new Date();
48
49 applyFieldDefaults(denormalized, taskType);
50 applyTimestampDefaults(denormalized, mapping, taskType, effectiveNow);
51 applyMatchDefaults(denormalized, taskType);
52
53 const input: CreateInputLike = {
54 type: "task",
55 frontmatter: denormalized,
56 body,
57 };
58
59 const firstAttempt = await collection.create(input);
60 if (!firstAttempt.error || firstAttempt.error.code !== "path_required") {
61 return firstAttempt;
62 }
63
64 const pathResolution = derivePathFromType(taskType, denormalized, mapping, effectiveNow);
65 if (!pathResolution.path) {
66 if (pathResolution.missingKeys && pathResolution.missingKeys.length > 0) {
67 const missing = pathResolution.missingKeys.join(", ");
68 return {
69 ...firstAttempt,
70 warnings: [
71 `Cannot resolve path_pattern "${pathResolution.template}": missing template values for ${missing}.`,
72 ],
73 };
74 }
75 return firstAttempt;
76 }
77
78 return await collection.create({
79 ...input,
80 path: pathResolution.path,
81 });
82}
83
84function getTaskTypeDef(collection: CreateCollectionLike): TaskTypeDefLike | undefined {
85 const maybeCollection = collection as unknown as { typeDefs?: Map<string, TaskTypeDefLike> };

Callers

nothing calls this directly

Calls 6

getTaskTypeDefFunction · 0.85
applyFieldDefaultsFunction · 0.85
applyTimestampDefaultsFunction · 0.85
applyMatchDefaultsFunction · 0.85
derivePathFromTypeFunction · 0.85
createMethod · 0.65

Tested by

no test coverage detected