Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/mdbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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 = {}
Expand Down
22 changes: 22 additions & 0 deletions test/mdbase.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading