@plume-press/cli 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli.mjs +234 -458
- package/dist/local.mjs +15 -39
- package/dist/schema.d.ts +1 -7
- package/dist/schema.mjs +6 -19
- package/package.json +1 -1
package/dist/local.mjs
CHANGED
|
@@ -33315,13 +33315,6 @@ function named(value, path) {
|
|
|
33315
33315
|
);
|
|
33316
33316
|
}
|
|
33317
33317
|
function defineSchema(schema2) {
|
|
33318
|
-
return checkSchema(schema2);
|
|
33319
|
-
}
|
|
33320
|
-
function readStoredSchema(schema2, ignored = () => {
|
|
33321
|
-
}) {
|
|
33322
|
-
return checkSchema(schema2, ignored);
|
|
33323
|
-
}
|
|
33324
|
-
function checkSchema(schema2, ignoredPreviewPath) {
|
|
33325
33318
|
canonicalJson(schema2);
|
|
33326
33319
|
assert2(object2(schema2), "expected object");
|
|
33327
33320
|
allowedKeys(schema2, ["collections", "singletons"], "schema");
|
|
@@ -33455,16 +33448,11 @@ function checkSchema(schema2, ignoredPreviewPath) {
|
|
|
33455
33448
|
entities.add(entityName);
|
|
33456
33449
|
validateFields2(entity2.fields, entityName, false);
|
|
33457
33450
|
if ("previewPath" in entity2)
|
|
33458
|
-
|
|
33459
|
-
|
|
33460
|
-
|
|
33461
|
-
|
|
33462
|
-
|
|
33463
|
-
);
|
|
33464
|
-
} catch (error62) {
|
|
33465
|
-
if (!ignoredPreviewPath) throw error62;
|
|
33466
|
-
ignoredPreviewPath(error62.message);
|
|
33467
|
-
}
|
|
33451
|
+
validatePreviewPath(
|
|
33452
|
+
entityName,
|
|
33453
|
+
entity2.previewPath,
|
|
33454
|
+
isCollection ? entity2.fields : null
|
|
33455
|
+
);
|
|
33468
33456
|
}
|
|
33469
33457
|
return schema2;
|
|
33470
33458
|
}
|
|
@@ -33502,7 +33490,7 @@ function validatePreviewPath(entity2, path, fields) {
|
|
|
33502
33490
|
);
|
|
33503
33491
|
}
|
|
33504
33492
|
async function schemaHash(schema2) {
|
|
33505
|
-
|
|
33493
|
+
defineSchema(schema2);
|
|
33506
33494
|
const bytes2 = new TextEncoder().encode(
|
|
33507
33495
|
canonicalJson(schema2)
|
|
33508
33496
|
);
|
|
@@ -34120,7 +34108,7 @@ function deliverRecord(fields, data, context, prefix = []) {
|
|
|
34120
34108
|
const asset = context.asset(entry.id);
|
|
34121
34109
|
if (!asset || kind === "image" && !asset.mediaType.startsWith("image/"))
|
|
34122
34110
|
throw new TypeError("Unknown media asset.");
|
|
34123
|
-
const url2 = context.mediaUrl(path);
|
|
34111
|
+
const url2 = context.preferAssetUrl && asset.url ? asset.url : context.mediaUrl(path);
|
|
34124
34112
|
return kind === "image" ? {
|
|
34125
34113
|
url: url2,
|
|
34126
34114
|
width: asset.width,
|
|
@@ -34156,7 +34144,10 @@ function deliverRecord(fields, data, context, prefix = []) {
|
|
|
34156
34144
|
case "richText":
|
|
34157
34145
|
if (typeof value === "string")
|
|
34158
34146
|
result[field.name] = renderRichText(value, {
|
|
34159
|
-
imageUrl: (
|
|
34147
|
+
imageUrl: (image, index2) => {
|
|
34148
|
+
const asset = context.asset(image.id);
|
|
34149
|
+
return context.preferAssetUrl && asset?.url ? asset.url : context.mediaUrl([...path, index2]);
|
|
34150
|
+
}
|
|
34160
34151
|
});
|
|
34161
34152
|
break;
|
|
34162
34153
|
case "reference":
|
|
@@ -34180,6 +34171,9 @@ function defaultMediaUrl(input2) {
|
|
|
34180
34171
|
// packages/core/src/image-size.ts
|
|
34181
34172
|
var MAX_HEADER_BYTES = 1024 * 1024;
|
|
34182
34173
|
|
|
34174
|
+
// packages/core/src/media-object-key.ts
|
|
34175
|
+
var identifier = external_exports.uuidv7();
|
|
34176
|
+
|
|
34183
34177
|
// packages/local/src/index.ts
|
|
34184
34178
|
import { lstat, mkdir, open as openFile, rm } from "node:fs/promises";
|
|
34185
34179
|
import { join, resolve } from "node:path";
|
|
@@ -34216,23 +34210,6 @@ async function safePath(cwd, create2) {
|
|
|
34216
34210
|
);
|
|
34217
34211
|
return path;
|
|
34218
34212
|
}
|
|
34219
|
-
function addTimestamps(db) {
|
|
34220
|
-
const missing = () => !db.prepare("PRAGMA table_info(local_records)").all().some((column) => column.name === "created_at");
|
|
34221
|
-
if (!missing() && !db.prepare(
|
|
34222
|
-
"SELECT 1 FROM local_records WHERE created_at IS NULL OR updated_at IS NULL LIMIT 1"
|
|
34223
|
-
).get())
|
|
34224
|
-
return;
|
|
34225
|
-
transaction(db, () => {
|
|
34226
|
-
if (missing()) {
|
|
34227
|
-
db.exec("ALTER TABLE local_records ADD COLUMN created_at INTEGER");
|
|
34228
|
-
db.exec("ALTER TABLE local_records ADD COLUMN updated_at INTEGER");
|
|
34229
|
-
}
|
|
34230
|
-
const now = Date.now();
|
|
34231
|
-
db.prepare(
|
|
34232
|
-
"UPDATE local_records SET created_at = coalesce(created_at, ?), updated_at = coalesce(updated_at, created_at, ?) WHERE created_at IS NULL OR updated_at IS NULL"
|
|
34233
|
-
).run(now, now);
|
|
34234
|
-
});
|
|
34235
|
-
}
|
|
34236
34213
|
function meta3(db) {
|
|
34237
34214
|
return db.prepare("SELECT schema, revision FROM local_meta WHERE id = 1").get();
|
|
34238
34215
|
}
|
|
@@ -34438,7 +34415,6 @@ async function open2(path, expected) {
|
|
|
34438
34415
|
db.exec("PRAGMA busy_timeout = 5000");
|
|
34439
34416
|
const stored = meta3(db);
|
|
34440
34417
|
if (!stored) throw new Error("Local content database is not initialized.");
|
|
34441
|
-
addTimestamps(db);
|
|
34442
34418
|
let schema2 = defineSchema(JSON.parse(stored.schema));
|
|
34443
34419
|
if (expected && canonicalJson(schema2) !== canonicalJson(expected))
|
|
34444
34420
|
throw new Error(
|
|
@@ -34627,7 +34603,7 @@ async function openLocalStore(input2) {
|
|
|
34627
34603
|
"CREATE TABLE local_meta (id INTEGER PRIMARY KEY CHECK(id = 1), schema TEXT NOT NULL, revision INTEGER NOT NULL)"
|
|
34628
34604
|
);
|
|
34629
34605
|
db.exec(
|
|
34630
|
-
"CREATE TABLE local_records (collection TEXT NOT NULL, record_id TEXT NOT NULL, data TEXT NOT NULL, visibility TEXT NOT NULL CHECK(visibility IN ('draft', 'public')), created_at INTEGER, updated_at INTEGER, PRIMARY KEY(collection, record_id))"
|
|
34606
|
+
"CREATE TABLE local_records (collection TEXT NOT NULL, record_id TEXT NOT NULL, data TEXT NOT NULL, visibility TEXT NOT NULL CHECK(visibility IN ('draft', 'public')), created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL, PRIMARY KEY(collection, record_id))"
|
|
34631
34607
|
);
|
|
34632
34608
|
db.prepare(
|
|
34633
34609
|
"INSERT INTO local_meta (id, schema, revision) VALUES (1, ?, 0)"
|
package/dist/schema.d.ts
CHANGED
|
@@ -187,11 +187,6 @@ export type FieldIssue = {
|
|
|
187
187
|
export declare function canonicalJson(value: JsonValue): string;
|
|
188
188
|
/** Schema configuration is data only. Executable validators/transforms are unsupported. */
|
|
189
189
|
export declare function defineSchema<const S extends SchemaDefinition>(schema: S): S;
|
|
190
|
-
/** A schema stored with content, which an older Plume accepted: checked like
|
|
191
|
-
* `defineSchema`, except that a `previewPath` this version's grammar rejects is reported
|
|
192
|
-
* to `ignored` and left inert (`resolvePreviewPath` gives it no path), so that content
|
|
193
|
-
* stays readable. Defining or registering a schema stays strict. */
|
|
194
|
-
export declare function readStoredSchema(schema: unknown, ignored?: (problem: string) => void): SchemaDefinition;
|
|
195
190
|
/** A path on the Site's own website: one leading `/`, no backslash, whitespace or control
|
|
196
191
|
* character, at most 2048 characters, and still a path of the same site once a URL parser
|
|
197
192
|
* normalises it (`/./`, `..`), so no browser or parser reads it as another host. */
|
|
@@ -201,8 +196,7 @@ export declare function isLocalPath(path: unknown): path is string;
|
|
|
201
196
|
* Item ID (even when a Field is named `id`), `{<field>}` that text or slug Field's value,
|
|
202
197
|
* each trimmed and URL-encoded. The result is always an `isLocalPath`. */
|
|
203
198
|
export declare function resolvePreviewPath(entity: Collection | Singleton, recordId: string, data: JsonValue | undefined): string | null;
|
|
204
|
-
/** Hashes a schema
|
|
205
|
-
* block its identity (see `readStoredSchema`). */
|
|
199
|
+
/** Hashes a valid schema using its canonical JSON representation. */
|
|
206
200
|
export declare function schemaHash(schema: SchemaDefinition): Promise<string>;
|
|
207
201
|
/** Validates shape only; richText HTML requires sanitization at the write/render boundary.
|
|
208
202
|
* Slug uniqueness, reference targets and media `accept` need the whole content and are
|
package/dist/schema.mjs
CHANGED
|
@@ -83,13 +83,6 @@ function named(value, path) {
|
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
85
|
function defineSchema(schema) {
|
|
86
|
-
return checkSchema(schema);
|
|
87
|
-
}
|
|
88
|
-
function readStoredSchema(schema, ignored = () => {
|
|
89
|
-
}) {
|
|
90
|
-
return checkSchema(schema, ignored);
|
|
91
|
-
}
|
|
92
|
-
function checkSchema(schema, ignoredPreviewPath) {
|
|
93
86
|
canonicalJson(schema);
|
|
94
87
|
assert(object(schema), "expected object");
|
|
95
88
|
allowedKeys(schema, ["collections", "singletons"], "schema");
|
|
@@ -223,16 +216,11 @@ function checkSchema(schema, ignoredPreviewPath) {
|
|
|
223
216
|
entities.add(entityName);
|
|
224
217
|
validateFields2(entity.fields, entityName, false);
|
|
225
218
|
if ("previewPath" in entity)
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
);
|
|
232
|
-
} catch (error) {
|
|
233
|
-
if (!ignoredPreviewPath) throw error;
|
|
234
|
-
ignoredPreviewPath(error.message);
|
|
235
|
-
}
|
|
219
|
+
validatePreviewPath(
|
|
220
|
+
entityName,
|
|
221
|
+
entity.previewPath,
|
|
222
|
+
isCollection ? entity.fields : null
|
|
223
|
+
);
|
|
236
224
|
}
|
|
237
225
|
return schema;
|
|
238
226
|
}
|
|
@@ -296,7 +284,7 @@ function resolvePreviewPath(entity, recordId, data) {
|
|
|
296
284
|
return !missing && isLocalPath(path) ? path : null;
|
|
297
285
|
}
|
|
298
286
|
async function schemaHash(schema) {
|
|
299
|
-
|
|
287
|
+
defineSchema(schema);
|
|
300
288
|
const bytes = new TextEncoder().encode(
|
|
301
289
|
canonicalJson(schema)
|
|
302
290
|
);
|
|
@@ -574,7 +562,6 @@ export {
|
|
|
574
562
|
dropMissingReferences,
|
|
575
563
|
isLocalPath,
|
|
576
564
|
mediaAccepted,
|
|
577
|
-
readStoredSchema,
|
|
578
565
|
referenceIds,
|
|
579
566
|
resolvePreviewPath,
|
|
580
567
|
schemaHash,
|