mirror of
https://github.com/penpot/penpot.git
synced 2026-10-30 22:40:33 +00:00
The bucket of a storage object is decided by the reference that uses
it, not by the label that the object carries in the file. An object
serves exactly one bucket: when two references of different buckets
share an object, it is split in two, one per bucket. The touched-gc
check is per bucket, so a cross-bucket reference is invisible to it:
the object is marked for deletion and the delete fails on the foreign
key, which is what blocked the gc queue in production.
app.binfile.v3 (export): every reference is resolved before it is
written. An object of the wrong bucket is replaced by an alive object
with the same hash and the required bucket, or by a copy emitted in
the bundle when there is no twin. Objects marked for deletion are
readable now: app.storage got {:include-deleted? true} in get-object,
get-object-data and get-object-bytes, plus get-object-by-hash. A file
whose media thumbnail pointed to a deleted object could not be
exported at all.
app.binfile.v1 and v3 (import): the bucket is taken from the
reference, so an object shared by two buckets is stored once per
bucket. Objects that no reference uses are not persisted, and a
reference to an object that the bundle does not contain is rejected
instead of dangling or pointing to an object of another file.
library (the .penpot builder): object entries are validated and
encoded with the storage object schema, and :hash is optional, as in
the backend.
AI-assisted-by: deepseek-v4.1-flash
Penpot Library
A library that exposes a limited set of Penpot's features for programmatic use. Currently, it provides methods to build Penpot files in memory and export them as .penpot files (ZIP archives containing all the necessary data to import them into a Penpot application).
User Guide
How to install
pnpm add @penpot/library
Example of use
import * as penpot from "@penpot/library";
import { createWriteStream } from 'fs';
import { Writable } from "stream";
const context = penpot.createBuildContext();
context.addFile({name: "Test File 1"});
context.addPage({name: "Foo Page"});
context.addBoard({
name: "Foo Board",
x: 0,
y: 0,
width: 500,
height: 300,
});
context.closeBoard();
context.closeFile();
// Create a file stream to write the zip to
const output = createWriteStream('sample-stream.zip');
// Wrap Node's stream in a WHATWG WritableStream
const writable = Writable.toWeb(output);
await penpot.exportStream(context, writable);
Developer Guide
How to publish
Build the library:
./scripts/build
Login on npm:
npm login
Publish on npm:
npm publish --access public
License
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
Copyright (c) KALEIDOS SUBSIDIARY SL