diff --git a/CHANGELOG.md b/CHANGELOG.md index a85489d..babaf1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Changed + +- Documented `taskSchemaDocument`, `bindingSchemaDocument`, `paths.taskSchema` and `paths.bindingSchema` as tasknotes.task type-pack resources. A host must not write them as plain files: mdbase setup refuses a plain file at a path the pack manages unless it holds the exact resource bytes (tasknotes-app #436). The contract already carries both schemas inline. + ## 0.3.0-rc.21 ### Added diff --git a/src/mdbase.ts b/src/mdbase.ts index ce38eea..56963df 100644 --- a/src/mdbase.ts +++ b/src/mdbase.ts @@ -121,13 +121,24 @@ export interface TaskNotesMdbaseResources { configDocument: string; contractDocument: string; typeDocument: string; + /** + * The task schema as a standalone JSON document: a resource of the + * tasknotes.task type pack (see buildTaskNotesMdbaseTypePack), which a + * connector installs with a receipt. Hosts never write it to + * `paths.taskSchema` as a plain file. mdbase setup refuses a plain file at + * a path the pack manages unless it holds these exact bytes, and the + * contract already carries the schema inline as `record_schema`. + */ taskSchemaDocument: string; + /** The binding schema as a standalone JSON document; a type-pack resource like `taskSchemaDocument`. */ bindingSchemaDocument: string; paths: { config: "mdbase.yaml"; contract: string; type: string; + /** Where the tasknotes.task type pack installs `taskSchemaDocument`. Not a host-written file. */ taskSchema: string; + /** Where the tasknotes.task type pack installs `bindingSchemaDocument`. Not a host-written file. */ bindingSchema: string; records: string; }; @@ -505,7 +516,9 @@ function userFieldProperty( * * Hosts provide their effective TaskNotes settings and perform the actual IO. * The returned object model is authoritative; the documents are deterministic - * serializations for filesystem-backed collections. + * serializations for filesystem-backed collections. The two schema documents + * are the exception: they are tasknotes.task type-pack resources, and a host + * does not write them itself (see `taskSchemaDocument`). */ export function buildTaskNotesMdbaseResources( options: TaskNotesMdbaseOptions = {} diff --git a/test/mdbase.test.mjs b/test/mdbase.test.mjs index 7a033e5..7e2dc08 100644 --- a/test/mdbase.test.mjs +++ b/test/mdbase.test.mjs @@ -95,6 +95,28 @@ test("builds one canonical TaskNotes and mdbase collection contract", () => { assert.deepEqual(YAML.parse(contractFrontmatter[1]), resources.contract); }); +test("keeps the standalone schemas pack-managed and inline in the contract", async () => { + // Hosts never write the schema files: the pack manages both paths, and + // the contract carries both schemas, so a collection without the files + // is complete. + const resources = buildTaskNotesMdbaseResources(); + const pack = await buildTaskNotesMdbaseTypePack(resources); + for (const [target, document] of [ + [resources.paths.taskSchema, resources.taskSchemaDocument], + [resources.paths.bindingSchema, resources.bindingSchemaDocument], + ]) { + const resource = pack.manifest.resources.find((entry) => entry.target === target); + assert.equal(resource?.kind, "schema"); + assert.equal(resource?.mode, "managed"); + assert.equal( + pack.resources.find(({ source }) => source === resource.source)?.document, + document + ); + } + assert.deepEqual(resources.contract.record_schema.value, resources.taskSchema); + assert.deepEqual(resources.contract.binding_schema.value, resources.bindingSchema); +}); + test("packages the contract, implementation, and schemas as one digest-pinned type pack", async () => { const resources = buildTaskNotesMdbaseResources({ typeName: "action" }); const pack = await buildTaskNotesMdbaseTypePack(resources);