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
14 changes: 9 additions & 5 deletions apps/extension/src/generated/mdbase-app.json

Large diffs are not rendered by default.

53 changes: 0 additions & 53 deletions apps/reader/mdbase/packs/mdbase.view-1.0.0.json

This file was deleted.

57 changes: 57 additions & 0 deletions apps/reader/mdbase/packs/mdbase.view-1.0.1.json

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions apps/reader/public/.well-known/mdbase-app.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/reader/scripts/reader-manifest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const READER_TYPE_PACK_VERSION = "1.0.0-beta.4";
const projectRoot = resolve(import.meta.dirname, "..");
// Reader saves library views as mdbase.view records; this is the published
// mdbase-contracts provision, embedded byte-for-byte.
const viewPackPath = resolve(projectRoot, "mdbase", "packs", "mdbase.view-1.0.0.json");
const viewPackPath = resolve(projectRoot, "mdbase", "packs", "mdbase.view-1.0.1.json");
// Seed types belong to the collection once installed. Version 1 (pack beta.3) declared
// `type: { const: <name> }` and required `type`, which fails in collections whose
// settings.explicit_type_keys record the type elsewhere (such as `[mdbase_type]`, where
Expand Down
67 changes: 65 additions & 2 deletions apps/reader/scripts/reader-type-pack.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const application = await buildReaderManifest();
const current = application.provisions.type_packs.find(
(pack) => pack.manifest.id === "dev.mdbase.reader",
);
const viewPack = application.provisions.type_packs.find(
(pack) => pack.manifest.id === "mdbase.view",
);
const options = { installedBy: application.id };
// The JavaScript installer predates `upgrade_from`; see referenceInstallerProvision.
const provision = referenceInstallerProvision;
Expand All @@ -30,6 +33,12 @@ const releasedDigests = {
"1.0.0-beta.3": "sha256:712aa3d2ad5ca8719505b27c8c72f39fb9643660edbbeee3321e01ab53ef6938",
"1.0.0-beta.4": "sha256:f66f0b5e96df834c2aeab9aaddb4dc6eb6533111892a121ccb2b89ec15660dac",
};
// The vendored mdbase-contracts view pack, pinned the same way. 1.0.1 ships the version-2
// view starter (no pinned `type`, open top level) with `upgrade_from` the 1.0.0 starter;
// confirmed with the mdbase CLI's `packs assess`.
const releasedViewPackDigests = {
"1.0.1": "sha256:b32222bce5f16b01b87c34736b0e70bfad3583b5678557fa6c42ee706f7ef1d4",
};
// Exact bytes of the version-1 starter types released in beta.3, which beta.4 upgrades from.
const beta3SeedDigests = {
"types/reader-source.md":
Expand Down Expand Up @@ -108,8 +117,15 @@ test("Reader's new pack release preserves contract identities and capability pro
assert.equal(current.manifest.version, "1.0.0-beta.4");
assert.deepEqual(current.provides, legacy.provides);
assert.equal(application.requirements.capabilities.contract_version, 2);
const view = application.provisions.type_packs.find((pack) => pack.manifest.id === "mdbase.view");
assert.equal(view.manifest.version, "1.0.0");
assert.equal(viewPack.manifest.version, "1.0.1");
assert.deepEqual(
viewPack.provides.map(({ id, version }) => `${id}@${version}`),
["mdbase.view@1.0.0"],
);
assert.equal(
sha256(canonicalJson(viewPack.manifest)),
releasedViewPackDigests[viewPack.manifest.version],
);
});

test("the released pack digest stays immutable and is independent of deployment origin", async (t) => {
Expand Down Expand Up @@ -211,6 +227,53 @@ for (const typeKeys of ["[type]", "[mdbase_type]"]) {
for (const result of created)
assert.equal(result.valid, true, JSON.stringify(result.diagnostics));
});

test(`view records named by type are valid where explicit_type_keys is ${typeKeys}`, async (t) => {
// mdbase.view 1.0.1's version-2 starter keeps `match: { where: { type: view } }` for
// hand-written records. Connect's engine accepts `create({ type: "view" })` in a
// [mdbase_type] collection (checked with the mdbase CLI), but this JavaScript SDK's
// create still requires the match rule to hold, so write the record as the engine does.
const root = await collection(t);
await apply(root, viewPack, await assess(root, viewPack));
await writeFile(
join(root, "mdbase.yaml"),
`spec_version: 0.3.0\nsettings:\n explicit_type_keys: ${typeKeys}\n`,
);
const typeKey = typeKeys.slice(1, -1);
await mkdir(join(root, "views"));
await writeFile(
join(root, "views", "example.md"),
[
"---",
`${typeKey}: view`,
"id: reader.library.example",
"version: 1",
"name: Example",
// In a [mdbase_type] collection `type` is ordinary data the open top level accepts.
...(typeKey === "mdbase_type" ? ["type: article-journal"] : []),
"views:",
" - id: all",
" name: All",
"---",
"",
].join("\n"),
);
const opened = await Collection.open(root);
assert.ok(opened.collection, opened.error?.message);
try {
const validation = await opened.collection.validate("views/example.md");
assert.equal(validation.valid, true, JSON.stringify(validation.issues));
const view = await opened.collection.getContractView(
"views/example.md",
"mdbase.view",
"1.0.0",
);
assert.equal(view.valid, true);
assert.equal(view.view.name, "Example");
} finally {
await opened.collection.close();
}
});
}

test("reproduces the immutable beta.1 digest conflict without touching installed files", async (t) => {
Expand Down
14 changes: 9 additions & 5 deletions apps/reader/src/generated/mdbase-app.json

Large diffs are not rendered by default.