@nuasite/cms-sidecar 0.59.0 → 0.61.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 +38 -0
- package/dist/cli.js +940 -699
- package/dist/types/index.d.ts +1 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/portable.d.ts +10 -0
- package/dist/types/portable.d.ts.map +1 -0
- package/dist/types/server.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
- package/src/index.ts +1 -24
- package/src/portable.ts +28 -0
- package/src/server.ts +55 -20
package/dist/cli.js
CHANGED
|
@@ -14888,17 +14888,17 @@ var require_visit = __commonJS((exports) => {
|
|
|
14888
14888
|
visit.BREAK = BREAK;
|
|
14889
14889
|
visit.SKIP = SKIP;
|
|
14890
14890
|
visit.REMOVE = REMOVE;
|
|
14891
|
-
function visit_(key, node, visitor,
|
|
14892
|
-
const ctrl = callVisitor(key, node, visitor,
|
|
14891
|
+
function visit_(key, node, visitor, path3) {
|
|
14892
|
+
const ctrl = callVisitor(key, node, visitor, path3);
|
|
14893
14893
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
14894
|
-
replaceNode(key,
|
|
14895
|
-
return visit_(key, ctrl, visitor,
|
|
14894
|
+
replaceNode(key, path3, ctrl);
|
|
14895
|
+
return visit_(key, ctrl, visitor, path3);
|
|
14896
14896
|
}
|
|
14897
14897
|
if (typeof ctrl !== "symbol") {
|
|
14898
14898
|
if (identity.isCollection(node)) {
|
|
14899
|
-
|
|
14899
|
+
path3 = Object.freeze(path3.concat(node));
|
|
14900
14900
|
for (let i = 0;i < node.items.length; ++i) {
|
|
14901
|
-
const ci = visit_(i, node.items[i], visitor,
|
|
14901
|
+
const ci = visit_(i, node.items[i], visitor, path3);
|
|
14902
14902
|
if (typeof ci === "number")
|
|
14903
14903
|
i = ci - 1;
|
|
14904
14904
|
else if (ci === BREAK)
|
|
@@ -14909,13 +14909,13 @@ var require_visit = __commonJS((exports) => {
|
|
|
14909
14909
|
}
|
|
14910
14910
|
}
|
|
14911
14911
|
} else if (identity.isPair(node)) {
|
|
14912
|
-
|
|
14913
|
-
const ck = visit_("key", node.key, visitor,
|
|
14912
|
+
path3 = Object.freeze(path3.concat(node));
|
|
14913
|
+
const ck = visit_("key", node.key, visitor, path3);
|
|
14914
14914
|
if (ck === BREAK)
|
|
14915
14915
|
return BREAK;
|
|
14916
14916
|
else if (ck === REMOVE)
|
|
14917
14917
|
node.key = null;
|
|
14918
|
-
const cv = visit_("value", node.value, visitor,
|
|
14918
|
+
const cv = visit_("value", node.value, visitor, path3);
|
|
14919
14919
|
if (cv === BREAK)
|
|
14920
14920
|
return BREAK;
|
|
14921
14921
|
else if (cv === REMOVE)
|
|
@@ -14936,17 +14936,17 @@ var require_visit = __commonJS((exports) => {
|
|
|
14936
14936
|
visitAsync.BREAK = BREAK;
|
|
14937
14937
|
visitAsync.SKIP = SKIP;
|
|
14938
14938
|
visitAsync.REMOVE = REMOVE;
|
|
14939
|
-
async function visitAsync_(key, node, visitor,
|
|
14940
|
-
const ctrl = await callVisitor(key, node, visitor,
|
|
14939
|
+
async function visitAsync_(key, node, visitor, path3) {
|
|
14940
|
+
const ctrl = await callVisitor(key, node, visitor, path3);
|
|
14941
14941
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
14942
|
-
replaceNode(key,
|
|
14943
|
-
return visitAsync_(key, ctrl, visitor,
|
|
14942
|
+
replaceNode(key, path3, ctrl);
|
|
14943
|
+
return visitAsync_(key, ctrl, visitor, path3);
|
|
14944
14944
|
}
|
|
14945
14945
|
if (typeof ctrl !== "symbol") {
|
|
14946
14946
|
if (identity.isCollection(node)) {
|
|
14947
|
-
|
|
14947
|
+
path3 = Object.freeze(path3.concat(node));
|
|
14948
14948
|
for (let i = 0;i < node.items.length; ++i) {
|
|
14949
|
-
const ci = await visitAsync_(i, node.items[i], visitor,
|
|
14949
|
+
const ci = await visitAsync_(i, node.items[i], visitor, path3);
|
|
14950
14950
|
if (typeof ci === "number")
|
|
14951
14951
|
i = ci - 1;
|
|
14952
14952
|
else if (ci === BREAK)
|
|
@@ -14957,13 +14957,13 @@ var require_visit = __commonJS((exports) => {
|
|
|
14957
14957
|
}
|
|
14958
14958
|
}
|
|
14959
14959
|
} else if (identity.isPair(node)) {
|
|
14960
|
-
|
|
14961
|
-
const ck = await visitAsync_("key", node.key, visitor,
|
|
14960
|
+
path3 = Object.freeze(path3.concat(node));
|
|
14961
|
+
const ck = await visitAsync_("key", node.key, visitor, path3);
|
|
14962
14962
|
if (ck === BREAK)
|
|
14963
14963
|
return BREAK;
|
|
14964
14964
|
else if (ck === REMOVE)
|
|
14965
14965
|
node.key = null;
|
|
14966
|
-
const cv = await visitAsync_("value", node.value, visitor,
|
|
14966
|
+
const cv = await visitAsync_("value", node.value, visitor, path3);
|
|
14967
14967
|
if (cv === BREAK)
|
|
14968
14968
|
return BREAK;
|
|
14969
14969
|
else if (cv === REMOVE)
|
|
@@ -14990,23 +14990,23 @@ var require_visit = __commonJS((exports) => {
|
|
|
14990
14990
|
}
|
|
14991
14991
|
return visitor;
|
|
14992
14992
|
}
|
|
14993
|
-
function callVisitor(key, node, visitor,
|
|
14993
|
+
function callVisitor(key, node, visitor, path3) {
|
|
14994
14994
|
if (typeof visitor === "function")
|
|
14995
|
-
return visitor(key, node,
|
|
14995
|
+
return visitor(key, node, path3);
|
|
14996
14996
|
if (identity.isMap(node))
|
|
14997
|
-
return visitor.Map?.(key, node,
|
|
14997
|
+
return visitor.Map?.(key, node, path3);
|
|
14998
14998
|
if (identity.isSeq(node))
|
|
14999
|
-
return visitor.Seq?.(key, node,
|
|
14999
|
+
return visitor.Seq?.(key, node, path3);
|
|
15000
15000
|
if (identity.isPair(node))
|
|
15001
|
-
return visitor.Pair?.(key, node,
|
|
15001
|
+
return visitor.Pair?.(key, node, path3);
|
|
15002
15002
|
if (identity.isScalar(node))
|
|
15003
|
-
return visitor.Scalar?.(key, node,
|
|
15003
|
+
return visitor.Scalar?.(key, node, path3);
|
|
15004
15004
|
if (identity.isAlias(node))
|
|
15005
|
-
return visitor.Alias?.(key, node,
|
|
15005
|
+
return visitor.Alias?.(key, node, path3);
|
|
15006
15006
|
return;
|
|
15007
15007
|
}
|
|
15008
|
-
function replaceNode(key,
|
|
15009
|
-
const parent =
|
|
15008
|
+
function replaceNode(key, path3, node) {
|
|
15009
|
+
const parent = path3[path3.length - 1];
|
|
15010
15010
|
if (identity.isCollection(parent)) {
|
|
15011
15011
|
parent.items[key] = node;
|
|
15012
15012
|
} else if (identity.isPair(parent)) {
|
|
@@ -15563,10 +15563,10 @@ var require_Collection = __commonJS((exports) => {
|
|
|
15563
15563
|
var createNode = require_createNode();
|
|
15564
15564
|
var identity = require_identity();
|
|
15565
15565
|
var Node = require_Node();
|
|
15566
|
-
function collectionFromPath(schema,
|
|
15566
|
+
function collectionFromPath(schema, path3, value) {
|
|
15567
15567
|
let v = value;
|
|
15568
|
-
for (let i =
|
|
15569
|
-
const k =
|
|
15568
|
+
for (let i = path3.length - 1;i >= 0; --i) {
|
|
15569
|
+
const k = path3[i];
|
|
15570
15570
|
if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
|
|
15571
15571
|
const a = [];
|
|
15572
15572
|
a[k] = v;
|
|
@@ -15585,7 +15585,7 @@ var require_Collection = __commonJS((exports) => {
|
|
|
15585
15585
|
sourceObjects: new Map
|
|
15586
15586
|
});
|
|
15587
15587
|
}
|
|
15588
|
-
var isEmptyPath = (
|
|
15588
|
+
var isEmptyPath = (path3) => path3 == null || typeof path3 === "object" && !!path3[Symbol.iterator]().next().done;
|
|
15589
15589
|
|
|
15590
15590
|
class Collection extends Node.NodeBase {
|
|
15591
15591
|
constructor(type, schema) {
|
|
@@ -15606,11 +15606,11 @@ var require_Collection = __commonJS((exports) => {
|
|
|
15606
15606
|
copy.range = this.range.slice();
|
|
15607
15607
|
return copy;
|
|
15608
15608
|
}
|
|
15609
|
-
addIn(
|
|
15610
|
-
if (isEmptyPath(
|
|
15609
|
+
addIn(path3, value) {
|
|
15610
|
+
if (isEmptyPath(path3))
|
|
15611
15611
|
this.add(value);
|
|
15612
15612
|
else {
|
|
15613
|
-
const [key, ...rest] =
|
|
15613
|
+
const [key, ...rest] = path3;
|
|
15614
15614
|
const node = this.get(key, true);
|
|
15615
15615
|
if (identity.isCollection(node))
|
|
15616
15616
|
node.addIn(rest, value);
|
|
@@ -15620,8 +15620,8 @@ var require_Collection = __commonJS((exports) => {
|
|
|
15620
15620
|
throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
15621
15621
|
}
|
|
15622
15622
|
}
|
|
15623
|
-
deleteIn(
|
|
15624
|
-
const [key, ...rest] =
|
|
15623
|
+
deleteIn(path3) {
|
|
15624
|
+
const [key, ...rest] = path3;
|
|
15625
15625
|
if (rest.length === 0)
|
|
15626
15626
|
return this.delete(key);
|
|
15627
15627
|
const node = this.get(key, true);
|
|
@@ -15630,8 +15630,8 @@ var require_Collection = __commonJS((exports) => {
|
|
|
15630
15630
|
else
|
|
15631
15631
|
throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
15632
15632
|
}
|
|
15633
|
-
getIn(
|
|
15634
|
-
const [key, ...rest] =
|
|
15633
|
+
getIn(path3, keepScalar) {
|
|
15634
|
+
const [key, ...rest] = path3;
|
|
15635
15635
|
const node = this.get(key, true);
|
|
15636
15636
|
if (rest.length === 0)
|
|
15637
15637
|
return !keepScalar && identity.isScalar(node) ? node.value : node;
|
|
@@ -15646,15 +15646,15 @@ var require_Collection = __commonJS((exports) => {
|
|
|
15646
15646
|
return n == null || allowScalar && identity.isScalar(n) && n.value == null && !n.commentBefore && !n.comment && !n.tag;
|
|
15647
15647
|
});
|
|
15648
15648
|
}
|
|
15649
|
-
hasIn(
|
|
15650
|
-
const [key, ...rest] =
|
|
15649
|
+
hasIn(path3) {
|
|
15650
|
+
const [key, ...rest] = path3;
|
|
15651
15651
|
if (rest.length === 0)
|
|
15652
15652
|
return this.has(key);
|
|
15653
15653
|
const node = this.get(key, true);
|
|
15654
15654
|
return identity.isCollection(node) ? node.hasIn(rest) : false;
|
|
15655
15655
|
}
|
|
15656
|
-
setIn(
|
|
15657
|
-
const [key, ...rest] =
|
|
15656
|
+
setIn(path3, value) {
|
|
15657
|
+
const [key, ...rest] = path3;
|
|
15658
15658
|
if (rest.length === 0) {
|
|
15659
15659
|
this.set(key, value);
|
|
15660
15660
|
} else {
|
|
@@ -18044,9 +18044,9 @@ var require_Document = __commonJS((exports) => {
|
|
|
18044
18044
|
if (assertCollection(this.contents))
|
|
18045
18045
|
this.contents.add(value);
|
|
18046
18046
|
}
|
|
18047
|
-
addIn(
|
|
18047
|
+
addIn(path3, value) {
|
|
18048
18048
|
if (assertCollection(this.contents))
|
|
18049
|
-
this.contents.addIn(
|
|
18049
|
+
this.contents.addIn(path3, value);
|
|
18050
18050
|
}
|
|
18051
18051
|
createAlias(node, name) {
|
|
18052
18052
|
if (!node.anchor) {
|
|
@@ -18095,30 +18095,30 @@ var require_Document = __commonJS((exports) => {
|
|
|
18095
18095
|
delete(key) {
|
|
18096
18096
|
return assertCollection(this.contents) ? this.contents.delete(key) : false;
|
|
18097
18097
|
}
|
|
18098
|
-
deleteIn(
|
|
18099
|
-
if (Collection.isEmptyPath(
|
|
18098
|
+
deleteIn(path3) {
|
|
18099
|
+
if (Collection.isEmptyPath(path3)) {
|
|
18100
18100
|
if (this.contents == null)
|
|
18101
18101
|
return false;
|
|
18102
18102
|
this.contents = null;
|
|
18103
18103
|
return true;
|
|
18104
18104
|
}
|
|
18105
|
-
return assertCollection(this.contents) ? this.contents.deleteIn(
|
|
18105
|
+
return assertCollection(this.contents) ? this.contents.deleteIn(path3) : false;
|
|
18106
18106
|
}
|
|
18107
18107
|
get(key, keepScalar) {
|
|
18108
18108
|
return identity.isCollection(this.contents) ? this.contents.get(key, keepScalar) : undefined;
|
|
18109
18109
|
}
|
|
18110
|
-
getIn(
|
|
18111
|
-
if (Collection.isEmptyPath(
|
|
18110
|
+
getIn(path3, keepScalar) {
|
|
18111
|
+
if (Collection.isEmptyPath(path3))
|
|
18112
18112
|
return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
|
|
18113
|
-
return identity.isCollection(this.contents) ? this.contents.getIn(
|
|
18113
|
+
return identity.isCollection(this.contents) ? this.contents.getIn(path3, keepScalar) : undefined;
|
|
18114
18114
|
}
|
|
18115
18115
|
has(key) {
|
|
18116
18116
|
return identity.isCollection(this.contents) ? this.contents.has(key) : false;
|
|
18117
18117
|
}
|
|
18118
|
-
hasIn(
|
|
18119
|
-
if (Collection.isEmptyPath(
|
|
18118
|
+
hasIn(path3) {
|
|
18119
|
+
if (Collection.isEmptyPath(path3))
|
|
18120
18120
|
return this.contents !== undefined;
|
|
18121
|
-
return identity.isCollection(this.contents) ? this.contents.hasIn(
|
|
18121
|
+
return identity.isCollection(this.contents) ? this.contents.hasIn(path3) : false;
|
|
18122
18122
|
}
|
|
18123
18123
|
set(key, value) {
|
|
18124
18124
|
if (this.contents == null) {
|
|
@@ -18127,13 +18127,13 @@ var require_Document = __commonJS((exports) => {
|
|
|
18127
18127
|
this.contents.set(key, value);
|
|
18128
18128
|
}
|
|
18129
18129
|
}
|
|
18130
|
-
setIn(
|
|
18131
|
-
if (Collection.isEmptyPath(
|
|
18130
|
+
setIn(path3, value) {
|
|
18131
|
+
if (Collection.isEmptyPath(path3)) {
|
|
18132
18132
|
this.contents = value;
|
|
18133
18133
|
} else if (this.contents == null) {
|
|
18134
|
-
this.contents = Collection.collectionFromPath(this.schema, Array.from(
|
|
18134
|
+
this.contents = Collection.collectionFromPath(this.schema, Array.from(path3), value);
|
|
18135
18135
|
} else if (assertCollection(this.contents)) {
|
|
18136
|
-
this.contents.setIn(
|
|
18136
|
+
this.contents.setIn(path3, value);
|
|
18137
18137
|
}
|
|
18138
18138
|
}
|
|
18139
18139
|
setSchema(version, options = {}) {
|
|
@@ -20027,9 +20027,9 @@ var require_cst_visit = __commonJS((exports) => {
|
|
|
20027
20027
|
visit.BREAK = BREAK;
|
|
20028
20028
|
visit.SKIP = SKIP;
|
|
20029
20029
|
visit.REMOVE = REMOVE;
|
|
20030
|
-
visit.itemAtPath = (cst,
|
|
20030
|
+
visit.itemAtPath = (cst, path3) => {
|
|
20031
20031
|
let item = cst;
|
|
20032
|
-
for (const [field, index] of
|
|
20032
|
+
for (const [field, index] of path3) {
|
|
20033
20033
|
const tok = item?.[field];
|
|
20034
20034
|
if (tok && "items" in tok) {
|
|
20035
20035
|
item = tok.items[index];
|
|
@@ -20038,23 +20038,23 @@ var require_cst_visit = __commonJS((exports) => {
|
|
|
20038
20038
|
}
|
|
20039
20039
|
return item;
|
|
20040
20040
|
};
|
|
20041
|
-
visit.parentCollection = (cst,
|
|
20042
|
-
const parent = visit.itemAtPath(cst,
|
|
20043
|
-
const field =
|
|
20041
|
+
visit.parentCollection = (cst, path3) => {
|
|
20042
|
+
const parent = visit.itemAtPath(cst, path3.slice(0, -1));
|
|
20043
|
+
const field = path3[path3.length - 1][0];
|
|
20044
20044
|
const coll = parent?.[field];
|
|
20045
20045
|
if (coll && "items" in coll)
|
|
20046
20046
|
return coll;
|
|
20047
20047
|
throw new Error("Parent collection not found");
|
|
20048
20048
|
};
|
|
20049
|
-
function _visit(
|
|
20050
|
-
let ctrl = visitor(item,
|
|
20049
|
+
function _visit(path3, item, visitor) {
|
|
20050
|
+
let ctrl = visitor(item, path3);
|
|
20051
20051
|
if (typeof ctrl === "symbol")
|
|
20052
20052
|
return ctrl;
|
|
20053
20053
|
for (const field of ["key", "value"]) {
|
|
20054
20054
|
const token = item[field];
|
|
20055
20055
|
if (token && "items" in token) {
|
|
20056
20056
|
for (let i = 0;i < token.items.length; ++i) {
|
|
20057
|
-
const ci = _visit(Object.freeze(
|
|
20057
|
+
const ci = _visit(Object.freeze(path3.concat([[field, i]])), token.items[i], visitor);
|
|
20058
20058
|
if (typeof ci === "number")
|
|
20059
20059
|
i = ci - 1;
|
|
20060
20060
|
else if (ci === BREAK)
|
|
@@ -20065,10 +20065,10 @@ var require_cst_visit = __commonJS((exports) => {
|
|
|
20065
20065
|
}
|
|
20066
20066
|
}
|
|
20067
20067
|
if (typeof ctrl === "function" && field === "key")
|
|
20068
|
-
ctrl = ctrl(item,
|
|
20068
|
+
ctrl = ctrl(item, path3);
|
|
20069
20069
|
}
|
|
20070
20070
|
}
|
|
20071
|
-
return typeof ctrl === "function" ? ctrl(item,
|
|
20071
|
+
return typeof ctrl === "function" ? ctrl(item, path3) : ctrl;
|
|
20072
20072
|
}
|
|
20073
20073
|
exports.visit = visit;
|
|
20074
20074
|
});
|
|
@@ -21337,14 +21337,14 @@ var require_parser = __commonJS((exports) => {
|
|
|
21337
21337
|
case "scalar":
|
|
21338
21338
|
case "single-quoted-scalar":
|
|
21339
21339
|
case "double-quoted-scalar": {
|
|
21340
|
-
const
|
|
21340
|
+
const fs3 = this.flowScalar(this.type);
|
|
21341
21341
|
if (atNextItem || it.value) {
|
|
21342
|
-
map.items.push({ start, key:
|
|
21342
|
+
map.items.push({ start, key: fs3, sep: [] });
|
|
21343
21343
|
this.onKeyLine = true;
|
|
21344
21344
|
} else if (it.sep) {
|
|
21345
|
-
this.stack.push(
|
|
21345
|
+
this.stack.push(fs3);
|
|
21346
21346
|
} else {
|
|
21347
|
-
Object.assign(it, { key:
|
|
21347
|
+
Object.assign(it, { key: fs3, sep: [] });
|
|
21348
21348
|
this.onKeyLine = true;
|
|
21349
21349
|
}
|
|
21350
21350
|
return;
|
|
@@ -21472,13 +21472,13 @@ var require_parser = __commonJS((exports) => {
|
|
|
21472
21472
|
case "scalar":
|
|
21473
21473
|
case "single-quoted-scalar":
|
|
21474
21474
|
case "double-quoted-scalar": {
|
|
21475
|
-
const
|
|
21475
|
+
const fs3 = this.flowScalar(this.type);
|
|
21476
21476
|
if (!it || it.value)
|
|
21477
|
-
fc.items.push({ start: [], key:
|
|
21477
|
+
fc.items.push({ start: [], key: fs3, sep: [] });
|
|
21478
21478
|
else if (it.sep)
|
|
21479
|
-
this.stack.push(
|
|
21479
|
+
this.stack.push(fs3);
|
|
21480
21480
|
else
|
|
21481
|
-
Object.assign(it, { key:
|
|
21481
|
+
Object.assign(it, { key: fs3, sep: [] });
|
|
21482
21482
|
return;
|
|
21483
21483
|
}
|
|
21484
21484
|
case "flow-map-end":
|
|
@@ -21780,6 +21780,424 @@ var require_dist = __commonJS((exports) => {
|
|
|
21780
21780
|
exports.visitAsync = visit.visitAsync;
|
|
21781
21781
|
});
|
|
21782
21782
|
|
|
21783
|
+
// ../cms-core/src/fs/node-fs.ts
|
|
21784
|
+
import fs from "fs/promises";
|
|
21785
|
+
import path from "path";
|
|
21786
|
+
|
|
21787
|
+
// ../cms-core/src/fs/glob.ts
|
|
21788
|
+
class UnreadableDirectoryError extends Error {
|
|
21789
|
+
directory;
|
|
21790
|
+
code;
|
|
21791
|
+
constructor(directory, code, options) {
|
|
21792
|
+
super(`Cannot read directory "${directory}" (${code})`, options);
|
|
21793
|
+
this.name = "UnreadableDirectoryError";
|
|
21794
|
+
this.directory = directory;
|
|
21795
|
+
this.code = code;
|
|
21796
|
+
}
|
|
21797
|
+
}
|
|
21798
|
+
function globToRegExp(glob) {
|
|
21799
|
+
let re = "";
|
|
21800
|
+
for (let i = 0;i < glob.length; i++) {
|
|
21801
|
+
const c = glob[i];
|
|
21802
|
+
if (c === "*") {
|
|
21803
|
+
if (glob[i + 1] === "*") {
|
|
21804
|
+
re += ".*";
|
|
21805
|
+
i++;
|
|
21806
|
+
if (glob[i + 1] === "/")
|
|
21807
|
+
i++;
|
|
21808
|
+
} else {
|
|
21809
|
+
re += "[^/]*";
|
|
21810
|
+
}
|
|
21811
|
+
} else if (c === "?") {
|
|
21812
|
+
re += "[^/]";
|
|
21813
|
+
} else if (c === "{") {
|
|
21814
|
+
const end = glob.indexOf("}", i);
|
|
21815
|
+
if (end === -1) {
|
|
21816
|
+
re += "\\{";
|
|
21817
|
+
} else {
|
|
21818
|
+
const opts = glob.slice(i + 1, end).split(",").map((s) => s.replace(/[.+^${}()|[\]\\]/g, "\\$&"));
|
|
21819
|
+
re += `(?:${opts.join("|")})`;
|
|
21820
|
+
i = end;
|
|
21821
|
+
}
|
|
21822
|
+
} else if (".+^$()|[]\\".includes(c)) {
|
|
21823
|
+
re += `\\${c}`;
|
|
21824
|
+
} else {
|
|
21825
|
+
re += c;
|
|
21826
|
+
}
|
|
21827
|
+
}
|
|
21828
|
+
return new RegExp(`^${re}$`);
|
|
21829
|
+
}
|
|
21830
|
+
function globMayMatchUnder(glob, dir) {
|
|
21831
|
+
if (/\{[^}]*\//.test(glob))
|
|
21832
|
+
return true;
|
|
21833
|
+
const segments = glob.split("/").filter((segment) => segment !== "" && segment !== ".");
|
|
21834
|
+
const dirs = dir.split("/").filter((segment) => segment !== "" && segment !== ".");
|
|
21835
|
+
const reaches = (i, j) => {
|
|
21836
|
+
if (j === dirs.length)
|
|
21837
|
+
return i < segments.length;
|
|
21838
|
+
if (i >= segments.length)
|
|
21839
|
+
return false;
|
|
21840
|
+
if (segments[i].includes("**"))
|
|
21841
|
+
return true;
|
|
21842
|
+
return globToRegExp(segments[i]).test(dirs[j]) && reaches(i + 1, j + 1);
|
|
21843
|
+
};
|
|
21844
|
+
return reaches(0, 0);
|
|
21845
|
+
}
|
|
21846
|
+
|
|
21847
|
+
// ../cms-core/src/fs/node-fs.ts
|
|
21848
|
+
function resolveWithinRoot(root, filePath) {
|
|
21849
|
+
const resolvedRoot = path.resolve(root);
|
|
21850
|
+
const isAbsoluteFs = filePath.startsWith(resolvedRoot);
|
|
21851
|
+
const normalizedPath = !isAbsoluteFs && filePath.startsWith("/") ? filePath.slice(1) : filePath;
|
|
21852
|
+
const fullPath = path.isAbsolute(normalizedPath) ? path.resolve(normalizedPath) : path.resolve(resolvedRoot, normalizedPath);
|
|
21853
|
+
if (!fullPath.startsWith(resolvedRoot + path.sep) && fullPath !== resolvedRoot) {
|
|
21854
|
+
throw new Error(`Path traversal detected: ${filePath}`);
|
|
21855
|
+
}
|
|
21856
|
+
return fullPath;
|
|
21857
|
+
}
|
|
21858
|
+
function isNodeError(error) {
|
|
21859
|
+
return error instanceof Error && "code" in error;
|
|
21860
|
+
}
|
|
21861
|
+
var isWithin = (root, abs) => abs === root || abs.startsWith(root.endsWith(path.sep) ? root : root + path.sep);
|
|
21862
|
+
var relativeTo = (absRoot, abs) => path.relative(absRoot, abs).split(path.sep).join("/") || ".";
|
|
21863
|
+
async function walkFiles(walk, absDir, linked) {
|
|
21864
|
+
if (linked.size > 0 && walk.linkedDirectoriesLeft !== undefined && walk.linkedDirectoriesLeft-- <= 0) {
|
|
21865
|
+
throw new Error(`More than ${walk.maxLinkedDirectories} directories to list behind symbolic links`);
|
|
21866
|
+
}
|
|
21867
|
+
let dirEntries;
|
|
21868
|
+
try {
|
|
21869
|
+
dirEntries = await fs.readdir(absDir, { withFileTypes: true });
|
|
21870
|
+
} catch (error) {
|
|
21871
|
+
if (!isNodeError(error))
|
|
21872
|
+
throw error;
|
|
21873
|
+
if (error.code === "ENOENT" || error.code === "ENOTDIR")
|
|
21874
|
+
return [];
|
|
21875
|
+
throw new UnreadableDirectoryError(relativeTo(walk.absRoot, absDir), error.code ?? "unknown error", { cause: error });
|
|
21876
|
+
}
|
|
21877
|
+
const out = [];
|
|
21878
|
+
for (const entry of dirEntries) {
|
|
21879
|
+
const abs = path.join(absDir, entry.name);
|
|
21880
|
+
let isDirectory = entry.isDirectory();
|
|
21881
|
+
let isFile = entry.isFile();
|
|
21882
|
+
let within = linked;
|
|
21883
|
+
let real = null;
|
|
21884
|
+
if (walk.followSymlinks && entry.isSymbolicLink()) {
|
|
21885
|
+
const target = await fs.stat(abs).catch(() => null);
|
|
21886
|
+
real = target?.isDirectory() ? await fs.realpath(abs).catch(() => abs) : null;
|
|
21887
|
+
isFile = target?.isFile() ?? false;
|
|
21888
|
+
isDirectory = real !== null && !linked.has(real);
|
|
21889
|
+
if (real !== null)
|
|
21890
|
+
within = new Set([...linked, real]);
|
|
21891
|
+
}
|
|
21892
|
+
if (isDirectory) {
|
|
21893
|
+
if (walk.skip(relativeTo(walk.absRoot, abs)))
|
|
21894
|
+
continue;
|
|
21895
|
+
if (!walk.mayHold(relativeTo(walk.absRoot, abs)))
|
|
21896
|
+
continue;
|
|
21897
|
+
if (real !== null && !isWithin(walk.realRoot, real)) {
|
|
21898
|
+
throw new Error(`Symbolic link "${relativeTo(walk.absRoot, abs)}" leads out of the project root`);
|
|
21899
|
+
}
|
|
21900
|
+
out.push(...await walkFiles(walk, abs, within));
|
|
21901
|
+
} else if (isFile) {
|
|
21902
|
+
out.push(relativeTo(walk.absRoot, abs));
|
|
21903
|
+
}
|
|
21904
|
+
}
|
|
21905
|
+
return out;
|
|
21906
|
+
}
|
|
21907
|
+
function staticPrefixDir(pattern) {
|
|
21908
|
+
const segments = pattern.split("/");
|
|
21909
|
+
const staticSegments = [];
|
|
21910
|
+
for (const segment of segments) {
|
|
21911
|
+
if (/[*?{}[\]]/.test(segment))
|
|
21912
|
+
break;
|
|
21913
|
+
staticSegments.push(segment);
|
|
21914
|
+
}
|
|
21915
|
+
if (staticSegments.length === segments.length) {
|
|
21916
|
+
staticSegments.pop();
|
|
21917
|
+
}
|
|
21918
|
+
return staticSegments.join("/");
|
|
21919
|
+
}
|
|
21920
|
+
async function writeAtomically(fullPath, content) {
|
|
21921
|
+
await fs.mkdir(path.dirname(fullPath), { recursive: true });
|
|
21922
|
+
const tempPath = `${fullPath}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
21923
|
+
try {
|
|
21924
|
+
await fs.writeFile(tempPath, content);
|
|
21925
|
+
await fs.rename(tempPath, fullPath);
|
|
21926
|
+
} catch (error) {
|
|
21927
|
+
await fs.rm(tempPath, { force: true });
|
|
21928
|
+
throw error;
|
|
21929
|
+
}
|
|
21930
|
+
}
|
|
21931
|
+
function createNodeFs(root) {
|
|
21932
|
+
const resolvedRoot = path.resolve(root);
|
|
21933
|
+
const resolve = (p) => resolveWithinRoot(resolvedRoot, p);
|
|
21934
|
+
return {
|
|
21935
|
+
async readFile(filePath) {
|
|
21936
|
+
return fs.readFile(resolve(filePath), "utf-8");
|
|
21937
|
+
},
|
|
21938
|
+
async readBytes(filePath) {
|
|
21939
|
+
return fs.readFile(resolve(filePath));
|
|
21940
|
+
},
|
|
21941
|
+
async writeFile(filePath, content) {
|
|
21942
|
+
await writeAtomically(resolve(filePath), content);
|
|
21943
|
+
},
|
|
21944
|
+
async writeBytes(filePath, content) {
|
|
21945
|
+
await writeAtomically(resolve(filePath), content);
|
|
21946
|
+
},
|
|
21947
|
+
async rename(from, to) {
|
|
21948
|
+
const fullTo = resolve(to);
|
|
21949
|
+
await fs.mkdir(path.dirname(fullTo), { recursive: true });
|
|
21950
|
+
await fs.rename(resolve(from), fullTo);
|
|
21951
|
+
},
|
|
21952
|
+
async remove(filePath) {
|
|
21953
|
+
await fs.rm(resolve(filePath), { force: true });
|
|
21954
|
+
},
|
|
21955
|
+
async exists(filePath) {
|
|
21956
|
+
try {
|
|
21957
|
+
await fs.access(resolve(filePath));
|
|
21958
|
+
return true;
|
|
21959
|
+
} catch {
|
|
21960
|
+
return false;
|
|
21961
|
+
}
|
|
21962
|
+
},
|
|
21963
|
+
async list(dir) {
|
|
21964
|
+
try {
|
|
21965
|
+
const entries = await fs.readdir(resolve(dir), { withFileTypes: true });
|
|
21966
|
+
return entries.map((entry) => ({ name: entry.name, isDirectory: entry.isDirectory() }));
|
|
21967
|
+
} catch (error) {
|
|
21968
|
+
if (isNodeError(error) && error.code === "ENOENT")
|
|
21969
|
+
return [];
|
|
21970
|
+
throw error;
|
|
21971
|
+
}
|
|
21972
|
+
},
|
|
21973
|
+
async glob(pattern, options) {
|
|
21974
|
+
const baseRel = staticPrefixDir(pattern);
|
|
21975
|
+
const absBase = resolve(baseRel);
|
|
21976
|
+
const matcher = globToRegExp(pattern);
|
|
21977
|
+
const followSymlinks = options?.followSymlinks ?? false;
|
|
21978
|
+
const walk = {
|
|
21979
|
+
absRoot: resolvedRoot,
|
|
21980
|
+
mayHold: (dir) => globMayMatchUnder(pattern, dir),
|
|
21981
|
+
skip: options?.skipDirectory ?? (() => false),
|
|
21982
|
+
followSymlinks,
|
|
21983
|
+
realRoot: followSymlinks ? await fs.realpath(resolvedRoot).catch(() => resolvedRoot) : resolvedRoot,
|
|
21984
|
+
maxLinkedDirectories: options?.maxLinkedDirectories,
|
|
21985
|
+
linkedDirectoriesLeft: options?.maxLinkedDirectories
|
|
21986
|
+
};
|
|
21987
|
+
if (!walk.mayHold(relativeTo(resolvedRoot, absBase)))
|
|
21988
|
+
return [];
|
|
21989
|
+
const files = await walkFiles(walk, absBase, new Set);
|
|
21990
|
+
return files.filter((rel) => matcher.test(rel));
|
|
21991
|
+
},
|
|
21992
|
+
async stat(filePath) {
|
|
21993
|
+
const s = await fs.stat(resolve(filePath));
|
|
21994
|
+
return { mtimeMs: s.mtimeMs, size: s.size };
|
|
21995
|
+
}
|
|
21996
|
+
};
|
|
21997
|
+
}
|
|
21998
|
+
// ../cms-core/src/media/local.ts
|
|
21999
|
+
import { randomUUID } from "crypto";
|
|
22000
|
+
import fs2 from "fs/promises";
|
|
22001
|
+
import path2 from "path";
|
|
22002
|
+
|
|
22003
|
+
// ../cms-core/src/media/errors.ts
|
|
22004
|
+
var MEDIA_INVALID_ID = "Invalid media id";
|
|
22005
|
+
var MEDIA_INVALID_FOLDER = "Invalid folder name";
|
|
22006
|
+
var MEDIA_NOT_FOUND = "Media file not found";
|
|
22007
|
+
function mediaErrorStatus(error) {
|
|
22008
|
+
if (error === MEDIA_INVALID_ID || error === MEDIA_INVALID_FOLDER)
|
|
22009
|
+
return 400;
|
|
22010
|
+
if (error === MEDIA_NOT_FOUND)
|
|
22011
|
+
return 404;
|
|
22012
|
+
return 500;
|
|
22013
|
+
}
|
|
22014
|
+
|
|
22015
|
+
// ../cms-core/src/media/mime.ts
|
|
22016
|
+
function getFileExtension(filename) {
|
|
22017
|
+
const parts = filename.split(".");
|
|
22018
|
+
const ext = parts.length > 1 ? parts.pop()?.toLowerCase() ?? "" : "";
|
|
22019
|
+
return /^[a-z0-9]+$/.test(ext) ? ext : "";
|
|
22020
|
+
}
|
|
22021
|
+
var MIME_BY_EXT = {
|
|
22022
|
+
".jpg": "image/jpeg",
|
|
22023
|
+
".jpeg": "image/jpeg",
|
|
22024
|
+
".png": "image/png",
|
|
22025
|
+
".gif": "image/gif",
|
|
22026
|
+
".webp": "image/webp",
|
|
22027
|
+
".avif": "image/avif",
|
|
22028
|
+
".svg": "image/svg+xml",
|
|
22029
|
+
".ico": "image/x-icon",
|
|
22030
|
+
".mp4": "video/mp4",
|
|
22031
|
+
".webm": "video/webm",
|
|
22032
|
+
".pdf": "application/pdf"
|
|
22033
|
+
};
|
|
22034
|
+
function mimeFromExt(ext) {
|
|
22035
|
+
return MIME_BY_EXT[ext] ?? "application/octet-stream";
|
|
22036
|
+
}
|
|
22037
|
+
|
|
22038
|
+
// ../cms-core/src/media/names.ts
|
|
22039
|
+
function hasDotSegment(value) {
|
|
22040
|
+
return value.split("/").some((s) => s === "." || s === "..");
|
|
22041
|
+
}
|
|
22042
|
+
function isUnsafeFolder(folder) {
|
|
22043
|
+
return folder.includes("\\") || folder.split("/").some((s) => {
|
|
22044
|
+
const decoded = s.replace(/%2e/gi, ".");
|
|
22045
|
+
return decoded === "." || decoded === "..";
|
|
22046
|
+
});
|
|
22047
|
+
}
|
|
22048
|
+
|
|
22049
|
+
// ../cms-core/src/media/local.ts
|
|
22050
|
+
function errorCode(error) {
|
|
22051
|
+
return error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : undefined;
|
|
22052
|
+
}
|
|
22053
|
+
function failure(action, error) {
|
|
22054
|
+
const code = errorCode(error);
|
|
22055
|
+
return code ? `Failed to ${action} (${code})` : `Failed to ${action}`;
|
|
22056
|
+
}
|
|
22057
|
+
async function hasSymlink(from, names) {
|
|
22058
|
+
let current = from;
|
|
22059
|
+
for (const name of names) {
|
|
22060
|
+
current += path2.sep + name;
|
|
22061
|
+
try {
|
|
22062
|
+
if ((await fs2.lstat(current)).isSymbolicLink())
|
|
22063
|
+
return true;
|
|
22064
|
+
} catch (error) {
|
|
22065
|
+
const code = errorCode(error);
|
|
22066
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
22067
|
+
return false;
|
|
22068
|
+
throw error;
|
|
22069
|
+
}
|
|
22070
|
+
}
|
|
22071
|
+
return false;
|
|
22072
|
+
}
|
|
22073
|
+
function createLocalStorageAdapter(options = {}) {
|
|
22074
|
+
const dir = path2.resolve(options.dir ?? "public/uploads");
|
|
22075
|
+
const base = dir.endsWith(path2.sep) ? dir.slice(0, -path2.sep.length) : dir;
|
|
22076
|
+
const urlPrefix = (options.urlPrefix ?? "/uploads").replace(/\/$/, "");
|
|
22077
|
+
async function resolveInside(relative, kind) {
|
|
22078
|
+
const segments = relative.split("/");
|
|
22079
|
+
if (relative.includes("\x00") || segments.some((s) => s === "" || s === "." || s === ".."))
|
|
22080
|
+
return null;
|
|
22081
|
+
if (path2.sep === "\\" && segments.some((s) => /[\\:]|[. ]$/.test(s)))
|
|
22082
|
+
return null;
|
|
22083
|
+
const resolved = path2.resolve(dir, ...segments);
|
|
22084
|
+
if (resolved !== [base, ...segments].join(path2.sep))
|
|
22085
|
+
return null;
|
|
22086
|
+
if (await hasSymlink(base, kind === "file" ? segments.slice(0, -1) : segments))
|
|
22087
|
+
return null;
|
|
22088
|
+
return resolved;
|
|
22089
|
+
}
|
|
22090
|
+
async function resolveFolder(input, use) {
|
|
22091
|
+
const folder = (input ?? "").split("/").filter(Boolean).join("/");
|
|
22092
|
+
if (!folder)
|
|
22093
|
+
return { folder, targetDir: dir };
|
|
22094
|
+
if (use === "write" && isUnsafeFolder(folder))
|
|
22095
|
+
return null;
|
|
22096
|
+
const targetDir = await resolveInside(folder, "folder");
|
|
22097
|
+
return targetDir ? { folder, targetDir } : null;
|
|
22098
|
+
}
|
|
22099
|
+
return {
|
|
22100
|
+
staticFiles: { urlPrefix, dir },
|
|
22101
|
+
async list(opts) {
|
|
22102
|
+
const limit = opts?.limit ?? 50;
|
|
22103
|
+
const offset = opts?.cursor ? parseInt(opts.cursor, 10) : 0;
|
|
22104
|
+
const nothing = { items: [], folders: [], hasMore: false };
|
|
22105
|
+
try {
|
|
22106
|
+
const target = await resolveFolder(opts?.folder, "read");
|
|
22107
|
+
if (!target)
|
|
22108
|
+
return nothing;
|
|
22109
|
+
const { folder, targetDir } = target;
|
|
22110
|
+
await fs2.mkdir(targetDir, { recursive: true });
|
|
22111
|
+
const entries = await fs2.readdir(targetDir, { withFileTypes: true });
|
|
22112
|
+
const folders = entries.filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => ({
|
|
22113
|
+
name: e.name,
|
|
22114
|
+
path: folder ? `${folder}/${e.name}` : e.name
|
|
22115
|
+
})).sort((a, b) => a.name.localeCompare(b.name));
|
|
22116
|
+
const files = entries.filter((e) => e.isFile() && !e.name.startsWith("."));
|
|
22117
|
+
const withStats = await Promise.all(files.map(async (f) => {
|
|
22118
|
+
const filePath = path2.join(targetDir, f.name);
|
|
22119
|
+
const stat = await fs2.stat(filePath);
|
|
22120
|
+
return { name: f.name, stat };
|
|
22121
|
+
}));
|
|
22122
|
+
withStats.sort((a, b) => b.stat.mtimeMs - a.stat.mtimeMs);
|
|
22123
|
+
const slice = withStats.slice(offset, offset + limit);
|
|
22124
|
+
const hasMore = offset + limit < withStats.length;
|
|
22125
|
+
const urlFolder = folder ? `/${folder}` : "";
|
|
22126
|
+
const items = slice.map((f) => {
|
|
22127
|
+
const ext = path2.extname(f.name).toLowerCase();
|
|
22128
|
+
const contentType = mimeFromExt(ext);
|
|
22129
|
+
return {
|
|
22130
|
+
id: folder ? `${folder}/${f.name}` : f.name,
|
|
22131
|
+
url: `${urlPrefix}${urlFolder}/${f.name}`,
|
|
22132
|
+
filename: f.name,
|
|
22133
|
+
contentType,
|
|
22134
|
+
uploadedAt: f.stat.mtime.toISOString(),
|
|
22135
|
+
folder: folder || undefined
|
|
22136
|
+
};
|
|
22137
|
+
});
|
|
22138
|
+
return {
|
|
22139
|
+
items,
|
|
22140
|
+
folders,
|
|
22141
|
+
hasMore,
|
|
22142
|
+
cursor: hasMore ? String(offset + limit) : undefined
|
|
22143
|
+
};
|
|
22144
|
+
} catch (error) {
|
|
22145
|
+
const code = errorCode(error);
|
|
22146
|
+
if (opts?.folder && (code === "ENOTDIR" || code === "EEXIST" || code === "ENAMETOOLONG"))
|
|
22147
|
+
return nothing;
|
|
22148
|
+
throw new Error(failure("list media", error));
|
|
22149
|
+
}
|
|
22150
|
+
},
|
|
22151
|
+
async upload(file, filename, contentType, uploadOpts) {
|
|
22152
|
+
try {
|
|
22153
|
+
const target = await resolveFolder(uploadOpts?.folder, "write");
|
|
22154
|
+
if (!target)
|
|
22155
|
+
return { success: false, error: MEDIA_INVALID_FOLDER };
|
|
22156
|
+
const { folder, targetDir } = target;
|
|
22157
|
+
await fs2.mkdir(targetDir, { recursive: true });
|
|
22158
|
+
const ext = getFileExtension(filename);
|
|
22159
|
+
const uuid = randomUUID();
|
|
22160
|
+
const newFilename = `${uuid}${ext ? `.${ext}` : ""}`;
|
|
22161
|
+
const filePath = path2.join(targetDir, newFilename);
|
|
22162
|
+
await fs2.writeFile(filePath, file);
|
|
22163
|
+
const urlFolder = folder ? `/${folder}` : "";
|
|
22164
|
+
const id = folder ? `${folder}/${newFilename}` : newFilename;
|
|
22165
|
+
return {
|
|
22166
|
+
success: true,
|
|
22167
|
+
url: `${urlPrefix}${urlFolder}/${newFilename}`,
|
|
22168
|
+
filename: newFilename,
|
|
22169
|
+
id
|
|
22170
|
+
};
|
|
22171
|
+
} catch (error) {
|
|
22172
|
+
return { success: false, error: failure("store media file", error) };
|
|
22173
|
+
}
|
|
22174
|
+
},
|
|
22175
|
+
async delete(id) {
|
|
22176
|
+
try {
|
|
22177
|
+
const filePath = await resolveInside(id, "file");
|
|
22178
|
+
if (!filePath)
|
|
22179
|
+
return { success: false, error: MEDIA_INVALID_ID };
|
|
22180
|
+
await fs2.unlink(filePath);
|
|
22181
|
+
return { success: true };
|
|
22182
|
+
} catch (error) {
|
|
22183
|
+
if (errorCode(error) === "ENOENT")
|
|
22184
|
+
return { success: false, error: MEDIA_NOT_FOUND };
|
|
22185
|
+
return { success: false, error: failure("delete media file", error) };
|
|
22186
|
+
}
|
|
22187
|
+
},
|
|
22188
|
+
async createFolder(folder) {
|
|
22189
|
+
try {
|
|
22190
|
+
const target = await resolveFolder(folder, "write");
|
|
22191
|
+
if (!target)
|
|
22192
|
+
return { success: false, error: MEDIA_INVALID_FOLDER };
|
|
22193
|
+
await fs2.mkdir(target.targetDir, { recursive: true });
|
|
22194
|
+
return { success: true };
|
|
22195
|
+
} catch (error) {
|
|
22196
|
+
return { success: false, error: failure("create folder", error) };
|
|
22197
|
+
}
|
|
22198
|
+
}
|
|
22199
|
+
};
|
|
22200
|
+
}
|
|
21783
22201
|
// ../cms-core/src/asset-paths.ts
|
|
21784
22202
|
function assetBaseDir(file) {
|
|
21785
22203
|
const lastSlash = file.lastIndexOf("/");
|
|
@@ -22272,70 +22690,32 @@ function analyzeAstroSource(source) {
|
|
|
22272
22690
|
const frontmatter = extractAstroFrontmatter(source);
|
|
22273
22691
|
return frontmatter === null ? { imports: [], collectionCalls: [], collectionBindings: [] } : analyzeAstroScript(frontmatter);
|
|
22274
22692
|
}
|
|
22275
|
-
// ../cms-core/src/
|
|
22276
|
-
|
|
22277
|
-
|
|
22278
|
-
|
|
22279
|
-
|
|
22280
|
-
|
|
22281
|
-
|
|
22282
|
-
|
|
22283
|
-
|
|
22284
|
-
|
|
22285
|
-
|
|
22286
|
-
|
|
22287
|
-
|
|
22288
|
-
|
|
22289
|
-
|
|
22290
|
-
|
|
22291
|
-
|
|
22292
|
-
|
|
22293
|
-
|
|
22294
|
-
|
|
22295
|
-
|
|
22296
|
-
|
|
22297
|
-
|
|
22298
|
-
i++;
|
|
22299
|
-
} else {
|
|
22300
|
-
re += "[^/]*";
|
|
22301
|
-
}
|
|
22302
|
-
} else if (c === "?") {
|
|
22303
|
-
re += "[^/]";
|
|
22304
|
-
} else if (c === "{") {
|
|
22305
|
-
const end = glob.indexOf("}", i);
|
|
22306
|
-
if (end === -1) {
|
|
22307
|
-
re += "\\{";
|
|
22308
|
-
} else {
|
|
22309
|
-
const opts = glob.slice(i + 1, end).split(",").map((s) => s.replace(/[.+^${}()|[\]\\]/g, "\\$&"));
|
|
22310
|
-
re += `(?:${opts.join("|")})`;
|
|
22311
|
-
i = end;
|
|
22312
|
-
}
|
|
22313
|
-
} else if (".+^$()|[]\\".includes(c)) {
|
|
22314
|
-
re += `\\${c}`;
|
|
22315
|
-
} else {
|
|
22316
|
-
re += c;
|
|
22317
|
-
}
|
|
22318
|
-
}
|
|
22319
|
-
return new RegExp(`^${re}$`);
|
|
22320
|
-
}
|
|
22321
|
-
function globMayMatchUnder(glob, dir) {
|
|
22322
|
-
if (/\{[^}]*\//.test(glob))
|
|
22323
|
-
return true;
|
|
22324
|
-
const segments = glob.split("/").filter((segment) => segment !== "" && segment !== ".");
|
|
22325
|
-
const dirs = dir.split("/").filter((segment) => segment !== "" && segment !== ".");
|
|
22326
|
-
const reaches = (i, j) => {
|
|
22327
|
-
if (j === dirs.length)
|
|
22328
|
-
return i < segments.length;
|
|
22329
|
-
if (i >= segments.length)
|
|
22330
|
-
return false;
|
|
22331
|
-
if (segments[i].includes("**"))
|
|
22332
|
-
return true;
|
|
22333
|
-
return globToRegExp(segments[i]).test(dirs[j]) && reaches(i + 1, j + 1);
|
|
22334
|
-
};
|
|
22335
|
-
return reaches(0, 0);
|
|
22693
|
+
// ../cms-core/src/byte-range.ts
|
|
22694
|
+
function resolveByteRange(header, size) {
|
|
22695
|
+
if (header === null)
|
|
22696
|
+
return null;
|
|
22697
|
+
const match = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
|
|
22698
|
+
if (!match)
|
|
22699
|
+
return null;
|
|
22700
|
+
const [, first = "", last = ""] = match;
|
|
22701
|
+
if (first === "" && last === "")
|
|
22702
|
+
return null;
|
|
22703
|
+
if (first === "") {
|
|
22704
|
+
const suffix = Number(last);
|
|
22705
|
+
if (suffix === 0 || size === 0)
|
|
22706
|
+
return "unsatisfiable";
|
|
22707
|
+
return { start: Math.max(0, size - suffix), end: size - 1 };
|
|
22708
|
+
}
|
|
22709
|
+
const start = Number(first);
|
|
22710
|
+
const end = last === "" ? size - 1 : Math.min(Number(last), size - 1);
|
|
22711
|
+
if (last !== "" && Number(last) < start)
|
|
22712
|
+
return null;
|
|
22713
|
+
if (start >= size)
|
|
22714
|
+
return "unsatisfiable";
|
|
22715
|
+
return { start, end };
|
|
22336
22716
|
}
|
|
22337
|
-
|
|
22338
22717
|
// ../cms-core/src/check-entries.ts
|
|
22718
|
+
var import_yaml = __toESM(require_dist(), 1);
|
|
22339
22719
|
var DATA_EXTENSIONS = new Set([".json", ".yaml", ".yml"]);
|
|
22340
22720
|
|
|
22341
22721
|
// ../cms-types/src/field-values.ts
|
|
@@ -22374,7 +22754,7 @@ function blankRequiredFields(fields, frontmatter) {
|
|
|
22374
22754
|
return fields.filter((field) => field.required && !(field.hidden ?? field.layout?.hidden) && !isDeclaredDerived(field) && isBlankFieldValue(frontmatter[field.name])).map((field) => field.name);
|
|
22375
22755
|
}
|
|
22376
22756
|
var ENTRY_SLUG_FIELD = "slug";
|
|
22377
|
-
var NON_TEXT_SLUG_TYPES = new Set(["array", "object", "reference", "image", "file", "boolean", "number", "date", "datetime"]);
|
|
22757
|
+
var NON_TEXT_SLUG_TYPES = new Set(["array", "object", "reference", "image", "file", "video", "boolean", "number", "date", "datetime"]);
|
|
22378
22758
|
function holdsEntrySlug(field) {
|
|
22379
22759
|
return field.name === ENTRY_SLUG_FIELD && (field.type === undefined || !NON_TEXT_SLUG_TYPES.has(field.type));
|
|
22380
22760
|
}
|
|
@@ -22462,6 +22842,7 @@ var FIELD_TYPES = [
|
|
|
22462
22842
|
"number",
|
|
22463
22843
|
"image",
|
|
22464
22844
|
"file",
|
|
22845
|
+
"video",
|
|
22465
22846
|
"url",
|
|
22466
22847
|
"email",
|
|
22467
22848
|
"tel",
|
|
@@ -22501,8 +22882,8 @@ function computePathnameFromSpec(spec, data) {
|
|
|
22501
22882
|
return;
|
|
22502
22883
|
segments.push(seg.map && Object.hasOwn(seg.map, value) ? seg.map[value] : value);
|
|
22503
22884
|
}
|
|
22504
|
-
const
|
|
22505
|
-
return
|
|
22885
|
+
const path3 = ("/" + segments.join("/")).replace(/\/{2,}/g, "/").replace(/\/+$/, "");
|
|
22886
|
+
return path3 === "" ? "/" : path3;
|
|
22506
22887
|
}
|
|
22507
22888
|
function resolvePathnameFromSpec(def, data) {
|
|
22508
22889
|
if (!def.pathname)
|
|
@@ -22579,6 +22960,7 @@ var FIELD_HELPER_TYPES = new Set([
|
|
|
22579
22960
|
"number",
|
|
22580
22961
|
"image",
|
|
22581
22962
|
"file",
|
|
22963
|
+
"video",
|
|
22582
22964
|
"url",
|
|
22583
22965
|
"email",
|
|
22584
22966
|
"tel",
|
|
@@ -22714,36 +23096,36 @@ var UNREAD_CONTENT_CONFIG_PATHS = [
|
|
|
22714
23096
|
"src/content/config.js",
|
|
22715
23097
|
"src/content/config.mts"
|
|
22716
23098
|
];
|
|
22717
|
-
async function classifyEmptyContentConfig(
|
|
23099
|
+
async function classifyEmptyContentConfig(fs3) {
|
|
22718
23100
|
let found = false;
|
|
22719
23101
|
for (const configPath of CONTENT_CONFIG_PATHS) {
|
|
22720
23102
|
try {
|
|
22721
|
-
await
|
|
23103
|
+
await fs3.stat(configPath);
|
|
22722
23104
|
} catch {
|
|
22723
23105
|
continue;
|
|
22724
23106
|
}
|
|
22725
23107
|
found = true;
|
|
22726
|
-
if (parseSource(await
|
|
23108
|
+
if (parseSource(await fs3.readFile(configPath)) === null) {
|
|
22727
23109
|
return "unparseable";
|
|
22728
23110
|
}
|
|
22729
23111
|
}
|
|
22730
23112
|
return found ? "no-collections" : "missing";
|
|
22731
23113
|
}
|
|
22732
|
-
async function parseContentConfig(
|
|
22733
|
-
return (await readContentConfig(
|
|
23114
|
+
async function parseContentConfig(fs3, cache) {
|
|
23115
|
+
return (await readContentConfig(fs3, cache)).parsed;
|
|
22734
23116
|
}
|
|
22735
|
-
async function readContentConfig(
|
|
23117
|
+
async function readContentConfig(fs3, cache) {
|
|
22736
23118
|
let unparsed;
|
|
22737
23119
|
for (const configPath of CONTENT_CONFIG_PATHS) {
|
|
22738
23120
|
let stat;
|
|
22739
23121
|
try {
|
|
22740
|
-
stat = await
|
|
23122
|
+
stat = await fs3.stat(configPath);
|
|
22741
23123
|
} catch {
|
|
22742
23124
|
continue;
|
|
22743
23125
|
}
|
|
22744
23126
|
let cached = cache.get(configPath);
|
|
22745
23127
|
if (!cached || cached.mtimeMs !== stat.mtimeMs) {
|
|
22746
|
-
const content = await
|
|
23128
|
+
const content = await fs3.readFile(configPath);
|
|
22747
23129
|
cached = { mtimeMs: stat.mtimeMs, ...readConfigSource(content) };
|
|
22748
23130
|
cache.set(configPath, cached);
|
|
22749
23131
|
}
|
|
@@ -23118,9 +23500,9 @@ function configOptionMentions(source, name) {
|
|
|
23118
23500
|
if (!ast)
|
|
23119
23501
|
return null;
|
|
23120
23502
|
const mentions = [];
|
|
23121
|
-
walkValues(ast.program, (
|
|
23122
|
-
const { node, key } =
|
|
23123
|
-
const parent =
|
|
23503
|
+
walkValues(ast.program, (path3) => {
|
|
23504
|
+
const { node, key } = path3.at(-1);
|
|
23505
|
+
const parent = path3.at(-2)?.node;
|
|
23124
23506
|
const isKey = parent?.type === "ObjectProperty" && key === "key";
|
|
23125
23507
|
const asString = node.type === "StringLiteral" ? node.value : node.type === "TemplateLiteral" && node.expressions.length === 0 ? node.quasis[0]?.value.cooked : undefined;
|
|
23126
23508
|
const named = node.type === "Identifier" ? node.name === name : asString === name;
|
|
@@ -23148,8 +23530,8 @@ var TS_NODES_WITH_CODE = new Set([
|
|
|
23148
23530
|
"TSParameterProperty"
|
|
23149
23531
|
]);
|
|
23150
23532
|
var NODE_METADATA = new Set(["loc", "extra", "leadingComments", "trailingComments", "innerComments"]);
|
|
23151
|
-
function walkValues(node, visit,
|
|
23152
|
-
visit(
|
|
23533
|
+
function walkValues(node, visit, path3 = [{ node, key: "" }]) {
|
|
23534
|
+
visit(path3);
|
|
23153
23535
|
const children = Object.entries(node);
|
|
23154
23536
|
for (const [key, child] of children) {
|
|
23155
23537
|
if (NODE_METADATA.has(key))
|
|
@@ -23157,16 +23539,16 @@ function walkValues(node, visit, path = [{ node, key: "" }]) {
|
|
|
23157
23539
|
for (const item of Array.isArray(child) ? child : [child]) {
|
|
23158
23540
|
if (!isAstNode(item) || item.type.startsWith("TS") && !TS_NODES_WITH_CODE.has(item.type))
|
|
23159
23541
|
continue;
|
|
23160
|
-
|
|
23161
|
-
walkValues(item, visit,
|
|
23162
|
-
|
|
23542
|
+
path3.push({ node: item, key });
|
|
23543
|
+
walkValues(item, visit, path3);
|
|
23544
|
+
path3.pop();
|
|
23163
23545
|
}
|
|
23164
23546
|
}
|
|
23165
23547
|
}
|
|
23166
|
-
function isModuleLevelDeclarator(
|
|
23167
|
-
const holder =
|
|
23548
|
+
function isModuleLevelDeclarator(path3, index) {
|
|
23549
|
+
const holder = path3[index - 2]?.node;
|
|
23168
23550
|
if (holder?.type === "ExportNamedDeclaration")
|
|
23169
|
-
return
|
|
23551
|
+
return path3[index - 3]?.node.type === "Program";
|
|
23170
23552
|
return holder?.type === "Program";
|
|
23171
23553
|
}
|
|
23172
23554
|
function isImmutableLiteral(node) {
|
|
@@ -23187,34 +23569,34 @@ function followedConstants(ast, bindings) {
|
|
|
23187
23569
|
const member = object?.type === "ObjectExpression" ? literalMember(object, key) : undefined;
|
|
23188
23570
|
return !!member && isImmutableLiteral(resolveExpression(member, new Map));
|
|
23189
23571
|
};
|
|
23190
|
-
const readIn = (
|
|
23572
|
+
const readIn = (path3, index) => {
|
|
23191
23573
|
const calls = [];
|
|
23192
23574
|
for (let at = index;; ) {
|
|
23193
|
-
const parent =
|
|
23194
|
-
const { node, key } =
|
|
23575
|
+
const parent = path3[at - 1]?.node;
|
|
23576
|
+
const { node, key } = path3[at];
|
|
23195
23577
|
if (!parent)
|
|
23196
23578
|
return null;
|
|
23197
23579
|
if (VALUE_WRAPPERS.has(parent.type) && key === "expression") {
|
|
23198
23580
|
at--;
|
|
23199
|
-
} else if (parent.type === "ObjectProperty" && key === "value" &&
|
|
23581
|
+
} else if (parent.type === "ObjectProperty" && key === "value" && path3[at - 2]?.node.type === "ObjectExpression") {
|
|
23200
23582
|
at -= 2;
|
|
23201
23583
|
} else if (parent.type === "CallExpression" && parent.arguments[0] === node && parent.callee.type === "Identifier" && READER_CALLS.includes(parent.callee.name)) {
|
|
23202
23584
|
calls.push(parent.callee.name);
|
|
23203
23585
|
at--;
|
|
23204
23586
|
} else {
|
|
23205
|
-
return parent.type === "VariableDeclarator" && key === "init" && parent.id.type === "Identifier" && isModuleLevelDeclarator(
|
|
23587
|
+
return parent.type === "VariableDeclarator" && key === "init" && parent.id.type === "Identifier" && isModuleLevelDeclarator(path3, at - 1) ? { holder: parent.id.name, calls } : null;
|
|
23206
23588
|
}
|
|
23207
23589
|
}
|
|
23208
23590
|
};
|
|
23209
|
-
const isValueRead = (
|
|
23591
|
+
const isValueRead = (path3, index) => {
|
|
23210
23592
|
let at = index;
|
|
23211
|
-
while (VALUE_WRAPPERS.has(
|
|
23593
|
+
while (VALUE_WRAPPERS.has(path3[at - 1]?.node.type ?? "") && path3[at].key === "expression")
|
|
23212
23594
|
at--;
|
|
23213
|
-
const parent =
|
|
23214
|
-
const { key } =
|
|
23595
|
+
const parent = path3[at - 1]?.node;
|
|
23596
|
+
const { key } = path3[at];
|
|
23215
23597
|
switch (parent?.type) {
|
|
23216
23598
|
case "ObjectProperty":
|
|
23217
|
-
return key === "value" &&
|
|
23599
|
+
return key === "value" && path3[at - 2]?.node.type === "ObjectExpression";
|
|
23218
23600
|
case "CallExpression":
|
|
23219
23601
|
case "OptionalCallExpression":
|
|
23220
23602
|
case "NewExpression":
|
|
@@ -23230,9 +23612,9 @@ function followedConstants(ast, bindings) {
|
|
|
23230
23612
|
return false;
|
|
23231
23613
|
}
|
|
23232
23614
|
};
|
|
23233
|
-
walkValues(ast.program, (
|
|
23234
|
-
const { node, key } =
|
|
23235
|
-
const parent =
|
|
23615
|
+
walkValues(ast.program, (path3) => {
|
|
23616
|
+
const { node, key } = path3.at(-1);
|
|
23617
|
+
const parent = path3.at(-2)?.node;
|
|
23236
23618
|
if (node.type !== "Identifier" || !parent)
|
|
23237
23619
|
return;
|
|
23238
23620
|
const { name } = node;
|
|
@@ -23245,14 +23627,14 @@ function followedConstants(ast, bindings) {
|
|
|
23245
23627
|
anythingMayChange = true;
|
|
23246
23628
|
if (READER_CALLS.includes(name) || name === "Object") {
|
|
23247
23629
|
const imported = (parent.type === "ImportSpecifier" || parent.type === "ImportDefaultSpecifier" || parent.type === "ImportNamespaceSpecifier") && key === "local";
|
|
23248
|
-
const grandparent =
|
|
23630
|
+
const grandparent = path3.at(-3)?.node;
|
|
23249
23631
|
const called = parent.type === "CallExpression" && key === "callee" || name === "Object" && parent.type === "MemberExpression" && key === "object" && !parent.computed && grandparent?.type === "CallExpression" && grandparent.callee === parent;
|
|
23250
23632
|
if (!imported && !called)
|
|
23251
23633
|
untrusted.add(name);
|
|
23252
23634
|
}
|
|
23253
23635
|
if (!bindings.has(name))
|
|
23254
23636
|
return;
|
|
23255
|
-
if (parent.type === "VariableDeclarator" && key === "id" && isModuleLevelDeclarator(
|
|
23637
|
+
if (parent.type === "VariableDeclarator" && key === "id" && isModuleLevelDeclarator(path3, path3.length - 2))
|
|
23256
23638
|
return;
|
|
23257
23639
|
if (parent.type === "ExportDefaultDeclaration")
|
|
23258
23640
|
return;
|
|
@@ -23262,9 +23644,9 @@ function followedConstants(ast, bindings) {
|
|
|
23262
23644
|
note(handedTo, name, ["Object"]);
|
|
23263
23645
|
return;
|
|
23264
23646
|
}
|
|
23265
|
-
if ((parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && key === "object" && !parent.computed && parent.property.type === "Identifier" && holdsPrimitiveAt(name, parent.property.name) && isValueRead(
|
|
23647
|
+
if ((parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && key === "object" && !parent.computed && parent.property.type === "Identifier" && holdsPrimitiveAt(name, parent.property.name) && isValueRead(path3, path3.length - 2))
|
|
23266
23648
|
return;
|
|
23267
|
-
const read = readIn(
|
|
23649
|
+
const read = readIn(path3, path3.length - 1);
|
|
23268
23650
|
if (read === null) {
|
|
23269
23651
|
dropped.add(name);
|
|
23270
23652
|
return;
|
|
@@ -23784,11 +24166,11 @@ function checkDerivedFromDeclarations(collectionName, fields) {
|
|
|
23784
24166
|
dropNestedDerivedFrom(collectionName, field.name, field.fields);
|
|
23785
24167
|
}
|
|
23786
24168
|
}
|
|
23787
|
-
function dropNestedDerivedFrom(collectionName,
|
|
24169
|
+
function dropNestedDerivedFrom(collectionName, path3, fields) {
|
|
23788
24170
|
if (!fields)
|
|
23789
24171
|
return;
|
|
23790
24172
|
for (const field of fields) {
|
|
23791
|
-
const fieldPath = `${
|
|
24173
|
+
const fieldPath = `${path3}.${field.name}`;
|
|
23792
24174
|
const layout = field.layout;
|
|
23793
24175
|
if (layout?.derivedFrom !== undefined) {
|
|
23794
24176
|
console.warn(`[cms] collection "${collectionName}": field "${fieldPath}" declares \`derivedFrom\` on a nested field, which is not supported` + ` \u2014 only top-level fields derive, so the declaration is ignored and the field stays editable`);
|
|
@@ -23800,10 +24182,11 @@ function dropNestedDerivedFrom(collectionName, path, fields) {
|
|
|
23800
24182
|
}
|
|
23801
24183
|
// ../cms-core/src/collection-scanner.ts
|
|
23802
24184
|
var import_yaml2 = __toESM(require_dist(), 1);
|
|
23803
|
-
import
|
|
24185
|
+
import path3 from "path";
|
|
23804
24186
|
var DATE_PATTERN = /^\d{4}-\d{2}-\d{2}/;
|
|
23805
24187
|
var URL_PATTERN = /^(https?:\/\/|\/)/;
|
|
23806
24188
|
var IMAGE_EXTENSIONS = /\.(jpg|jpeg|png|gif|webp|svg|avif)$/i;
|
|
24189
|
+
var VIDEO_EXTENSIONS = /\.(mp4|webm)$/i;
|
|
23807
24190
|
var MAX_SELECT_OPTIONS = 10;
|
|
23808
24191
|
var TEXTAREA_MIN_LENGTH = 200;
|
|
23809
24192
|
var SIDEBAR_FIELD_NAMES = new Set([
|
|
@@ -23942,6 +24325,9 @@ function inferFieldType(value, key) {
|
|
|
23942
24325
|
if (IMAGE_EXTENSIONS.test(value)) {
|
|
23943
24326
|
return "image";
|
|
23944
24327
|
}
|
|
24328
|
+
if (VIDEO_EXTENSIONS.test(value)) {
|
|
24329
|
+
return "video";
|
|
24330
|
+
}
|
|
23945
24331
|
const lowerKey = key.toLowerCase();
|
|
23946
24332
|
if (/(?:^|[_-])(?:image|thumbnail|cover|avatar|logo|icon|banner|photo)(?:$|[_-])/.test(lowerKey)) {
|
|
23947
24333
|
return "image";
|
|
@@ -24051,7 +24437,7 @@ function assembleCollectionDefinition(collectionName, contentDir, fieldMap, entr
|
|
|
24051
24437
|
return {
|
|
24052
24438
|
name: collectionName,
|
|
24053
24439
|
label,
|
|
24054
|
-
path:
|
|
24440
|
+
path: path3.join(contentDir, collectionName),
|
|
24055
24441
|
entryCount,
|
|
24056
24442
|
fields,
|
|
24057
24443
|
fileExtension: "md",
|
|
@@ -24060,14 +24446,14 @@ function assembleCollectionDefinition(collectionName, contentDir, fieldMap, entr
|
|
|
24060
24446
|
};
|
|
24061
24447
|
}
|
|
24062
24448
|
function getCollectionSourceBasePath(basePath, collectionName, contentDir) {
|
|
24063
|
-
const defaultCollectionPath =
|
|
24449
|
+
const defaultCollectionPath = path3.join(contentDir, collectionName);
|
|
24064
24450
|
const normalizedBasePath = normalizeBasePath(basePath);
|
|
24065
|
-
if (normalizedBasePath ===
|
|
24066
|
-
return
|
|
24451
|
+
if (normalizedBasePath === path3.normalize(defaultCollectionPath)) {
|
|
24452
|
+
return path3.join(contentDir, collectionName);
|
|
24067
24453
|
}
|
|
24068
24454
|
return normalizedBasePath;
|
|
24069
24455
|
}
|
|
24070
|
-
async function buildCollectionDefinition(
|
|
24456
|
+
async function buildCollectionDefinition(fs3, basePath, sources, collectionName, contentDir) {
|
|
24071
24457
|
if (sources.length === 0)
|
|
24072
24458
|
return null;
|
|
24073
24459
|
const sourceBasePath = getCollectionSourceBasePath(basePath, collectionName, contentDir);
|
|
@@ -24077,7 +24463,7 @@ async function buildCollectionDefinition(fs, basePath, sources, collectionName,
|
|
|
24077
24463
|
const allDirectives = {};
|
|
24078
24464
|
const entryInfos = [];
|
|
24079
24465
|
let hasDraft = false;
|
|
24080
|
-
const fileContents = await Promise.all(sources.map((s) =>
|
|
24466
|
+
const fileContents = await Promise.all(sources.map((s) => fs3.readFile(path3.join(basePath, s.relPath)).catch(() => null)));
|
|
24081
24467
|
for (let i = 0;i < sources.length; i++) {
|
|
24082
24468
|
const source = sources[i];
|
|
24083
24469
|
const content = fileContents[i];
|
|
@@ -24092,7 +24478,7 @@ async function buildCollectionDefinition(fs, basePath, sources, collectionName,
|
|
|
24092
24478
|
}
|
|
24093
24479
|
const entryInfo = {
|
|
24094
24480
|
slug: source.slug,
|
|
24095
|
-
sourcePath:
|
|
24481
|
+
sourcePath: path3.join(sourceBasePath, source.relPath)
|
|
24096
24482
|
};
|
|
24097
24483
|
if (frontmatter) {
|
|
24098
24484
|
const title = deriveEntryTitle(frontmatter);
|
|
@@ -24119,14 +24505,14 @@ async function buildCollectionDefinition(fs, basePath, sources, collectionName,
|
|
|
24119
24505
|
assignFieldMetadata(def.fields, allDirectives);
|
|
24120
24506
|
return def;
|
|
24121
24507
|
}
|
|
24122
|
-
async function buildDataCollectionDefinition(
|
|
24508
|
+
async function buildDataCollectionDefinition(fs3, basePath, sources, collectionName, contentDir) {
|
|
24123
24509
|
if (sources.length === 0)
|
|
24124
24510
|
return null;
|
|
24125
24511
|
const sourceBasePath = getCollectionSourceBasePath(basePath, collectionName, contentDir);
|
|
24126
24512
|
const fieldMap = new Map;
|
|
24127
24513
|
const entryInfos = [];
|
|
24128
24514
|
const ext = sources.some((s) => s.relPath.endsWith(".json")) ? "json" : sources.some((s) => s.relPath.endsWith(".yaml")) ? "yaml" : "yml";
|
|
24129
|
-
const fileContents = await Promise.all(sources.map((s) =>
|
|
24515
|
+
const fileContents = await Promise.all(sources.map((s) => fs3.readFile(path3.join(basePath, s.relPath)).catch(() => null)));
|
|
24130
24516
|
for (let i = 0;i < sources.length; i++) {
|
|
24131
24517
|
const source = sources[i];
|
|
24132
24518
|
const raw = fileContents[i];
|
|
@@ -24144,7 +24530,7 @@ async function buildDataCollectionDefinition(fs, basePath, sources, collectionNa
|
|
|
24144
24530
|
entryInfos.push({
|
|
24145
24531
|
slug: source.slug,
|
|
24146
24532
|
title,
|
|
24147
|
-
sourcePath:
|
|
24533
|
+
sourcePath: path3.join(sourceBasePath, source.relPath),
|
|
24148
24534
|
data
|
|
24149
24535
|
});
|
|
24150
24536
|
collectFieldObservations(fieldMap, data, sources.length);
|
|
@@ -24155,8 +24541,8 @@ async function buildDataCollectionDefinition(fs, basePath, sources, collectionNa
|
|
|
24155
24541
|
fileExtension: ext
|
|
24156
24542
|
});
|
|
24157
24543
|
}
|
|
24158
|
-
async function scanCollection(
|
|
24159
|
-
const dirEntries = await
|
|
24544
|
+
async function scanCollection(fs3, collectionPath, collectionName, contentDir) {
|
|
24545
|
+
const dirEntries = await fs3.list(collectionPath);
|
|
24160
24546
|
if (dirEntries.length === 0)
|
|
24161
24547
|
return null;
|
|
24162
24548
|
const sources = [];
|
|
@@ -24175,8 +24561,8 @@ async function scanCollection(fs, collectionPath, collectionName, contentDir) {
|
|
|
24175
24561
|
if (takenSlugs.has(dir.name))
|
|
24176
24562
|
return null;
|
|
24177
24563
|
for (const ext of ["md", "mdx"]) {
|
|
24178
|
-
const relPath =
|
|
24179
|
-
if (await
|
|
24564
|
+
const relPath = path3.join(dir.name, `index.${ext}`);
|
|
24565
|
+
if (await fs3.exists(path3.join(collectionPath, relPath))) {
|
|
24180
24566
|
return { slug: dir.name, relPath };
|
|
24181
24567
|
}
|
|
24182
24568
|
}
|
|
@@ -24188,22 +24574,22 @@ async function scanCollection(fs, collectionPath, collectionName, contentDir) {
|
|
|
24188
24574
|
}
|
|
24189
24575
|
if (sources.length === 0)
|
|
24190
24576
|
return null;
|
|
24191
|
-
return await buildCollectionDefinition(
|
|
24577
|
+
return await buildCollectionDefinition(fs3, collectionPath, sources, collectionName, contentDir);
|
|
24192
24578
|
}
|
|
24193
|
-
async function globLoaderFiles(
|
|
24579
|
+
async function globLoaderFiles(fs3, baseRel, pattern, options) {
|
|
24194
24580
|
const isPrivate = (relToBase) => relToBase.split("/").some((seg) => seg.startsWith("_") || seg.startsWith("."));
|
|
24195
|
-
const matches = await
|
|
24196
|
-
return matches.map((rel) =>
|
|
24581
|
+
const matches = await fs3.glob(path3.join(baseRel, pattern), { ...options, skipDirectory: (dir) => isPrivate(path3.relative(baseRel, dir)) });
|
|
24582
|
+
return matches.map((rel) => path3.relative(baseRel, rel)).filter((relToBase) => !isPrivate(relToBase));
|
|
24197
24583
|
}
|
|
24198
|
-
async function scanGlobCollection(
|
|
24199
|
-
const rels = await globLoaderFiles(
|
|
24584
|
+
async function scanGlobCollection(fs3, collectionName, baseRel, pattern, contentDir) {
|
|
24585
|
+
const rels = await globLoaderFiles(fs3, baseRel, pattern);
|
|
24200
24586
|
const mdSources = rels.filter((relToBase) => relToBase.endsWith(".md") || relToBase.endsWith(".mdx")).map((relToBase) => ({ slug: relToBase.replace(/\.(md|mdx)$/, ""), relPath: relToBase }));
|
|
24201
24587
|
if (mdSources.length > 0) {
|
|
24202
|
-
return await buildCollectionDefinition(
|
|
24588
|
+
return await buildCollectionDefinition(fs3, baseRel, mdSources, collectionName, contentDir);
|
|
24203
24589
|
}
|
|
24204
24590
|
const dataSources = rels.filter((relToBase) => /\.(ya?ml|json)$/.test(relToBase)).map((relToBase) => ({ slug: relToBase.replace(/\.(ya?ml|json)$/, ""), relPath: relToBase }));
|
|
24205
24591
|
if (dataSources.length > 0) {
|
|
24206
|
-
return await buildDataCollectionDefinition(
|
|
24592
|
+
return await buildDataCollectionDefinition(fs3, baseRel, dataSources, collectionName, contentDir);
|
|
24207
24593
|
}
|
|
24208
24594
|
return null;
|
|
24209
24595
|
}
|
|
@@ -24528,8 +24914,8 @@ function detectDerivedHrefFields(collections) {
|
|
|
24528
24914
|
}
|
|
24529
24915
|
}
|
|
24530
24916
|
}
|
|
24531
|
-
async function scanDataCollection(
|
|
24532
|
-
const dirEntries = await
|
|
24917
|
+
async function scanDataCollection(fs3, collectionPath, collectionName, contentDir) {
|
|
24918
|
+
const dirEntries = await fs3.list(collectionPath);
|
|
24533
24919
|
if (dirEntries.length === 0)
|
|
24534
24920
|
return null;
|
|
24535
24921
|
const sources = [];
|
|
@@ -24548,8 +24934,8 @@ async function scanDataCollection(fs, collectionPath, collectionName, contentDir
|
|
|
24548
24934
|
if (takenSlugs.has(dir.name))
|
|
24549
24935
|
return null;
|
|
24550
24936
|
for (const indexExt of ["json", "yaml", "yml"]) {
|
|
24551
|
-
const relPath =
|
|
24552
|
-
if (await
|
|
24937
|
+
const relPath = path3.join(dir.name, `index.${indexExt}`);
|
|
24938
|
+
if (await fs3.exists(path3.join(collectionPath, relPath))) {
|
|
24553
24939
|
return { slug: dir.name, relPath };
|
|
24554
24940
|
}
|
|
24555
24941
|
}
|
|
@@ -24559,10 +24945,10 @@ async function scanDataCollection(fs, collectionPath, collectionName, contentDir
|
|
|
24559
24945
|
if (entry)
|
|
24560
24946
|
sources.push(entry);
|
|
24561
24947
|
}
|
|
24562
|
-
return await buildDataCollectionDefinition(
|
|
24948
|
+
return await buildDataCollectionDefinition(fs3, collectionPath, sources, collectionName, contentDir);
|
|
24563
24949
|
}
|
|
24564
24950
|
function normalizeBasePath(basePath) {
|
|
24565
|
-
return
|
|
24951
|
+
return path3.normalize(basePath.replace(/^\.[/\\]+/, "")).replace(/[/\\]+$/, "");
|
|
24566
24952
|
}
|
|
24567
24953
|
var WHOLE_DIRECTORY_PATTERN = /^(?:\*\*[/\\])*\*(?:\.(?:\{([^{}/\\]*)\}|([A-Za-z0-9]+)))?$/;
|
|
24568
24954
|
function patternCoversWholeCollection(pattern, definition) {
|
|
@@ -24573,7 +24959,7 @@ function patternCoversWholeCollection(pattern, definition) {
|
|
|
24573
24959
|
if (braceGroup === undefined && singleExtension === undefined)
|
|
24574
24960
|
return true;
|
|
24575
24961
|
const patternExtensions = new Set((braceGroup !== undefined ? braceGroup.split(",") : [singleExtension]).map((ext) => ext.trim().replace(/^\./, "").toLowerCase()).filter(Boolean));
|
|
24576
|
-
const scannedExtensions = new Set((definition.entries ?? []).map((entry) =>
|
|
24962
|
+
const scannedExtensions = new Set((definition.entries ?? []).map((entry) => path3.extname(entry.sourcePath).slice(1).toLowerCase()).filter(Boolean));
|
|
24577
24963
|
if (scannedExtensions.size === 0)
|
|
24578
24964
|
return false;
|
|
24579
24965
|
for (const ext of scannedExtensions) {
|
|
@@ -24582,24 +24968,24 @@ function patternCoversWholeCollection(pattern, definition) {
|
|
|
24582
24968
|
}
|
|
24583
24969
|
return true;
|
|
24584
24970
|
}
|
|
24585
|
-
async function scanCollections(
|
|
24971
|
+
async function scanCollections(fs3, contentDir = "src/content", parseCache = new Map, options = {}) {
|
|
24586
24972
|
const collections = {};
|
|
24587
24973
|
const failedScans = new Map;
|
|
24588
|
-
const entries = await
|
|
24974
|
+
const entries = await fs3.list(contentDir);
|
|
24589
24975
|
const scanPromises = entries.filter((entry) => entry.isDirectory && !entry.name.startsWith("_") && !entry.name.startsWith(".")).map(async (entry) => {
|
|
24590
24976
|
try {
|
|
24591
|
-
const collectionPath =
|
|
24592
|
-
const definition = await scanCollection(
|
|
24977
|
+
const collectionPath = path3.join(contentDir, entry.name);
|
|
24978
|
+
const definition = await scanCollection(fs3, collectionPath, entry.name, contentDir) ?? await scanDataCollection(fs3, collectionPath, entry.name, contentDir);
|
|
24593
24979
|
if (definition) {
|
|
24594
24980
|
collections[entry.name] = definition;
|
|
24595
24981
|
}
|
|
24596
24982
|
} catch (error) {
|
|
24597
24983
|
console.warn(`[cms] Skipping collection "${entry.name}" \u2014 scan failed:`, error);
|
|
24598
|
-
failedScans.set(entry.name, { name: entry.name, reason: "scan-failed", base:
|
|
24984
|
+
failedScans.set(entry.name, { name: entry.name, reason: "scan-failed", base: path3.join(contentDir, entry.name) });
|
|
24599
24985
|
}
|
|
24600
24986
|
});
|
|
24601
24987
|
await Promise.all(scanPromises);
|
|
24602
|
-
const config = await readContentConfig(
|
|
24988
|
+
const config = await readContentConfig(fs3, parseCache);
|
|
24603
24989
|
const { parsed } = config;
|
|
24604
24990
|
const scannedNameByBasePath = new Map;
|
|
24605
24991
|
for (const [name, definition] of Object.entries(collections)) {
|
|
@@ -24626,7 +25012,7 @@ async function scanCollections(fs, contentDir = "src/content", parseCache = new
|
|
|
24626
25012
|
}
|
|
24627
25013
|
let definition;
|
|
24628
25014
|
try {
|
|
24629
|
-
definition = await scanGlobCollection(
|
|
25015
|
+
definition = await scanGlobCollection(fs3, collectionName, parsedCollection.loaderBase, parsedCollection.loaderPattern, contentDir);
|
|
24630
25016
|
} catch (error) {
|
|
24631
25017
|
console.warn(`[cms] Skipping glob collection "${collectionName}" \u2014 scan failed:`, error);
|
|
24632
25018
|
failedScans.set(collectionName, {
|
|
@@ -24655,7 +25041,7 @@ async function scanCollections(fs, contentDir = "src/content", parseCache = new
|
|
|
24655
25041
|
if (options.report) {
|
|
24656
25042
|
try {
|
|
24657
25043
|
const contentDirectories = entries.filter((entry) => entry.isDirectory && !entry.name.startsWith("_") && !entry.name.startsWith(".")).map((entry) => entry.name);
|
|
24658
|
-
scanReports.set(collections, await buildScanReport(
|
|
25044
|
+
scanReports.set(collections, await buildScanReport(fs3, contentDir, collections, config, failedScans, contentDirectories));
|
|
24659
25045
|
} catch (error) {
|
|
24660
25046
|
console.warn("[cms] Collection scan report unavailable:", error);
|
|
24661
25047
|
}
|
|
@@ -24676,7 +25062,7 @@ function readsAsRelativeDirectory(base) {
|
|
|
24676
25062
|
return false;
|
|
24677
25063
|
try {
|
|
24678
25064
|
const asUrl = decodeURIComponent(new URL(base, "file:///project-root/").pathname).replace(/\/{2,}/g, "/").replace(/\/+$/, "");
|
|
24679
|
-
const asPath = normalizeBasePath(base).split(
|
|
25065
|
+
const asPath = normalizeBasePath(base).split(path3.sep).join("/");
|
|
24680
25066
|
return asUrl === (asPath === "." ? "/project-root" : `/project-root/${asPath}`);
|
|
24681
25067
|
} catch {
|
|
24682
25068
|
return false;
|
|
@@ -24685,7 +25071,7 @@ function readsAsRelativeDirectory(base) {
|
|
|
24685
25071
|
function declaredLocation(declaration, contentDir) {
|
|
24686
25072
|
const location = {};
|
|
24687
25073
|
if (declaration.noLoader)
|
|
24688
|
-
location.base =
|
|
25074
|
+
location.base = path3.join(contentDir, declaration.name);
|
|
24689
25075
|
if (declaration.loaderBase !== undefined)
|
|
24690
25076
|
location.base = normalizeBasePath(declaration.loaderBase);
|
|
24691
25077
|
if (declaration.loaderPattern !== undefined)
|
|
@@ -24694,15 +25080,15 @@ function declaredLocation(declaration, contentDir) {
|
|
|
24694
25080
|
location.file = normalizeBasePath(declaration.loaderFile);
|
|
24695
25081
|
return location;
|
|
24696
25082
|
}
|
|
24697
|
-
async function contentDirectoryFiles(
|
|
24698
|
-
const files = await globLoaderFiles(
|
|
24699
|
-
return files.filter((file) => entryFile.test(file)).map((file) =>
|
|
25083
|
+
async function contentDirectoryFiles(fs3, directory, entryFile) {
|
|
25084
|
+
const files = await globLoaderFiles(fs3, directory, "**/*", { followSymlinks: true, maxLinkedDirectories: REPORT_LINKED_DIRECTORY_LIMIT });
|
|
25085
|
+
return files.filter((file) => entryFile.test(file)).map((file) => path3.join(directory, file));
|
|
24700
25086
|
}
|
|
24701
|
-
async function declaredEntryFiles(
|
|
25087
|
+
async function declaredEntryFiles(fs3, contentDir, declaration) {
|
|
24702
25088
|
if (declaration.noLoader) {
|
|
24703
25089
|
if (!readsAsRelativeDirectory(declaration.name))
|
|
24704
25090
|
return null;
|
|
24705
|
-
return { exact: true, files: await contentDirectoryFiles(
|
|
25091
|
+
return { exact: true, files: await contentDirectoryFiles(fs3, path3.join(contentDir, declaration.name), ENTRY_FILE) };
|
|
24706
25092
|
}
|
|
24707
25093
|
const declaredBase = declaration.loaderBase;
|
|
24708
25094
|
if (declaredBase === undefined || !readsAsRelativeDirectory(declaredBase))
|
|
@@ -24712,14 +25098,14 @@ async function declaredEntryFiles(fs, contentDir, declaration) {
|
|
|
24712
25098
|
const patterns = pattern !== undefined ? [pattern] : declaration.loaderPatterns;
|
|
24713
25099
|
if (patterns === undefined)
|
|
24714
25100
|
return null;
|
|
24715
|
-
const exact = pattern !== undefined && !UNSUPPORTED_GLOB_SYNTAX.test(pattern) && !UNSUPPORTED_GLOB_SYNTAX.test(
|
|
25101
|
+
const exact = pattern !== undefined && !UNSUPPORTED_GLOB_SYNTAX.test(pattern) && !UNSUPPORTED_GLOB_SYNTAX.test(path3.posix.normalize(pattern));
|
|
24716
25102
|
if (!exact && (base === "." || patterns.some((one) => LEAVES_THE_BASE.test(one))))
|
|
24717
25103
|
return null;
|
|
24718
|
-
const matches = await
|
|
25104
|
+
const matches = await fs3.glob(path3.join(base, exact ? pattern : "**/*"), {
|
|
24719
25105
|
followSymlinks: true,
|
|
24720
25106
|
maxLinkedDirectories: REPORT_LINKED_DIRECTORY_LIMIT
|
|
24721
25107
|
});
|
|
24722
|
-
const files = matches.filter((file) => ENTRY_FILE.test(file) && patterns.some((one) => mayTakeDotPath(one,
|
|
25108
|
+
const files = matches.filter((file) => ENTRY_FILE.test(file) && patterns.some((one) => mayTakeDotPath(one, path3.relative(base, file))));
|
|
24723
25109
|
return { exact, files };
|
|
24724
25110
|
}
|
|
24725
25111
|
function mayTakeDotPath(pattern, file) {
|
|
@@ -24736,9 +25122,9 @@ function mayTakeDotPath(pattern, file) {
|
|
|
24736
25122
|
return (!dotFile || takesDot(pattern.slice(cut + 1))) && (!dotDirectory || takesDot(pattern.slice(0, Math.max(cut, 0))));
|
|
24737
25123
|
}
|
|
24738
25124
|
var ASTRO_CONFIG_PATHS = ["astro.config.mjs", "astro.config.js", "astro.config.ts", "astro.config.mts"];
|
|
24739
|
-
async function customSrcDir(
|
|
25125
|
+
async function customSrcDir(fs3) {
|
|
24740
25126
|
for (const configPath of ASTRO_CONFIG_PATHS) {
|
|
24741
|
-
const source = await
|
|
25127
|
+
const source = await fs3.readFile(configPath).catch(() => null);
|
|
24742
25128
|
if (source === null)
|
|
24743
25129
|
continue;
|
|
24744
25130
|
const roots = configOptionMentions(source, "root");
|
|
@@ -24754,24 +25140,24 @@ async function customSrcDir(fs) {
|
|
|
24754
25140
|
return null;
|
|
24755
25141
|
if (srcDir === "src")
|
|
24756
25142
|
return;
|
|
24757
|
-
return
|
|
25143
|
+
return path3.isAbsolute(srcDir) || srcDir.startsWith("..") ? null : srcDir;
|
|
24758
25144
|
}
|
|
24759
25145
|
return;
|
|
24760
25146
|
}
|
|
24761
|
-
async function contentConfigStatus(
|
|
25147
|
+
async function contentConfigStatus(fs3, config) {
|
|
24762
25148
|
const configPaths = [...CONTENT_CONFIG_PATHS, ...UNREAD_CONTENT_CONFIG_PATHS];
|
|
24763
|
-
const srcDir = await customSrcDir(
|
|
25149
|
+
const srcDir = await customSrcDir(fs3);
|
|
24764
25150
|
if (srcDir === null)
|
|
24765
25151
|
return "unreadable";
|
|
24766
25152
|
if (srcDir !== undefined) {
|
|
24767
25153
|
for (const configPath of configPaths) {
|
|
24768
|
-
if (await
|
|
25154
|
+
if (await fs3.exists(path3.join(srcDir, path3.relative("src", configPath))))
|
|
24769
25155
|
return "unreadable";
|
|
24770
25156
|
}
|
|
24771
25157
|
}
|
|
24772
25158
|
let configFiles = 0;
|
|
24773
25159
|
for (const configPath of configPaths) {
|
|
24774
|
-
if (await
|
|
25160
|
+
if (await fs3.exists(configPath))
|
|
24775
25161
|
configFiles++;
|
|
24776
25162
|
}
|
|
24777
25163
|
if (configFiles === 0)
|
|
@@ -24780,16 +25166,16 @@ async function contentConfigStatus(fs, config) {
|
|
|
24780
25166
|
return "partial";
|
|
24781
25167
|
if (config.declared.length > 0)
|
|
24782
25168
|
return "ok";
|
|
24783
|
-
return await classifyEmptyContentConfig(
|
|
25169
|
+
return await classifyEmptyContentConfig(fs3) === "no-collections" ? "ok" : "unreadable";
|
|
24784
25170
|
}
|
|
24785
|
-
async function buildScanReport(
|
|
24786
|
-
const contentConfig = await contentConfigStatus(
|
|
25171
|
+
async function buildScanReport(fs3, contentDir, collections, config, failedScans, contentDirectories) {
|
|
25172
|
+
const contentConfig = await contentConfigStatus(fs3, config);
|
|
24787
25173
|
const unresolved = new Map;
|
|
24788
25174
|
const declaredByName = new Map(config.declared.map((declaration) => [declaration.name, declaration]));
|
|
24789
25175
|
const listed = new Set;
|
|
24790
25176
|
for (const definition of Object.values(collections)) {
|
|
24791
25177
|
for (const entry of definition.entries ?? [])
|
|
24792
|
-
listed.add(
|
|
25178
|
+
listed.add(path3.normalize(entry.sourcePath));
|
|
24793
25179
|
if ((definition.entries?.length ?? 0) >= definition.entryCount)
|
|
24794
25180
|
continue;
|
|
24795
25181
|
const declaration = declaredByName.get(definition.name);
|
|
@@ -24812,14 +25198,14 @@ async function buildScanReport(fs, contentDir, collections, config, failedScans,
|
|
|
24812
25198
|
}
|
|
24813
25199
|
let loads;
|
|
24814
25200
|
try {
|
|
24815
|
-
loads = await declaredEntryFiles(
|
|
25201
|
+
loads = await declaredEntryFiles(fs3, contentDir, declaration);
|
|
24816
25202
|
} catch {
|
|
24817
25203
|
unresolved.set(name, { name, reason: "scan-failed", ...location });
|
|
24818
25204
|
continue;
|
|
24819
25205
|
}
|
|
24820
25206
|
if (loads === null) {
|
|
24821
25207
|
unresolved.set(name, { name, reason: "unsupported-loader", ...location });
|
|
24822
|
-
} else if (!loads.files.every((file) => listed.has(
|
|
25208
|
+
} else if (!loads.files.every((file) => listed.has(path3.normalize(file)))) {
|
|
24823
25209
|
unresolved.set(name, { name, reason: loads.exact ? "unlisted-entries" : "unsupported-loader", ...location });
|
|
24824
25210
|
}
|
|
24825
25211
|
}
|
|
@@ -24828,11 +25214,11 @@ async function buildScanReport(fs, contentDir, collections, config, failedScans,
|
|
|
24828
25214
|
for (const name of contentDirectories) {
|
|
24829
25215
|
if (declaredByName.has(name) || unresolved.has(name) || failedScans.has(name))
|
|
24830
25216
|
continue;
|
|
24831
|
-
const directory =
|
|
24832
|
-
const files = await contentDirectoryFiles(
|
|
25217
|
+
const directory = path3.join(contentDir, name);
|
|
25218
|
+
const files = await contentDirectoryFiles(fs3, directory, MARKDOWN_FILE).catch(() => null);
|
|
24833
25219
|
if (files === null)
|
|
24834
25220
|
unresolved.set(name, { name, reason: "scan-failed", base: directory });
|
|
24835
|
-
else if (!files.every((file) => listed.has(
|
|
25221
|
+
else if (!files.every((file) => listed.has(path3.normalize(file))))
|
|
24836
25222
|
unresolved.set(name, { name, reason: "unlisted-entries", base: directory });
|
|
24837
25223
|
}
|
|
24838
25224
|
}
|
|
@@ -24868,28 +25254,28 @@ function warnOnPathnameCollisions(collections) {
|
|
|
24868
25254
|
}
|
|
24869
25255
|
// ../cms-core/src/component-registry.ts
|
|
24870
25256
|
var import_parser3 = __toESM(require_lib(), 1);
|
|
24871
|
-
import
|
|
24872
|
-
async function scanComponentDefinitions(
|
|
25257
|
+
import path4 from "path";
|
|
25258
|
+
async function scanComponentDefinitions(fs3, componentDirs = ["src/components"]) {
|
|
24873
25259
|
const components = {};
|
|
24874
25260
|
for (const dir of componentDirs) {
|
|
24875
|
-
await scanDirectory(
|
|
25261
|
+
await scanDirectory(fs3, dir, components);
|
|
24876
25262
|
}
|
|
24877
25263
|
return components;
|
|
24878
25264
|
}
|
|
24879
|
-
async function scanDirectory(
|
|
24880
|
-
const entries = await
|
|
25265
|
+
async function scanDirectory(fs3, relativePath, components) {
|
|
25266
|
+
const entries = await fs3.list(relativePath);
|
|
24881
25267
|
for (const entry of entries) {
|
|
24882
25268
|
const relPath = `${relativePath}/${entry.name}`;
|
|
24883
25269
|
if (entry.isDirectory) {
|
|
24884
|
-
await scanDirectory(
|
|
25270
|
+
await scanDirectory(fs3, relPath, components);
|
|
24885
25271
|
} else if (entry.name.endsWith(".astro")) {
|
|
24886
|
-
await parseComponent(
|
|
25272
|
+
await parseComponent(fs3, relPath, components);
|
|
24887
25273
|
}
|
|
24888
25274
|
}
|
|
24889
25275
|
}
|
|
24890
|
-
async function parseComponent(
|
|
24891
|
-
const content = await
|
|
24892
|
-
const componentName =
|
|
25276
|
+
async function parseComponent(fs3, relativePath, components) {
|
|
25277
|
+
const content = await fs3.readFile(relativePath);
|
|
25278
|
+
const componentName = path4.basename(relativePath, ".astro");
|
|
24893
25279
|
const props = extractProps(content);
|
|
24894
25280
|
const slots = extractSlots(content);
|
|
24895
25281
|
const description = extractDescription(content);
|
|
@@ -25078,249 +25464,209 @@ function extractProps(content) {
|
|
|
25078
25464
|
}
|
|
25079
25465
|
function extractSlots(content) {
|
|
25080
25466
|
const slots = [];
|
|
25081
|
-
const slotMatches = content.matchAll(/<slot\s+name=["']([^"']+)["']/g);
|
|
25082
|
-
for (const match of slotMatches) {
|
|
25083
|
-
if (match[1]) {
|
|
25084
|
-
slots.push(match[1]);
|
|
25085
|
-
}
|
|
25086
|
-
}
|
|
25087
|
-
const allSlotTags = content.matchAll(/<slot(?:\s+[^>]*)?\s*\/?>/g);
|
|
25088
|
-
for (const match of allSlotTags) {
|
|
25089
|
-
const tag = match[0];
|
|
25090
|
-
if (!/name\s*=/.test(tag)) {
|
|
25091
|
-
if (!slots.includes("default")) {
|
|
25092
|
-
slots.unshift("default");
|
|
25093
|
-
}
|
|
25094
|
-
break;
|
|
25095
|
-
}
|
|
25096
|
-
}
|
|
25097
|
-
return slots;
|
|
25098
|
-
}
|
|
25099
|
-
function extractDescription(content) {
|
|
25100
|
-
const match = content.match(/^---\n\/\*\*\s*([\s\S]*?)\s*\*\//);
|
|
25101
|
-
if (match?.[1]) {
|
|
25102
|
-
return match[1].split(`
|
|
25103
|
-
`).map((line) => line.replace(/^\s*\*\s?/, "").trim()).filter(Boolean).join(" ");
|
|
25104
|
-
}
|
|
25105
|
-
return;
|
|
25106
|
-
}
|
|
25107
|
-
function extractPreviewWidth(content) {
|
|
25108
|
-
const match = content.match(/^---\n\/\*\*\s*([\s\S]*?)\s*\*\//);
|
|
25109
|
-
if (match?.[1]) {
|
|
25110
|
-
const widthMatch = match[1].match(/@previewWidth\s+(\d+)/);
|
|
25111
|
-
if (widthMatch?.[1]) {
|
|
25112
|
-
return parseInt(widthMatch[1], 10);
|
|
25113
|
-
}
|
|
25114
|
-
}
|
|
25115
|
-
return;
|
|
25116
|
-
}
|
|
25117
|
-
// ../cms-core/src/handlers/entry-ops.ts
|
|
25118
|
-
var import_yaml3 = __toESM(require_dist(), 1);
|
|
25119
|
-
import path4 from "path";
|
|
25120
|
-
|
|
25121
|
-
// ../cms-core/src/media/local.ts
|
|
25122
|
-
import { randomUUID } from "crypto";
|
|
25123
|
-
import fs from "fs/promises";
|
|
25124
|
-
import path3 from "path";
|
|
25125
|
-
|
|
25126
|
-
// ../cms-core/src/media/errors.ts
|
|
25127
|
-
var MEDIA_INVALID_ID = "Invalid media id";
|
|
25128
|
-
var MEDIA_INVALID_FOLDER = "Invalid folder name";
|
|
25129
|
-
var MEDIA_NOT_FOUND = "Media file not found";
|
|
25130
|
-
function mediaErrorStatus(error) {
|
|
25131
|
-
if (error === MEDIA_INVALID_ID || error === MEDIA_INVALID_FOLDER)
|
|
25132
|
-
return 400;
|
|
25133
|
-
if (error === MEDIA_NOT_FOUND)
|
|
25134
|
-
return 404;
|
|
25135
|
-
return 500;
|
|
25136
|
-
}
|
|
25137
|
-
|
|
25138
|
-
// ../cms-core/src/media/names.ts
|
|
25139
|
-
function hasDotSegment(value) {
|
|
25140
|
-
return value.split("/").some((s) => s === "." || s === "..");
|
|
25141
|
-
}
|
|
25142
|
-
function isUnsafeFolder(folder) {
|
|
25143
|
-
return folder.includes("\\") || folder.split("/").some((s) => {
|
|
25144
|
-
const decoded = s.replace(/%2e/gi, ".");
|
|
25145
|
-
return decoded === "." || decoded === "..";
|
|
25146
|
-
});
|
|
25147
|
-
}
|
|
25148
|
-
|
|
25149
|
-
// ../cms-core/src/media/local.ts
|
|
25150
|
-
function errorCode(error) {
|
|
25151
|
-
return error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : undefined;
|
|
25152
|
-
}
|
|
25153
|
-
function failure(action, error) {
|
|
25154
|
-
const code = errorCode(error);
|
|
25155
|
-
return code ? `Failed to ${action} (${code})` : `Failed to ${action}`;
|
|
25156
|
-
}
|
|
25157
|
-
async function hasSymlink(from, names) {
|
|
25158
|
-
let current = from;
|
|
25159
|
-
for (const name of names) {
|
|
25160
|
-
current += path3.sep + name;
|
|
25161
|
-
try {
|
|
25162
|
-
if ((await fs.lstat(current)).isSymbolicLink())
|
|
25163
|
-
return true;
|
|
25164
|
-
} catch (error) {
|
|
25165
|
-
const code = errorCode(error);
|
|
25166
|
-
if (code === "ENOENT" || code === "ENOTDIR")
|
|
25167
|
-
return false;
|
|
25168
|
-
throw error;
|
|
25169
|
-
}
|
|
25170
|
-
}
|
|
25171
|
-
return false;
|
|
25172
|
-
}
|
|
25173
|
-
function createLocalStorageAdapter(options = {}) {
|
|
25174
|
-
const dir = path3.resolve(options.dir ?? "public/uploads");
|
|
25175
|
-
const base = dir.endsWith(path3.sep) ? dir.slice(0, -path3.sep.length) : dir;
|
|
25176
|
-
const urlPrefix = (options.urlPrefix ?? "/uploads").replace(/\/$/, "");
|
|
25177
|
-
async function resolveInside(relative, kind) {
|
|
25178
|
-
const segments = relative.split("/");
|
|
25179
|
-
if (relative.includes("\x00") || segments.some((s) => s === "" || s === "." || s === ".."))
|
|
25180
|
-
return null;
|
|
25181
|
-
if (path3.sep === "\\" && segments.some((s) => /[\\:]|[. ]$/.test(s)))
|
|
25182
|
-
return null;
|
|
25183
|
-
const resolved = path3.resolve(dir, ...segments);
|
|
25184
|
-
if (resolved !== [base, ...segments].join(path3.sep))
|
|
25185
|
-
return null;
|
|
25186
|
-
if (await hasSymlink(base, kind === "file" ? segments.slice(0, -1) : segments))
|
|
25187
|
-
return null;
|
|
25188
|
-
return resolved;
|
|
25189
|
-
}
|
|
25190
|
-
async function resolveFolder(input, use) {
|
|
25191
|
-
const folder = (input ?? "").split("/").filter(Boolean).join("/");
|
|
25192
|
-
if (!folder)
|
|
25193
|
-
return { folder, targetDir: dir };
|
|
25194
|
-
if (use === "write" && isUnsafeFolder(folder))
|
|
25195
|
-
return null;
|
|
25196
|
-
const targetDir = await resolveInside(folder, "folder");
|
|
25197
|
-
return targetDir ? { folder, targetDir } : null;
|
|
25198
|
-
}
|
|
25199
|
-
return {
|
|
25200
|
-
staticFiles: { urlPrefix, dir },
|
|
25201
|
-
async list(opts) {
|
|
25202
|
-
const limit = opts?.limit ?? 50;
|
|
25203
|
-
const offset = opts?.cursor ? parseInt(opts.cursor, 10) : 0;
|
|
25204
|
-
const nothing = { items: [], folders: [], hasMore: false };
|
|
25205
|
-
try {
|
|
25206
|
-
const target = await resolveFolder(opts?.folder, "read");
|
|
25207
|
-
if (!target)
|
|
25208
|
-
return nothing;
|
|
25209
|
-
const { folder, targetDir } = target;
|
|
25210
|
-
await fs.mkdir(targetDir, { recursive: true });
|
|
25211
|
-
const entries = await fs.readdir(targetDir, { withFileTypes: true });
|
|
25212
|
-
const folders = entries.filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => ({
|
|
25213
|
-
name: e.name,
|
|
25214
|
-
path: folder ? `${folder}/${e.name}` : e.name
|
|
25215
|
-
})).sort((a, b) => a.name.localeCompare(b.name));
|
|
25216
|
-
const files = entries.filter((e) => e.isFile() && !e.name.startsWith("."));
|
|
25217
|
-
const withStats = await Promise.all(files.map(async (f) => {
|
|
25218
|
-
const filePath = path3.join(targetDir, f.name);
|
|
25219
|
-
const stat = await fs.stat(filePath);
|
|
25220
|
-
return { name: f.name, stat };
|
|
25221
|
-
}));
|
|
25222
|
-
withStats.sort((a, b) => b.stat.mtimeMs - a.stat.mtimeMs);
|
|
25223
|
-
const slice = withStats.slice(offset, offset + limit);
|
|
25224
|
-
const hasMore = offset + limit < withStats.length;
|
|
25225
|
-
const urlFolder = folder ? `/${folder}` : "";
|
|
25226
|
-
const items = slice.map((f) => {
|
|
25227
|
-
const ext = path3.extname(f.name).toLowerCase();
|
|
25228
|
-
const contentType = mimeFromExt(ext);
|
|
25229
|
-
return {
|
|
25230
|
-
id: folder ? `${folder}/${f.name}` : f.name,
|
|
25231
|
-
url: `${urlPrefix}${urlFolder}/${f.name}`,
|
|
25232
|
-
filename: f.name,
|
|
25233
|
-
contentType,
|
|
25234
|
-
uploadedAt: f.stat.mtime.toISOString(),
|
|
25235
|
-
folder: folder || undefined
|
|
25236
|
-
};
|
|
25237
|
-
});
|
|
25238
|
-
return {
|
|
25239
|
-
items,
|
|
25240
|
-
folders,
|
|
25241
|
-
hasMore,
|
|
25242
|
-
cursor: hasMore ? String(offset + limit) : undefined
|
|
25243
|
-
};
|
|
25244
|
-
} catch (error) {
|
|
25245
|
-
const code = errorCode(error);
|
|
25246
|
-
if (opts?.folder && (code === "ENOTDIR" || code === "EEXIST" || code === "ENAMETOOLONG"))
|
|
25247
|
-
return nothing;
|
|
25248
|
-
throw new Error(failure("list media", error));
|
|
25249
|
-
}
|
|
25250
|
-
},
|
|
25251
|
-
async upload(file, filename, contentType, uploadOpts) {
|
|
25252
|
-
try {
|
|
25253
|
-
const target = await resolveFolder(uploadOpts?.folder, "write");
|
|
25254
|
-
if (!target)
|
|
25255
|
-
return { success: false, error: MEDIA_INVALID_FOLDER };
|
|
25256
|
-
const { folder, targetDir } = target;
|
|
25257
|
-
await fs.mkdir(targetDir, { recursive: true });
|
|
25258
|
-
const ext = getFileExtension(filename);
|
|
25259
|
-
const uuid = randomUUID();
|
|
25260
|
-
const newFilename = `${uuid}${ext ? `.${ext}` : ""}`;
|
|
25261
|
-
const filePath = path3.join(targetDir, newFilename);
|
|
25262
|
-
await fs.writeFile(filePath, file);
|
|
25263
|
-
const urlFolder = folder ? `/${folder}` : "";
|
|
25264
|
-
const id = folder ? `${folder}/${newFilename}` : newFilename;
|
|
25265
|
-
return {
|
|
25266
|
-
success: true,
|
|
25267
|
-
url: `${urlPrefix}${urlFolder}/${newFilename}`,
|
|
25268
|
-
filename: newFilename,
|
|
25269
|
-
id
|
|
25270
|
-
};
|
|
25271
|
-
} catch (error) {
|
|
25272
|
-
return { success: false, error: failure("store media file", error) };
|
|
25467
|
+
const slotMatches = content.matchAll(/<slot\s+name=["']([^"']+)["']/g);
|
|
25468
|
+
for (const match of slotMatches) {
|
|
25469
|
+
if (match[1]) {
|
|
25470
|
+
slots.push(match[1]);
|
|
25471
|
+
}
|
|
25472
|
+
}
|
|
25473
|
+
const allSlotTags = content.matchAll(/<slot(?:\s+[^>]*)?\s*\/?>/g);
|
|
25474
|
+
for (const match of allSlotTags) {
|
|
25475
|
+
const tag = match[0];
|
|
25476
|
+
if (!/name\s*=/.test(tag)) {
|
|
25477
|
+
if (!slots.includes("default")) {
|
|
25478
|
+
slots.unshift("default");
|
|
25273
25479
|
}
|
|
25480
|
+
break;
|
|
25481
|
+
}
|
|
25482
|
+
}
|
|
25483
|
+
return slots;
|
|
25484
|
+
}
|
|
25485
|
+
function extractDescription(content) {
|
|
25486
|
+
const match = content.match(/^---\n\/\*\*\s*([\s\S]*?)\s*\*\//);
|
|
25487
|
+
if (match?.[1]) {
|
|
25488
|
+
return match[1].split(`
|
|
25489
|
+
`).map((line) => line.replace(/^\s*\*\s?/, "").trim()).filter(Boolean).join(" ");
|
|
25490
|
+
}
|
|
25491
|
+
return;
|
|
25492
|
+
}
|
|
25493
|
+
function extractPreviewWidth(content) {
|
|
25494
|
+
const match = content.match(/^---\n\/\*\*\s*([\s\S]*?)\s*\*\//);
|
|
25495
|
+
if (match?.[1]) {
|
|
25496
|
+
const widthMatch = match[1].match(/@previewWidth\s+(\d+)/);
|
|
25497
|
+
if (widthMatch?.[1]) {
|
|
25498
|
+
return parseInt(widthMatch[1], 10);
|
|
25499
|
+
}
|
|
25500
|
+
}
|
|
25501
|
+
return;
|
|
25502
|
+
}
|
|
25503
|
+
// ../cms-core/src/fs/staged.ts
|
|
25504
|
+
import { createHash } from "crypto";
|
|
25505
|
+
class CmsCommitConflictError extends Error {
|
|
25506
|
+
paths;
|
|
25507
|
+
constructor(paths) {
|
|
25508
|
+
super(`Changed since the edit read them: ${paths.join(", ")}`);
|
|
25509
|
+
this.paths = paths;
|
|
25510
|
+
this.name = "CmsCommitConflictError";
|
|
25511
|
+
}
|
|
25512
|
+
}
|
|
25513
|
+
function digestBytes(content) {
|
|
25514
|
+
return `sha256:${createHash("sha256").update(content).digest("hex")}`;
|
|
25515
|
+
}
|
|
25516
|
+
function normalize(path5) {
|
|
25517
|
+
const segments = [];
|
|
25518
|
+
for (const segment of path5.split("/")) {
|
|
25519
|
+
if (segment === "" || segment === ".")
|
|
25520
|
+
continue;
|
|
25521
|
+
if (segment === ".." && segments.length > 0 && segments.at(-1) !== "..")
|
|
25522
|
+
segments.pop();
|
|
25523
|
+
else
|
|
25524
|
+
segments.push(segment);
|
|
25525
|
+
}
|
|
25526
|
+
return segments.join("/");
|
|
25527
|
+
}
|
|
25528
|
+
function isBelow(path5, dir) {
|
|
25529
|
+
return dir === "" || path5.startsWith(`${dir}/`);
|
|
25530
|
+
}
|
|
25531
|
+
function missing(path5) {
|
|
25532
|
+
return Object.assign(new Error(`ENOENT: no such file, '${path5}'`), { code: "ENOENT" });
|
|
25533
|
+
}
|
|
25534
|
+
function createStagedFileSystem(base) {
|
|
25535
|
+
const reads = new Map;
|
|
25536
|
+
const staged = new Map;
|
|
25537
|
+
const encoder = new TextEncoder;
|
|
25538
|
+
const decoder = new TextDecoder;
|
|
25539
|
+
function observe(path5, version) {
|
|
25540
|
+
const recorded = reads.get(path5);
|
|
25541
|
+
if (recorded === undefined || recorded.kind === "present" && version.kind === "content")
|
|
25542
|
+
reads.set(path5, version);
|
|
25543
|
+
}
|
|
25544
|
+
async function observeBeforeChange(path5) {
|
|
25545
|
+
if (staged.has(path5))
|
|
25546
|
+
return;
|
|
25547
|
+
const recorded = reads.get(path5);
|
|
25548
|
+
if (recorded !== undefined && recorded.kind !== "present")
|
|
25549
|
+
return;
|
|
25550
|
+
observe(path5, await versionOf(base, path5));
|
|
25551
|
+
}
|
|
25552
|
+
async function readBytes(rawPath) {
|
|
25553
|
+
const path5 = normalize(rawPath);
|
|
25554
|
+
const change = staged.get(path5);
|
|
25555
|
+
if (change === null)
|
|
25556
|
+
throw missing(path5);
|
|
25557
|
+
if (change !== undefined)
|
|
25558
|
+
return change.content.slice();
|
|
25559
|
+
try {
|
|
25560
|
+
const content = await base.readBytes(path5);
|
|
25561
|
+
observe(path5, { kind: "content", digest: digestBytes(content) });
|
|
25562
|
+
return content;
|
|
25563
|
+
} catch (error) {
|
|
25564
|
+
if (!await base.exists(path5))
|
|
25565
|
+
observe(path5, { kind: "absent" });
|
|
25566
|
+
throw error;
|
|
25567
|
+
}
|
|
25568
|
+
}
|
|
25569
|
+
async function write(rawPath, content) {
|
|
25570
|
+
const path5 = normalize(rawPath);
|
|
25571
|
+
await observeBeforeChange(path5);
|
|
25572
|
+
staged.set(path5, { content: content.slice(), mtimeMs: Date.now() });
|
|
25573
|
+
}
|
|
25574
|
+
async function remove(rawPath) {
|
|
25575
|
+
const path5 = normalize(rawPath);
|
|
25576
|
+
await observeBeforeChange(path5);
|
|
25577
|
+
staged.set(path5, null);
|
|
25578
|
+
}
|
|
25579
|
+
function stagedBelow(dir) {
|
|
25580
|
+
return [...staged].filter(([path5, change]) => change !== null && isBelow(path5, dir)).map(([path5]) => path5);
|
|
25581
|
+
}
|
|
25582
|
+
return {
|
|
25583
|
+
async readFile(path5) {
|
|
25584
|
+
return decoder.decode(await readBytes(path5));
|
|
25274
25585
|
},
|
|
25275
|
-
|
|
25276
|
-
|
|
25277
|
-
|
|
25278
|
-
if (!filePath)
|
|
25279
|
-
return { success: false, error: MEDIA_INVALID_ID };
|
|
25280
|
-
await fs.unlink(filePath);
|
|
25281
|
-
return { success: true };
|
|
25282
|
-
} catch (error) {
|
|
25283
|
-
if (errorCode(error) === "ENOENT")
|
|
25284
|
-
return { success: false, error: MEDIA_NOT_FOUND };
|
|
25285
|
-
return { success: false, error: failure("delete media file", error) };
|
|
25286
|
-
}
|
|
25586
|
+
readBytes,
|
|
25587
|
+
writeFile(path5, content) {
|
|
25588
|
+
return write(path5, encoder.encode(content));
|
|
25287
25589
|
},
|
|
25288
|
-
|
|
25289
|
-
|
|
25290
|
-
|
|
25291
|
-
|
|
25292
|
-
|
|
25293
|
-
|
|
25294
|
-
|
|
25295
|
-
|
|
25296
|
-
|
|
25590
|
+
writeBytes: write,
|
|
25591
|
+
async rename(from, to) {
|
|
25592
|
+
const content = await readBytes(from);
|
|
25593
|
+
await remove(from);
|
|
25594
|
+
await write(to, content);
|
|
25595
|
+
},
|
|
25596
|
+
remove,
|
|
25597
|
+
async exists(rawPath) {
|
|
25598
|
+
const path5 = normalize(rawPath);
|
|
25599
|
+
const change = staged.get(path5);
|
|
25600
|
+
if (change !== undefined)
|
|
25601
|
+
return change !== null;
|
|
25602
|
+
if (stagedBelow(path5).length > 0)
|
|
25603
|
+
return true;
|
|
25604
|
+
const exists = await base.exists(path5);
|
|
25605
|
+
observe(path5, exists ? { kind: "present" } : { kind: "absent" });
|
|
25606
|
+
return exists;
|
|
25607
|
+
},
|
|
25608
|
+
async list(rawDir) {
|
|
25609
|
+
const dir = normalize(rawDir);
|
|
25610
|
+
const entries = new Map((await base.list(dir)).map((entry) => [entry.name, entry.isDirectory]));
|
|
25611
|
+
for (const [path5, change] of staged) {
|
|
25612
|
+
if (!isBelow(path5, dir))
|
|
25613
|
+
continue;
|
|
25614
|
+
const rest = dir === "" ? path5 : path5.slice(dir.length + 1);
|
|
25615
|
+
const [name, ...deeper] = rest.split("/");
|
|
25616
|
+
if (name === undefined)
|
|
25617
|
+
continue;
|
|
25618
|
+
if (deeper.length > 0) {
|
|
25619
|
+
if (change !== null)
|
|
25620
|
+
entries.set(name, true);
|
|
25621
|
+
} else if (change === null) {
|
|
25622
|
+
entries.delete(name);
|
|
25623
|
+
} else {
|
|
25624
|
+
entries.set(name, false);
|
|
25625
|
+
}
|
|
25297
25626
|
}
|
|
25627
|
+
return [...entries].map(([name, isDirectory]) => ({ name, isDirectory }));
|
|
25628
|
+
},
|
|
25629
|
+
async glob(pattern, options) {
|
|
25630
|
+
const matcher = globToRegExp(pattern);
|
|
25631
|
+
const files = new Set(await base.glob(pattern, options));
|
|
25632
|
+
for (const [path5, change] of staged) {
|
|
25633
|
+
if (change === null)
|
|
25634
|
+
files.delete(path5);
|
|
25635
|
+
else if (matcher.test(path5))
|
|
25636
|
+
files.add(path5);
|
|
25637
|
+
}
|
|
25638
|
+
return [...files];
|
|
25639
|
+
},
|
|
25640
|
+
async stat(rawPath) {
|
|
25641
|
+
const path5 = normalize(rawPath);
|
|
25642
|
+
const change = staged.get(path5);
|
|
25643
|
+
if (change === null)
|
|
25644
|
+
throw missing(path5);
|
|
25645
|
+
if (change !== undefined)
|
|
25646
|
+
return { mtimeMs: change.mtimeMs, size: change.content.byteLength };
|
|
25647
|
+
const stat = await base.stat(path5);
|
|
25648
|
+
observe(path5, { kind: "present" });
|
|
25649
|
+
return stat;
|
|
25650
|
+
},
|
|
25651
|
+
changeset() {
|
|
25652
|
+
const changes = [...staged].map(([path5, change]) => change === null ? { kind: "remove", path: path5 } : { kind: "write", path: path5, content: change.content });
|
|
25653
|
+
return { reads: new Map(reads), changes };
|
|
25298
25654
|
}
|
|
25299
25655
|
};
|
|
25300
25656
|
}
|
|
25301
|
-
function
|
|
25302
|
-
|
|
25303
|
-
|
|
25304
|
-
|
|
25305
|
-
}
|
|
25306
|
-
|
|
25307
|
-
|
|
25308
|
-
|
|
25309
|
-
".png": "image/png",
|
|
25310
|
-
".gif": "image/gif",
|
|
25311
|
-
".webp": "image/webp",
|
|
25312
|
-
".avif": "image/avif",
|
|
25313
|
-
".svg": "image/svg+xml",
|
|
25314
|
-
".ico": "image/x-icon",
|
|
25315
|
-
".mp4": "video/mp4",
|
|
25316
|
-
".webm": "video/webm",
|
|
25317
|
-
".pdf": "application/pdf"
|
|
25318
|
-
};
|
|
25319
|
-
function mimeFromExt(ext) {
|
|
25320
|
-
return MIME_BY_EXT[ext] ?? "application/octet-stream";
|
|
25657
|
+
async function versionOf(fs3, path5) {
|
|
25658
|
+
if (!await fs3.exists(path5))
|
|
25659
|
+
return { kind: "absent" };
|
|
25660
|
+
try {
|
|
25661
|
+
return { kind: "content", digest: digestBytes(await fs3.readBytes(path5)) };
|
|
25662
|
+
} catch {
|
|
25663
|
+
return { kind: "present" };
|
|
25664
|
+
}
|
|
25321
25665
|
}
|
|
25322
25666
|
|
|
25323
25667
|
// ../cms-core/src/handlers/entry-ops.ts
|
|
25668
|
+
var import_yaml3 = __toESM(require_dist(), 1);
|
|
25669
|
+
import path5 from "path";
|
|
25324
25670
|
var MARKDOWN_EXTENSIONS = ["md", "mdx"];
|
|
25325
25671
|
function fileExtension(filePath) {
|
|
25326
25672
|
const idx = filePath.lastIndexOf(".");
|
|
@@ -25341,12 +25687,12 @@ async function resolveEntryPath(deps, collection, slug) {
|
|
|
25341
25687
|
const base = await resolveCollectionDir(deps, collection);
|
|
25342
25688
|
const flatExts = ["md", "mdx", "json", "yaml", "yml"];
|
|
25343
25689
|
for (const ext of flatExts) {
|
|
25344
|
-
const candidate =
|
|
25690
|
+
const candidate = path5.posix.join(base, `${slug}.${ext}`);
|
|
25345
25691
|
if (await deps.fs.exists(candidate))
|
|
25346
25692
|
return candidate;
|
|
25347
25693
|
}
|
|
25348
25694
|
for (const ext of MARKDOWN_EXTENSIONS) {
|
|
25349
|
-
const candidate =
|
|
25695
|
+
const candidate = path5.posix.join(base, slug, `index.${ext}`);
|
|
25350
25696
|
if (await deps.fs.exists(candidate))
|
|
25351
25697
|
return candidate;
|
|
25352
25698
|
}
|
|
@@ -25512,7 +25858,7 @@ async function inferLayoutFromExistingEntries(deps, collection) {
|
|
|
25512
25858
|
if (flatSlugs.has(dir.name))
|
|
25513
25859
|
return false;
|
|
25514
25860
|
for (const ext of MARKDOWN_EXTENSIONS) {
|
|
25515
|
-
if (await deps.fs.exists(
|
|
25861
|
+
if (await deps.fs.exists(path5.posix.join(collectionPath, dir.name, `index.${ext}`)))
|
|
25516
25862
|
return true;
|
|
25517
25863
|
}
|
|
25518
25864
|
return false;
|
|
@@ -25570,8 +25916,8 @@ async function missingRequiredFields(deps, collection, frontmatter) {
|
|
|
25570
25916
|
return [];
|
|
25571
25917
|
return blankRequiredFields(parsedCollection.fields, frontmatter);
|
|
25572
25918
|
}
|
|
25573
|
-
function missingRequiredMessage(
|
|
25574
|
-
return
|
|
25919
|
+
function missingRequiredMessage(missing2) {
|
|
25920
|
+
return missing2.length === 1 ? `Field "${missing2[0]}" is required` : `Required fields are empty: ${missing2.join(", ")}`;
|
|
25575
25921
|
}
|
|
25576
25922
|
function errorMessage(error) {
|
|
25577
25923
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -25607,14 +25953,14 @@ async function createEntry(deps, input) {
|
|
|
25607
25953
|
}
|
|
25608
25954
|
const seeded = await applyEntrySlugField(deps, collection, frontmatter, normalizedSlug);
|
|
25609
25955
|
const resolved = await applyDerivedFields(deps, collection, seeded);
|
|
25610
|
-
const
|
|
25611
|
-
if (
|
|
25612
|
-
return { success: false, error: missingRequiredMessage(
|
|
25956
|
+
const missing2 = await missingRequiredFields(deps, collection, resolved);
|
|
25957
|
+
if (missing2.length > 0) {
|
|
25958
|
+
return { success: false, error: missingRequiredMessage(missing2) };
|
|
25613
25959
|
}
|
|
25614
25960
|
const isData = ext === "json" || ext === "yaml" || ext === "yml";
|
|
25615
25961
|
const layout = isData ? "flat" : await detectCollectionMarkdownLayout(deps, collection);
|
|
25616
25962
|
const collectionDir = await resolveCollectionDir(deps, collection);
|
|
25617
|
-
const sourcePath = layout === "index" ?
|
|
25963
|
+
const sourcePath = layout === "index" ? path5.posix.join(collectionDir, normalizedSlug, `index.${ext}`) : path5.posix.join(collectionDir, `${normalizedSlug}.${ext}`);
|
|
25618
25964
|
let fileContent;
|
|
25619
25965
|
if (isData) {
|
|
25620
25966
|
fileContent = ext === "json" ? JSON.stringify({ ...resolved }, null, 2) + `
|
|
@@ -25644,9 +25990,9 @@ async function updateEntry(deps, input) {
|
|
|
25644
25990
|
const existing = sourcePath.endsWith(".json") ? JSON.parse(raw) : import_yaml3.default.parse(raw);
|
|
25645
25991
|
const merged = { ...existing ?? {}, ...patch };
|
|
25646
25992
|
const resolved = await applyDerivedFields(deps, input.collection, merged, patch ?? {});
|
|
25647
|
-
const
|
|
25648
|
-
if (
|
|
25649
|
-
return { success: false, error: missingRequiredMessage(
|
|
25993
|
+
const missing2 = await missingRequiredFields(deps, input.collection, resolved);
|
|
25994
|
+
if (missing2.length > 0) {
|
|
25995
|
+
return { success: false, error: missingRequiredMessage(missing2) };
|
|
25650
25996
|
}
|
|
25651
25997
|
const output = sourcePath.endsWith(".json") ? JSON.stringify(resolved, null, 2) + `
|
|
25652
25998
|
` : import_yaml3.default.stringify(resolved);
|
|
@@ -25659,9 +26005,9 @@ async function updateEntry(deps, input) {
|
|
|
25659
26005
|
...patch
|
|
25660
26006
|
};
|
|
25661
26007
|
const resolvedFrontmatter = await applyDerivedFields(deps, input.collection, mergedFrontmatter, patch ?? {});
|
|
25662
|
-
const
|
|
25663
|
-
if (
|
|
25664
|
-
return { success: false, error: missingRequiredMessage(
|
|
26008
|
+
const missing2 = await missingRequiredFields(deps, input.collection, resolvedFrontmatter);
|
|
26009
|
+
if (missing2.length > 0) {
|
|
26010
|
+
return { success: false, error: missingRequiredMessage(missing2) };
|
|
25665
26011
|
}
|
|
25666
26012
|
let finalContent = input.body ?? existing.content;
|
|
25667
26013
|
if (sourcePath.endsWith(".mdx")) {
|
|
@@ -26191,227 +26537,91 @@ function parseRedirectLines(lines) {
|
|
|
26191
26537
|
}
|
|
26192
26538
|
|
|
26193
26539
|
// ../cms-core/src/core.ts
|
|
26194
|
-
function createCmsCore(
|
|
26540
|
+
function createCmsCore(fs3, opts = {}) {
|
|
26195
26541
|
const contentDir = opts.contentDir ?? "src/content";
|
|
26196
26542
|
const componentDirs = opts.componentDirs ?? ["src/components"];
|
|
26543
|
+
const commit = opts.commit;
|
|
26197
26544
|
const parseCache = new Map;
|
|
26198
|
-
|
|
26199
|
-
|
|
26200
|
-
|
|
26201
|
-
|
|
26202
|
-
|
|
26203
|
-
|
|
26204
|
-
|
|
26545
|
+
function entryDeps(over) {
|
|
26546
|
+
return {
|
|
26547
|
+
fs: over,
|
|
26548
|
+
contentDir,
|
|
26549
|
+
parseCache,
|
|
26550
|
+
componentDirs,
|
|
26551
|
+
resolveComponentDefinitions: () => scanComponentDefinitions(over, componentDirs)
|
|
26552
|
+
};
|
|
26553
|
+
}
|
|
26554
|
+
const readDeps = entryDeps(fs3);
|
|
26555
|
+
async function mutate(operation) {
|
|
26556
|
+
if (commit === undefined)
|
|
26557
|
+
return operation(fs3);
|
|
26558
|
+
const staged = createStagedFileSystem(fs3);
|
|
26559
|
+
const result = await operation(staged);
|
|
26560
|
+
await commit(staged.changeset());
|
|
26561
|
+
return result;
|
|
26562
|
+
}
|
|
26205
26563
|
return {
|
|
26206
26564
|
scanCollections(options) {
|
|
26207
|
-
return scanCollections(
|
|
26565
|
+
return scanCollections(fs3, contentDir, parseCache, { report: options?.report ?? false });
|
|
26208
26566
|
},
|
|
26209
26567
|
collectionScanReport,
|
|
26210
26568
|
scanComponents() {
|
|
26211
|
-
return scanComponentDefinitions(
|
|
26569
|
+
return scanComponentDefinitions(fs3, componentDirs);
|
|
26212
26570
|
},
|
|
26213
26571
|
getEntry(collection, slug) {
|
|
26214
|
-
return getEntry(
|
|
26572
|
+
return getEntry(readDeps, collection, slug);
|
|
26215
26573
|
},
|
|
26216
26574
|
getEntryAsset(collection, slug, assetPath) {
|
|
26217
|
-
return getEntryAsset(
|
|
26575
|
+
return getEntryAsset(readDeps, collection, slug, assetPath);
|
|
26218
26576
|
},
|
|
26219
26577
|
getProjectAsset(assetPath) {
|
|
26220
|
-
return getProjectAsset(
|
|
26578
|
+
return getProjectAsset(readDeps, assetPath);
|
|
26221
26579
|
},
|
|
26222
26580
|
createEntry(input) {
|
|
26223
|
-
return createEntry(entryDeps, input);
|
|
26581
|
+
return mutate((over) => createEntry(entryDeps(over), input));
|
|
26224
26582
|
},
|
|
26225
26583
|
updateEntry(input) {
|
|
26226
|
-
return updateEntry(entryDeps, input);
|
|
26584
|
+
return mutate((over) => updateEntry(entryDeps(over), input));
|
|
26227
26585
|
},
|
|
26228
26586
|
deleteEntry(collection, slug) {
|
|
26229
|
-
return deleteEntry(entryDeps, collection, slug);
|
|
26587
|
+
return mutate((over) => deleteEntry(entryDeps(over), collection, slug));
|
|
26230
26588
|
},
|
|
26231
26589
|
renameEntry(collection, from, to) {
|
|
26232
|
-
return renameEntry(entryDeps, collection, from, to);
|
|
26590
|
+
return mutate((over) => renameEntry(entryDeps(over), collection, from, to));
|
|
26233
26591
|
},
|
|
26234
26592
|
addArrayItem(input) {
|
|
26235
|
-
return addArrayItem(entryDeps, input);
|
|
26593
|
+
return mutate((over) => addArrayItem(entryDeps(over), input));
|
|
26236
26594
|
},
|
|
26237
26595
|
removeArrayItem(input) {
|
|
26238
|
-
return removeArrayItem(entryDeps, input);
|
|
26596
|
+
return mutate((over) => removeArrayItem(entryDeps(over), input));
|
|
26239
26597
|
},
|
|
26240
26598
|
createPage(input) {
|
|
26241
|
-
return createPage({ fs:
|
|
26599
|
+
return mutate((over) => createPage({ fs: over }, input));
|
|
26242
26600
|
},
|
|
26243
26601
|
duplicatePage(input) {
|
|
26244
|
-
return duplicatePage({ fs:
|
|
26602
|
+
return mutate((over) => duplicatePage({ fs: over }, input));
|
|
26245
26603
|
},
|
|
26246
26604
|
deletePage(input) {
|
|
26247
|
-
return deletePage({ fs:
|
|
26605
|
+
return mutate((over) => deletePage({ fs: over }, input));
|
|
26248
26606
|
},
|
|
26249
26607
|
getLayouts() {
|
|
26250
|
-
return getLayouts({ fs:
|
|
26608
|
+
return getLayouts({ fs: fs3 });
|
|
26251
26609
|
},
|
|
26252
26610
|
listRedirects() {
|
|
26253
|
-
return listRedirects({ fs:
|
|
26611
|
+
return listRedirects({ fs: fs3 });
|
|
26254
26612
|
},
|
|
26255
26613
|
addRedirect(input) {
|
|
26256
|
-
return addRedirect({ fs:
|
|
26614
|
+
return mutate((over) => addRedirect({ fs: over }, input));
|
|
26257
26615
|
},
|
|
26258
26616
|
updateRedirect(input) {
|
|
26259
|
-
return updateRedirect({ fs:
|
|
26617
|
+
return mutate((over) => updateRedirect({ fs: over }, input));
|
|
26260
26618
|
},
|
|
26261
26619
|
deleteRedirect(input) {
|
|
26262
|
-
return deleteRedirect({ fs:
|
|
26620
|
+
return mutate((over) => deleteRedirect({ fs: over }, input));
|
|
26263
26621
|
},
|
|
26264
26622
|
media: opts.media
|
|
26265
26623
|
};
|
|
26266
26624
|
}
|
|
26267
|
-
// ../cms-core/src/fs/node-fs.ts
|
|
26268
|
-
import fs2 from "fs/promises";
|
|
26269
|
-
import path5 from "path";
|
|
26270
|
-
function resolveWithinRoot(root, filePath) {
|
|
26271
|
-
const resolvedRoot = path5.resolve(root);
|
|
26272
|
-
const isAbsoluteFs = filePath.startsWith(resolvedRoot);
|
|
26273
|
-
const normalizedPath = !isAbsoluteFs && filePath.startsWith("/") ? filePath.slice(1) : filePath;
|
|
26274
|
-
const fullPath = path5.isAbsolute(normalizedPath) ? path5.resolve(normalizedPath) : path5.resolve(resolvedRoot, normalizedPath);
|
|
26275
|
-
if (!fullPath.startsWith(resolvedRoot + path5.sep) && fullPath !== resolvedRoot) {
|
|
26276
|
-
throw new Error(`Path traversal detected: ${filePath}`);
|
|
26277
|
-
}
|
|
26278
|
-
return fullPath;
|
|
26279
|
-
}
|
|
26280
|
-
function isNodeError(error) {
|
|
26281
|
-
return error instanceof Error && "code" in error;
|
|
26282
|
-
}
|
|
26283
|
-
var isWithin = (root, abs) => abs === root || abs.startsWith(root.endsWith(path5.sep) ? root : root + path5.sep);
|
|
26284
|
-
var relativeTo = (absRoot, abs) => path5.relative(absRoot, abs).split(path5.sep).join("/") || ".";
|
|
26285
|
-
async function walkFiles(walk, absDir, linked) {
|
|
26286
|
-
if (linked.size > 0 && walk.linkedDirectoriesLeft !== undefined && walk.linkedDirectoriesLeft-- <= 0) {
|
|
26287
|
-
throw new Error(`More than ${walk.maxLinkedDirectories} directories to list behind symbolic links`);
|
|
26288
|
-
}
|
|
26289
|
-
let dirEntries;
|
|
26290
|
-
try {
|
|
26291
|
-
dirEntries = await fs2.readdir(absDir, { withFileTypes: true });
|
|
26292
|
-
} catch (error) {
|
|
26293
|
-
if (!isNodeError(error))
|
|
26294
|
-
throw error;
|
|
26295
|
-
if (error.code === "ENOENT" || error.code === "ENOTDIR")
|
|
26296
|
-
return [];
|
|
26297
|
-
throw new UnreadableDirectoryError(relativeTo(walk.absRoot, absDir), error.code ?? "unknown error", { cause: error });
|
|
26298
|
-
}
|
|
26299
|
-
const out = [];
|
|
26300
|
-
for (const entry of dirEntries) {
|
|
26301
|
-
const abs = path5.join(absDir, entry.name);
|
|
26302
|
-
let isDirectory = entry.isDirectory();
|
|
26303
|
-
let isFile = entry.isFile();
|
|
26304
|
-
let within = linked;
|
|
26305
|
-
let real = null;
|
|
26306
|
-
if (walk.followSymlinks && entry.isSymbolicLink()) {
|
|
26307
|
-
const target = await fs2.stat(abs).catch(() => null);
|
|
26308
|
-
real = target?.isDirectory() ? await fs2.realpath(abs).catch(() => abs) : null;
|
|
26309
|
-
isFile = target?.isFile() ?? false;
|
|
26310
|
-
isDirectory = real !== null && !linked.has(real);
|
|
26311
|
-
if (real !== null)
|
|
26312
|
-
within = new Set([...linked, real]);
|
|
26313
|
-
}
|
|
26314
|
-
if (isDirectory) {
|
|
26315
|
-
if (walk.skip(relativeTo(walk.absRoot, abs)))
|
|
26316
|
-
continue;
|
|
26317
|
-
if (!walk.mayHold(relativeTo(walk.absRoot, abs)))
|
|
26318
|
-
continue;
|
|
26319
|
-
if (real !== null && !isWithin(walk.realRoot, real)) {
|
|
26320
|
-
throw new Error(`Symbolic link "${relativeTo(walk.absRoot, abs)}" leads out of the project root`);
|
|
26321
|
-
}
|
|
26322
|
-
out.push(...await walkFiles(walk, abs, within));
|
|
26323
|
-
} else if (isFile) {
|
|
26324
|
-
out.push(relativeTo(walk.absRoot, abs));
|
|
26325
|
-
}
|
|
26326
|
-
}
|
|
26327
|
-
return out;
|
|
26328
|
-
}
|
|
26329
|
-
function staticPrefixDir(pattern) {
|
|
26330
|
-
const segments = pattern.split("/");
|
|
26331
|
-
const staticSegments = [];
|
|
26332
|
-
for (const segment of segments) {
|
|
26333
|
-
if (/[*?{}[\]]/.test(segment))
|
|
26334
|
-
break;
|
|
26335
|
-
staticSegments.push(segment);
|
|
26336
|
-
}
|
|
26337
|
-
if (staticSegments.length === segments.length) {
|
|
26338
|
-
staticSegments.pop();
|
|
26339
|
-
}
|
|
26340
|
-
return staticSegments.join("/");
|
|
26341
|
-
}
|
|
26342
|
-
function createNodeFs(root) {
|
|
26343
|
-
const resolvedRoot = path5.resolve(root);
|
|
26344
|
-
const resolve = (p) => resolveWithinRoot(resolvedRoot, p);
|
|
26345
|
-
return {
|
|
26346
|
-
async readFile(filePath) {
|
|
26347
|
-
return fs2.readFile(resolve(filePath), "utf-8");
|
|
26348
|
-
},
|
|
26349
|
-
async readBytes(filePath) {
|
|
26350
|
-
return fs2.readFile(resolve(filePath));
|
|
26351
|
-
},
|
|
26352
|
-
async writeFile(filePath, content) {
|
|
26353
|
-
const fullPath = resolve(filePath);
|
|
26354
|
-
await fs2.mkdir(path5.dirname(fullPath), { recursive: true });
|
|
26355
|
-
const tempPath = `${fullPath}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
26356
|
-
try {
|
|
26357
|
-
await fs2.writeFile(tempPath, content, "utf-8");
|
|
26358
|
-
await fs2.rename(tempPath, fullPath);
|
|
26359
|
-
} catch (error) {
|
|
26360
|
-
await fs2.rm(tempPath, { force: true });
|
|
26361
|
-
throw error;
|
|
26362
|
-
}
|
|
26363
|
-
},
|
|
26364
|
-
async rename(from, to) {
|
|
26365
|
-
const fullTo = resolve(to);
|
|
26366
|
-
await fs2.mkdir(path5.dirname(fullTo), { recursive: true });
|
|
26367
|
-
await fs2.rename(resolve(from), fullTo);
|
|
26368
|
-
},
|
|
26369
|
-
async remove(filePath) {
|
|
26370
|
-
await fs2.rm(resolve(filePath), { force: true });
|
|
26371
|
-
},
|
|
26372
|
-
async exists(filePath) {
|
|
26373
|
-
try {
|
|
26374
|
-
await fs2.access(resolve(filePath));
|
|
26375
|
-
return true;
|
|
26376
|
-
} catch {
|
|
26377
|
-
return false;
|
|
26378
|
-
}
|
|
26379
|
-
},
|
|
26380
|
-
async list(dir) {
|
|
26381
|
-
try {
|
|
26382
|
-
const entries = await fs2.readdir(resolve(dir), { withFileTypes: true });
|
|
26383
|
-
return entries.map((entry) => ({ name: entry.name, isDirectory: entry.isDirectory() }));
|
|
26384
|
-
} catch (error) {
|
|
26385
|
-
if (isNodeError(error) && error.code === "ENOENT")
|
|
26386
|
-
return [];
|
|
26387
|
-
throw error;
|
|
26388
|
-
}
|
|
26389
|
-
},
|
|
26390
|
-
async glob(pattern, options) {
|
|
26391
|
-
const baseRel = staticPrefixDir(pattern);
|
|
26392
|
-
const absBase = resolve(baseRel);
|
|
26393
|
-
const matcher = globToRegExp(pattern);
|
|
26394
|
-
const followSymlinks = options?.followSymlinks ?? false;
|
|
26395
|
-
const walk = {
|
|
26396
|
-
absRoot: resolvedRoot,
|
|
26397
|
-
mayHold: (dir) => globMayMatchUnder(pattern, dir),
|
|
26398
|
-
skip: options?.skipDirectory ?? (() => false),
|
|
26399
|
-
followSymlinks,
|
|
26400
|
-
realRoot: followSymlinks ? await fs2.realpath(resolvedRoot).catch(() => resolvedRoot) : resolvedRoot,
|
|
26401
|
-
maxLinkedDirectories: options?.maxLinkedDirectories,
|
|
26402
|
-
linkedDirectoriesLeft: options?.maxLinkedDirectories
|
|
26403
|
-
};
|
|
26404
|
-
if (!walk.mayHold(relativeTo(resolvedRoot, absBase)))
|
|
26405
|
-
return [];
|
|
26406
|
-
const files = await walkFiles(walk, absBase, new Set);
|
|
26407
|
-
return files.filter((rel) => matcher.test(rel));
|
|
26408
|
-
},
|
|
26409
|
-
async stat(filePath) {
|
|
26410
|
-
const s = await fs2.stat(resolve(filePath));
|
|
26411
|
-
return { mtimeMs: s.mtimeMs, size: s.size };
|
|
26412
|
-
}
|
|
26413
|
-
};
|
|
26414
|
-
}
|
|
26415
26625
|
// ../cms-core/src/media/contember.ts
|
|
26416
26626
|
function createContemberStorageAdapter(options) {
|
|
26417
26627
|
const { apiBaseUrl, projectSlug, sessionToken } = options;
|
|
@@ -27103,9 +27313,9 @@ function mediaFromEnv(env = process.env) {
|
|
|
27103
27313
|
}
|
|
27104
27314
|
|
|
27105
27315
|
// src/concurrency.ts
|
|
27106
|
-
import { createHash } from "crypto";
|
|
27316
|
+
import { createHash as createHash2 } from "crypto";
|
|
27107
27317
|
function hashContent(content) {
|
|
27108
|
-
return `sha256:${
|
|
27318
|
+
return `sha256:${createHash2("sha256").update(content, "utf-8").digest("hex")}`;
|
|
27109
27319
|
}
|
|
27110
27320
|
async function hashSource(fs3, sourcePath) {
|
|
27111
27321
|
if (!await fs3.exists(sourcePath))
|
|
@@ -27202,6 +27412,19 @@ function error(code, message, sourcePath) {
|
|
|
27202
27412
|
body.sourcePath = sourcePath;
|
|
27203
27413
|
return json(body, STATUS_BY_CODE[code]);
|
|
27204
27414
|
}
|
|
27415
|
+
function assetBytesResponse(asset, req) {
|
|
27416
|
+
const size = asset.bytes.byteLength;
|
|
27417
|
+
const headers = { "content-type": asset.contentType, "cache-control": "no-cache", "accept-ranges": "bytes" };
|
|
27418
|
+
const range = resolveByteRange(req.headers.get("range"), size);
|
|
27419
|
+
if (range === null)
|
|
27420
|
+
return new Response(asset.bytes, { headers });
|
|
27421
|
+
if (range === "unsatisfiable")
|
|
27422
|
+
return new Response(null, { status: 416, headers: { ...headers, "content-range": `bytes */${size}` } });
|
|
27423
|
+
return new Response(asset.bytes.subarray(range.start, range.end + 1), {
|
|
27424
|
+
status: 206,
|
|
27425
|
+
headers: { ...headers, "content-range": `bytes ${range.start}-${range.end}/${size}` }
|
|
27426
|
+
});
|
|
27427
|
+
}
|
|
27205
27428
|
function mutationResponse(result, fallback = "validation") {
|
|
27206
27429
|
if (result.success)
|
|
27207
27430
|
return json(result);
|
|
@@ -27534,48 +27757,62 @@ function createServer(opts) {
|
|
|
27534
27757
|
};
|
|
27535
27758
|
return json(entry);
|
|
27536
27759
|
}
|
|
27537
|
-
async function assetResponse(collection, slug, url) {
|
|
27760
|
+
async function assetResponse(collection, slug, req, url) {
|
|
27538
27761
|
const assetPath = url.searchParams.get("path");
|
|
27539
27762
|
if (assetPath === null || assetPath === "")
|
|
27540
27763
|
return error("validation", 'A "path" query parameter is required');
|
|
27541
27764
|
const asset = await core.getEntryAsset(collection, slug, assetPath);
|
|
27542
27765
|
if (!asset)
|
|
27543
27766
|
return error("not_found", `Asset not found for ${collection}/${slug}: ${assetPath}`);
|
|
27544
|
-
return
|
|
27767
|
+
return assetBytesResponse(asset, req);
|
|
27545
27768
|
}
|
|
27546
|
-
async function projectAssetResponse(url) {
|
|
27769
|
+
async function projectAssetResponse(req, url) {
|
|
27547
27770
|
const assetPath = url.searchParams.get("path");
|
|
27548
27771
|
if (assetPath === null || assetPath === "")
|
|
27549
27772
|
return error("validation", 'A "path" query parameter is required');
|
|
27550
27773
|
const asset = await core.getProjectAsset(assetPath);
|
|
27551
27774
|
if (!asset)
|
|
27552
27775
|
return error("not_found", `Asset not found: ${assetPath}`);
|
|
27553
|
-
return
|
|
27776
|
+
return assetBytesResponse(asset, req);
|
|
27554
27777
|
}
|
|
27555
27778
|
async function patchEntry(collection, slug, body) {
|
|
27556
27779
|
const existing = await core.getEntry(collection, slug);
|
|
27557
27780
|
if (!existing)
|
|
27558
27781
|
return error("not_found", `Entry not found: ${collection}/${slug}`);
|
|
27559
27782
|
const sourcePath = existing.sourcePath;
|
|
27783
|
+
const existingFrontmatter = existing.frontmatter;
|
|
27784
|
+
async function conflictResponse(serverHash) {
|
|
27785
|
+
const current = await core.getEntry(collection, slug);
|
|
27786
|
+
const conflict = {
|
|
27787
|
+
code: "conflict",
|
|
27788
|
+
serverHash,
|
|
27789
|
+
serverFrontmatter: current?.frontmatter ?? existingFrontmatter
|
|
27790
|
+
};
|
|
27791
|
+
if (current && current.content !== "")
|
|
27792
|
+
conflict.serverBody = current.content;
|
|
27793
|
+
return json(conflict, STATUS_BY_CODE.conflict);
|
|
27794
|
+
}
|
|
27560
27795
|
return mutex.runExclusive(sourcePath, async () => {
|
|
27561
27796
|
const serverHash = await hashSource(fs3, sourcePath);
|
|
27562
27797
|
if (body.baseHash !== undefined && serverHash !== null && body.baseHash !== serverHash) {
|
|
27563
|
-
|
|
27564
|
-
|
|
27565
|
-
|
|
27566
|
-
|
|
27567
|
-
|
|
27568
|
-
|
|
27569
|
-
|
|
27570
|
-
|
|
27571
|
-
|
|
27572
|
-
|
|
27573
|
-
|
|
27574
|
-
|
|
27575
|
-
|
|
27576
|
-
|
|
27577
|
-
|
|
27578
|
-
|
|
27798
|
+
return conflictResponse(serverHash);
|
|
27799
|
+
}
|
|
27800
|
+
let result;
|
|
27801
|
+
try {
|
|
27802
|
+
result = await core.updateEntry({
|
|
27803
|
+
collection,
|
|
27804
|
+
slug,
|
|
27805
|
+
frontmatter: body.frontmatter,
|
|
27806
|
+
body: body.body
|
|
27807
|
+
});
|
|
27808
|
+
} catch (cause) {
|
|
27809
|
+
if (!(cause instanceof CmsCommitConflictError))
|
|
27810
|
+
throw cause;
|
|
27811
|
+
const currentHash = await hashSource(fs3, sourcePath);
|
|
27812
|
+
if (currentHash === null)
|
|
27813
|
+
throw cause;
|
|
27814
|
+
return conflictResponse(currentHash);
|
|
27815
|
+
}
|
|
27579
27816
|
if (!result.success)
|
|
27580
27817
|
return mutationResponse(result);
|
|
27581
27818
|
const newHash = await hashSource(fs3, result.sourcePath ?? sourcePath);
|
|
@@ -27606,6 +27843,10 @@ function createServer(opts) {
|
|
|
27606
27843
|
const method = req.method;
|
|
27607
27844
|
try {
|
|
27608
27845
|
return await route(method, segments, req, url);
|
|
27846
|
+
} catch (cause) {
|
|
27847
|
+
if (cause instanceof CmsCommitConflictError)
|
|
27848
|
+
return error("conflict", cause.message);
|
|
27849
|
+
throw cause;
|
|
27609
27850
|
} finally {
|
|
27610
27851
|
if (method !== "GET") {
|
|
27611
27852
|
collectionsScan.invalidate();
|
|
@@ -27642,7 +27883,7 @@ function createServer(opts) {
|
|
|
27642
27883
|
break;
|
|
27643
27884
|
case "asset":
|
|
27644
27885
|
if (method === "GET")
|
|
27645
|
-
return projectAssetResponse(url);
|
|
27886
|
+
return projectAssetResponse(req, url);
|
|
27646
27887
|
break;
|
|
27647
27888
|
case "collections":
|
|
27648
27889
|
return routeCollections(method, tail, req, url);
|
|
@@ -27686,7 +27927,7 @@ function createServer(opts) {
|
|
|
27686
27927
|
if (action === "array" && method === "DELETE")
|
|
27687
27928
|
return removeArrayRoute(collection, slug, req);
|
|
27688
27929
|
if (action === "asset" && method === "GET")
|
|
27689
|
-
return assetResponse(collection, slug, url);
|
|
27930
|
+
return assetResponse(collection, slug, req, url);
|
|
27690
27931
|
}
|
|
27691
27932
|
return error("not_found", `No route: ${method} /cms/v1/collections/${tail.join("/")}`);
|
|
27692
27933
|
}
|