@dyrected/core 2.5.8 → 2.5.10
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/dist/app-DZt5nslu.d.ts +334 -331
- package/dist/app-Dk3SzV1a.d.cts +374 -0
- package/dist/app-Dk3SzV1a.d.ts +374 -0
- package/dist/chunk-3VUH2MNW.js +1903 -0
- package/dist/chunk-45JDQDA2.js +1899 -0
- package/dist/index.cjs +80 -54
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -5
- package/dist/server.cjs +74 -50
- package/dist/server.d.cts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1008,10 +1008,11 @@ function parseSqlWhere(where, getJsonField, placeholder = "?") {
|
|
|
1008
1008
|
function buildClause(w) {
|
|
1009
1009
|
const parts = [];
|
|
1010
1010
|
for (const [field, value] of Object.entries(w)) {
|
|
1011
|
-
|
|
1011
|
+
const upperField = field.toUpperCase();
|
|
1012
|
+
if (upperField === "OR" && Array.isArray(value)) {
|
|
1012
1013
|
const sub = value.map((v) => `(${buildClause(v)})`).join(" OR ");
|
|
1013
1014
|
parts.push(`(${sub})`);
|
|
1014
|
-
} else if (
|
|
1015
|
+
} else if (upperField === "AND" && Array.isArray(value)) {
|
|
1015
1016
|
const sub = value.map((v) => `(${buildClause(v)})`).join(" AND ");
|
|
1016
1017
|
parts.push(`(${sub})`);
|
|
1017
1018
|
} else {
|
|
@@ -1070,9 +1071,10 @@ function parseMongoWhere(where) {
|
|
|
1070
1071
|
function buildClause(w) {
|
|
1071
1072
|
const conditions = [];
|
|
1072
1073
|
for (const [field, value] of Object.entries(w)) {
|
|
1073
|
-
|
|
1074
|
+
const upperField = field.toUpperCase();
|
|
1075
|
+
if (upperField === "OR" && Array.isArray(value)) {
|
|
1074
1076
|
conditions.push({ $or: value.map(buildClause) });
|
|
1075
|
-
} else if (
|
|
1077
|
+
} else if (upperField === "AND" && Array.isArray(value)) {
|
|
1076
1078
|
conditions.push({ $and: value.map(buildClause) });
|
|
1077
1079
|
} else {
|
|
1078
1080
|
conditions.push(buildOperator(field, value));
|
|
@@ -1090,6 +1092,49 @@ var import_hono = require("hono");
|
|
|
1090
1092
|
var import_cors = require("hono/cors");
|
|
1091
1093
|
var import_request_id = require("hono/request-id");
|
|
1092
1094
|
|
|
1095
|
+
// src/services/defaults.service.ts
|
|
1096
|
+
var DefaultsService = class {
|
|
1097
|
+
/**
|
|
1098
|
+
* Recursively apply default values to a data object based on field definitions.
|
|
1099
|
+
*/
|
|
1100
|
+
static apply(fields, data = {}) {
|
|
1101
|
+
const result = { ...data || {} };
|
|
1102
|
+
fields.forEach((field) => {
|
|
1103
|
+
if (field.type === "join") return;
|
|
1104
|
+
if (field.type === "row" && field.fields) {
|
|
1105
|
+
Object.assign(result, this.apply(field.fields, data));
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
if (!field.name) return;
|
|
1109
|
+
let value = result[field.name];
|
|
1110
|
+
if ((value === void 0 || value === null) && field.renameTo) {
|
|
1111
|
+
const legacyValue = result[field.renameTo];
|
|
1112
|
+
if (legacyValue !== void 0 && legacyValue !== null) {
|
|
1113
|
+
value = legacyValue;
|
|
1114
|
+
result[field.name] = legacyValue;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
if (value === void 0 || value === null) {
|
|
1118
|
+
if (field.defaultValue !== void 0) {
|
|
1119
|
+
result[field.name] = field.defaultValue;
|
|
1120
|
+
} else {
|
|
1121
|
+
if (field.type === "boolean") result[field.name] = false;
|
|
1122
|
+
else if (field.type === "array") result[field.name] = [];
|
|
1123
|
+
else if (field.type === "multiSelect") result[field.name] = [];
|
|
1124
|
+
else if (field.type === "object") {
|
|
1125
|
+
result[field.name] = this.apply(field.fields || [], {});
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
} else if (field.type === "object" && field.fields) {
|
|
1129
|
+
result[field.name] = this.apply(field.fields, value);
|
|
1130
|
+
} else if (field.type === "array" && field.fields && Array.isArray(value)) {
|
|
1131
|
+
result[field.name] = value.map((item) => this.apply(field.fields, item));
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
return result;
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1093
1138
|
// src/services/population.service.ts
|
|
1094
1139
|
var PopulationService = class {
|
|
1095
1140
|
db;
|
|
@@ -1102,7 +1147,7 @@ var PopulationService = class {
|
|
|
1102
1147
|
* Recursively populate relationship fields in a document or array of documents.
|
|
1103
1148
|
*/
|
|
1104
1149
|
async populate(args) {
|
|
1105
|
-
const { data, fields, currentDepth, maxDepth } = args;
|
|
1150
|
+
const { data, fields, currentDepth = 0, maxDepth = 10 } = args;
|
|
1106
1151
|
if (currentDepth >= maxDepth || !data) {
|
|
1107
1152
|
return data;
|
|
1108
1153
|
}
|
|
@@ -1131,8 +1176,9 @@ var PopulationService = class {
|
|
|
1131
1176
|
doc = await this.db.findOne({ collection: field.relationTo, id });
|
|
1132
1177
|
}
|
|
1133
1178
|
if (!doc || typeof doc !== "object") return id;
|
|
1179
|
+
const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
|
|
1134
1180
|
return this.populate({
|
|
1135
|
-
data:
|
|
1181
|
+
data: docWithDefaults,
|
|
1136
1182
|
fields: relatedCollection.fields,
|
|
1137
1183
|
currentDepth: currentDepth + 1,
|
|
1138
1184
|
maxDepth
|
|
@@ -1145,12 +1191,35 @@ var PopulationService = class {
|
|
|
1145
1191
|
doc = await this.db.findOne({ collection: field.relationTo, id: value });
|
|
1146
1192
|
}
|
|
1147
1193
|
if (doc && typeof doc === "object") {
|
|
1194
|
+
const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
|
|
1148
1195
|
populatedDoc[field.name] = await this.populate({
|
|
1149
|
-
data:
|
|
1196
|
+
data: docWithDefaults,
|
|
1197
|
+
fields: relatedCollection.fields,
|
|
1198
|
+
currentDepth: currentDepth + 1,
|
|
1199
|
+
maxDepth
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
if (field.type === "url" && value && typeof value === "object" && value.type === "internal" && value.relationTo && value.value) {
|
|
1205
|
+
const relatedCollection = this.collections.find((c) => c.slug === value.relationTo);
|
|
1206
|
+
if (relatedCollection) {
|
|
1207
|
+
const doc = await this.db.findOne({ collection: value.relationTo, id: value.value });
|
|
1208
|
+
if (doc && typeof doc === "object") {
|
|
1209
|
+
const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
|
|
1210
|
+
const populatedDocValue = await this.populate({
|
|
1211
|
+
data: docWithDefaults,
|
|
1150
1212
|
fields: relatedCollection.fields,
|
|
1151
1213
|
currentDepth: currentDepth + 1,
|
|
1152
1214
|
maxDepth
|
|
1153
1215
|
});
|
|
1216
|
+
const identifier = docWithDefaults.slug || docWithDefaults.id;
|
|
1217
|
+
const resolvedUrl = `/collections/${value.relationTo}/${identifier}`;
|
|
1218
|
+
populatedDoc[field.name] = {
|
|
1219
|
+
...value,
|
|
1220
|
+
url: resolvedUrl,
|
|
1221
|
+
doc: populatedDocValue
|
|
1222
|
+
};
|
|
1154
1223
|
}
|
|
1155
1224
|
}
|
|
1156
1225
|
}
|
|
@@ -1198,49 +1267,6 @@ var PopulationService = class {
|
|
|
1198
1267
|
}
|
|
1199
1268
|
};
|
|
1200
1269
|
|
|
1201
|
-
// src/services/defaults.service.ts
|
|
1202
|
-
var DefaultsService = class {
|
|
1203
|
-
/**
|
|
1204
|
-
* Recursively apply default values to a data object based on field definitions.
|
|
1205
|
-
*/
|
|
1206
|
-
static apply(fields, data = {}) {
|
|
1207
|
-
const result = { ...data || {} };
|
|
1208
|
-
fields.forEach((field) => {
|
|
1209
|
-
if (field.type === "join") return;
|
|
1210
|
-
if (field.type === "row" && field.fields) {
|
|
1211
|
-
Object.assign(result, this.apply(field.fields, data));
|
|
1212
|
-
return;
|
|
1213
|
-
}
|
|
1214
|
-
if (!field.name) return;
|
|
1215
|
-
let value = result[field.name];
|
|
1216
|
-
if ((value === void 0 || value === null) && field.renameTo) {
|
|
1217
|
-
const legacyValue = result[field.renameTo];
|
|
1218
|
-
if (legacyValue !== void 0 && legacyValue !== null) {
|
|
1219
|
-
value = legacyValue;
|
|
1220
|
-
result[field.name] = legacyValue;
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
if (value === void 0 || value === null) {
|
|
1224
|
-
if (field.defaultValue !== void 0) {
|
|
1225
|
-
result[field.name] = field.defaultValue;
|
|
1226
|
-
} else {
|
|
1227
|
-
if (field.type === "boolean") result[field.name] = false;
|
|
1228
|
-
else if (field.type === "array") result[field.name] = [];
|
|
1229
|
-
else if (field.type === "multiSelect") result[field.name] = [];
|
|
1230
|
-
else if (field.type === "object") {
|
|
1231
|
-
result[field.name] = this.apply(field.fields || [], {});
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
} else if (field.type === "object" && field.fields) {
|
|
1235
|
-
result[field.name] = this.apply(field.fields, value);
|
|
1236
|
-
} else if (field.type === "array" && field.fields && Array.isArray(value)) {
|
|
1237
|
-
result[field.name] = value.map((item) => this.apply(field.fields, item));
|
|
1238
|
-
}
|
|
1239
|
-
});
|
|
1240
|
-
return result;
|
|
1241
|
-
}
|
|
1242
|
-
};
|
|
1243
|
-
|
|
1244
1270
|
// src/services/audit.service.ts
|
|
1245
1271
|
var AuditService = class {
|
|
1246
1272
|
/**
|
|
@@ -1281,7 +1307,7 @@ var CollectionController = class {
|
|
|
1281
1307
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
1282
1308
|
const limit = Number(c.req.query("limit")) || 10;
|
|
1283
1309
|
const page = Number(c.req.query("page")) || 1;
|
|
1284
|
-
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) :
|
|
1310
|
+
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 2;
|
|
1285
1311
|
const sort = c.req.query("sort") || void 0;
|
|
1286
1312
|
let where = void 0;
|
|
1287
1313
|
const whereRaw = c.req.query("where");
|
|
@@ -1323,7 +1349,7 @@ var CollectionController = class {
|
|
|
1323
1349
|
const db = config.db;
|
|
1324
1350
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
1325
1351
|
const id = c.req.param("id");
|
|
1326
|
-
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) :
|
|
1352
|
+
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 10;
|
|
1327
1353
|
if (!id) return c.json({ message: "Missing ID" }, 400);
|
|
1328
1354
|
const doc = await db.findOne({ collection: this.collection.slug, id });
|
|
1329
1355
|
if (!doc) return c.json({ message: "Not Found" }, 404);
|
|
@@ -1544,7 +1570,7 @@ var GlobalController = class {
|
|
|
1544
1570
|
const config = c.get("config");
|
|
1545
1571
|
const db = config.db;
|
|
1546
1572
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
1547
|
-
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) :
|
|
1573
|
+
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 10;
|
|
1548
1574
|
let data = await db.getGlobal({ slug: this.global.slug });
|
|
1549
1575
|
const isEmpty = !data || Object.keys(data).length === 0;
|
|
1550
1576
|
if (isEmpty && this.global.initialData) {
|
|
@@ -1558,7 +1584,7 @@ var GlobalController = class {
|
|
|
1558
1584
|
const populatedData = await populationService.populate({
|
|
1559
1585
|
data: dataWithDefaults,
|
|
1560
1586
|
fields: this.global.fields,
|
|
1561
|
-
currentDepth:
|
|
1587
|
+
currentDepth: 0,
|
|
1562
1588
|
maxDepth: depth
|
|
1563
1589
|
});
|
|
1564
1590
|
return c.json(populatedData);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-
|
|
2
|
-
export { A as AccessFunction, a as AdminConfig, B as Block, b as DatabaseAdapter, c as DyrectedContext, F as Field, d as FieldHook, e as FieldType, f as FileData, H as HookFunction, I as ImageService, P as PaginatedResult, S as StorageAdapter, U as UploadConfig, g as createDyrectedApp } from './app-
|
|
1
|
+
import { D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-Dk3SzV1a.cjs';
|
|
2
|
+
export { A as AccessFunction, a as AdminConfig, B as Block, b as DatabaseAdapter, c as DyrectedContext, F as Field, d as FieldHook, e as FieldType, f as FileData, H as HookFunction, I as ImageService, P as PaginatedResult, S as StorageAdapter, U as UploadConfig, g as createDyrectedApp } from './app-Dk3SzV1a.cjs';
|
|
3
3
|
import 'hono/types';
|
|
4
4
|
import 'hono';
|
|
5
5
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-
|
|
2
|
-
export { A as AccessFunction, a as AdminConfig, B as Block, b as DatabaseAdapter, c as DyrectedContext, F as Field, d as FieldHook, e as FieldType, f as FileData, H as HookFunction, I as ImageService, P as PaginatedResult, S as StorageAdapter, U as UploadConfig, g as createDyrectedApp } from './app-
|
|
1
|
+
import { D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-Dk3SzV1a.js';
|
|
2
|
+
export { A as AccessFunction, a as AdminConfig, B as Block, b as DatabaseAdapter, c as DyrectedContext, F as Field, d as FieldHook, e as FieldType, f as FileData, H as HookFunction, I as ImageService, P as PaginatedResult, S as StorageAdapter, U as UploadConfig, g as createDyrectedApp } from './app-Dk3SzV1a.js';
|
|
3
3
|
import 'hono/types';
|
|
4
4
|
import 'hono';
|
|
5
5
|
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createDyrectedApp,
|
|
3
3
|
normalizeConfig
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-3VUH2MNW.js";
|
|
5
5
|
|
|
6
6
|
// src/utils/setup-prompt.ts
|
|
7
7
|
function buildEnvironmentSection(frameworkLabel, isSelfHosted, config) {
|
|
@@ -902,10 +902,11 @@ function parseSqlWhere(where, getJsonField, placeholder = "?") {
|
|
|
902
902
|
function buildClause(w) {
|
|
903
903
|
const parts = [];
|
|
904
904
|
for (const [field, value] of Object.entries(w)) {
|
|
905
|
-
|
|
905
|
+
const upperField = field.toUpperCase();
|
|
906
|
+
if (upperField === "OR" && Array.isArray(value)) {
|
|
906
907
|
const sub = value.map((v) => `(${buildClause(v)})`).join(" OR ");
|
|
907
908
|
parts.push(`(${sub})`);
|
|
908
|
-
} else if (
|
|
909
|
+
} else if (upperField === "AND" && Array.isArray(value)) {
|
|
909
910
|
const sub = value.map((v) => `(${buildClause(v)})`).join(" AND ");
|
|
910
911
|
parts.push(`(${sub})`);
|
|
911
912
|
} else {
|
|
@@ -964,9 +965,10 @@ function parseMongoWhere(where) {
|
|
|
964
965
|
function buildClause(w) {
|
|
965
966
|
const conditions = [];
|
|
966
967
|
for (const [field, value] of Object.entries(w)) {
|
|
967
|
-
|
|
968
|
+
const upperField = field.toUpperCase();
|
|
969
|
+
if (upperField === "OR" && Array.isArray(value)) {
|
|
968
970
|
conditions.push({ $or: value.map(buildClause) });
|
|
969
|
-
} else if (
|
|
971
|
+
} else if (upperField === "AND" && Array.isArray(value)) {
|
|
970
972
|
conditions.push({ $and: value.map(buildClause) });
|
|
971
973
|
} else {
|
|
972
974
|
conditions.push(buildOperator(field, value));
|
package/dist/server.cjs
CHANGED
|
@@ -45,6 +45,49 @@ var import_hono = require("hono");
|
|
|
45
45
|
var import_cors = require("hono/cors");
|
|
46
46
|
var import_request_id = require("hono/request-id");
|
|
47
47
|
|
|
48
|
+
// src/services/defaults.service.ts
|
|
49
|
+
var DefaultsService = class {
|
|
50
|
+
/**
|
|
51
|
+
* Recursively apply default values to a data object based on field definitions.
|
|
52
|
+
*/
|
|
53
|
+
static apply(fields, data = {}) {
|
|
54
|
+
const result = { ...data || {} };
|
|
55
|
+
fields.forEach((field) => {
|
|
56
|
+
if (field.type === "join") return;
|
|
57
|
+
if (field.type === "row" && field.fields) {
|
|
58
|
+
Object.assign(result, this.apply(field.fields, data));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!field.name) return;
|
|
62
|
+
let value = result[field.name];
|
|
63
|
+
if ((value === void 0 || value === null) && field.renameTo) {
|
|
64
|
+
const legacyValue = result[field.renameTo];
|
|
65
|
+
if (legacyValue !== void 0 && legacyValue !== null) {
|
|
66
|
+
value = legacyValue;
|
|
67
|
+
result[field.name] = legacyValue;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (value === void 0 || value === null) {
|
|
71
|
+
if (field.defaultValue !== void 0) {
|
|
72
|
+
result[field.name] = field.defaultValue;
|
|
73
|
+
} else {
|
|
74
|
+
if (field.type === "boolean") result[field.name] = false;
|
|
75
|
+
else if (field.type === "array") result[field.name] = [];
|
|
76
|
+
else if (field.type === "multiSelect") result[field.name] = [];
|
|
77
|
+
else if (field.type === "object") {
|
|
78
|
+
result[field.name] = this.apply(field.fields || [], {});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
} else if (field.type === "object" && field.fields) {
|
|
82
|
+
result[field.name] = this.apply(field.fields, value);
|
|
83
|
+
} else if (field.type === "array" && field.fields && Array.isArray(value)) {
|
|
84
|
+
result[field.name] = value.map((item) => this.apply(field.fields, item));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
48
91
|
// src/services/population.service.ts
|
|
49
92
|
var PopulationService = class {
|
|
50
93
|
db;
|
|
@@ -57,7 +100,7 @@ var PopulationService = class {
|
|
|
57
100
|
* Recursively populate relationship fields in a document or array of documents.
|
|
58
101
|
*/
|
|
59
102
|
async populate(args) {
|
|
60
|
-
const { data, fields, currentDepth, maxDepth } = args;
|
|
103
|
+
const { data, fields, currentDepth = 0, maxDepth = 10 } = args;
|
|
61
104
|
if (currentDepth >= maxDepth || !data) {
|
|
62
105
|
return data;
|
|
63
106
|
}
|
|
@@ -86,8 +129,9 @@ var PopulationService = class {
|
|
|
86
129
|
doc = await this.db.findOne({ collection: field.relationTo, id });
|
|
87
130
|
}
|
|
88
131
|
if (!doc || typeof doc !== "object") return id;
|
|
132
|
+
const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
|
|
89
133
|
return this.populate({
|
|
90
|
-
data:
|
|
134
|
+
data: docWithDefaults,
|
|
91
135
|
fields: relatedCollection.fields,
|
|
92
136
|
currentDepth: currentDepth + 1,
|
|
93
137
|
maxDepth
|
|
@@ -100,12 +144,35 @@ var PopulationService = class {
|
|
|
100
144
|
doc = await this.db.findOne({ collection: field.relationTo, id: value });
|
|
101
145
|
}
|
|
102
146
|
if (doc && typeof doc === "object") {
|
|
147
|
+
const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
|
|
103
148
|
populatedDoc[field.name] = await this.populate({
|
|
104
|
-
data:
|
|
149
|
+
data: docWithDefaults,
|
|
150
|
+
fields: relatedCollection.fields,
|
|
151
|
+
currentDepth: currentDepth + 1,
|
|
152
|
+
maxDepth
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (field.type === "url" && value && typeof value === "object" && value.type === "internal" && value.relationTo && value.value) {
|
|
158
|
+
const relatedCollection = this.collections.find((c) => c.slug === value.relationTo);
|
|
159
|
+
if (relatedCollection) {
|
|
160
|
+
const doc = await this.db.findOne({ collection: value.relationTo, id: value.value });
|
|
161
|
+
if (doc && typeof doc === "object") {
|
|
162
|
+
const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
|
|
163
|
+
const populatedDocValue = await this.populate({
|
|
164
|
+
data: docWithDefaults,
|
|
105
165
|
fields: relatedCollection.fields,
|
|
106
166
|
currentDepth: currentDepth + 1,
|
|
107
167
|
maxDepth
|
|
108
168
|
});
|
|
169
|
+
const identifier = docWithDefaults.slug || docWithDefaults.id;
|
|
170
|
+
const resolvedUrl = `/collections/${value.relationTo}/${identifier}`;
|
|
171
|
+
populatedDoc[field.name] = {
|
|
172
|
+
...value,
|
|
173
|
+
url: resolvedUrl,
|
|
174
|
+
doc: populatedDocValue
|
|
175
|
+
};
|
|
109
176
|
}
|
|
110
177
|
}
|
|
111
178
|
}
|
|
@@ -153,49 +220,6 @@ var PopulationService = class {
|
|
|
153
220
|
}
|
|
154
221
|
};
|
|
155
222
|
|
|
156
|
-
// src/services/defaults.service.ts
|
|
157
|
-
var DefaultsService = class {
|
|
158
|
-
/**
|
|
159
|
-
* Recursively apply default values to a data object based on field definitions.
|
|
160
|
-
*/
|
|
161
|
-
static apply(fields, data = {}) {
|
|
162
|
-
const result = { ...data || {} };
|
|
163
|
-
fields.forEach((field) => {
|
|
164
|
-
if (field.type === "join") return;
|
|
165
|
-
if (field.type === "row" && field.fields) {
|
|
166
|
-
Object.assign(result, this.apply(field.fields, data));
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
if (!field.name) return;
|
|
170
|
-
let value = result[field.name];
|
|
171
|
-
if ((value === void 0 || value === null) && field.renameTo) {
|
|
172
|
-
const legacyValue = result[field.renameTo];
|
|
173
|
-
if (legacyValue !== void 0 && legacyValue !== null) {
|
|
174
|
-
value = legacyValue;
|
|
175
|
-
result[field.name] = legacyValue;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (value === void 0 || value === null) {
|
|
179
|
-
if (field.defaultValue !== void 0) {
|
|
180
|
-
result[field.name] = field.defaultValue;
|
|
181
|
-
} else {
|
|
182
|
-
if (field.type === "boolean") result[field.name] = false;
|
|
183
|
-
else if (field.type === "array") result[field.name] = [];
|
|
184
|
-
else if (field.type === "multiSelect") result[field.name] = [];
|
|
185
|
-
else if (field.type === "object") {
|
|
186
|
-
result[field.name] = this.apply(field.fields || [], {});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
} else if (field.type === "object" && field.fields) {
|
|
190
|
-
result[field.name] = this.apply(field.fields, value);
|
|
191
|
-
} else if (field.type === "array" && field.fields && Array.isArray(value)) {
|
|
192
|
-
result[field.name] = value.map((item) => this.apply(field.fields, item));
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
return result;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
223
|
// src/services/audit.service.ts
|
|
200
224
|
var AuditService = class {
|
|
201
225
|
/**
|
|
@@ -236,7 +260,7 @@ var CollectionController = class {
|
|
|
236
260
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
237
261
|
const limit = Number(c.req.query("limit")) || 10;
|
|
238
262
|
const page = Number(c.req.query("page")) || 1;
|
|
239
|
-
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) :
|
|
263
|
+
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 2;
|
|
240
264
|
const sort = c.req.query("sort") || void 0;
|
|
241
265
|
let where = void 0;
|
|
242
266
|
const whereRaw = c.req.query("where");
|
|
@@ -278,7 +302,7 @@ var CollectionController = class {
|
|
|
278
302
|
const db = config.db;
|
|
279
303
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
280
304
|
const id = c.req.param("id");
|
|
281
|
-
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) :
|
|
305
|
+
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 10;
|
|
282
306
|
if (!id) return c.json({ message: "Missing ID" }, 400);
|
|
283
307
|
const doc = await db.findOne({ collection: this.collection.slug, id });
|
|
284
308
|
if (!doc) return c.json({ message: "Not Found" }, 404);
|
|
@@ -499,7 +523,7 @@ var GlobalController = class {
|
|
|
499
523
|
const config = c.get("config");
|
|
500
524
|
const db = config.db;
|
|
501
525
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
502
|
-
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) :
|
|
526
|
+
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 10;
|
|
503
527
|
let data = await db.getGlobal({ slug: this.global.slug });
|
|
504
528
|
const isEmpty = !data || Object.keys(data).length === 0;
|
|
505
529
|
if (isEmpty && this.global.initialData) {
|
|
@@ -513,7 +537,7 @@ var GlobalController = class {
|
|
|
513
537
|
const populatedData = await populationService.populate({
|
|
514
538
|
data: dataWithDefaults,
|
|
515
539
|
fields: this.global.fields,
|
|
516
|
-
currentDepth:
|
|
540
|
+
currentDepth: 0,
|
|
517
541
|
maxDepth: depth
|
|
518
542
|
});
|
|
519
543
|
return c.json(populatedData);
|
package/dist/server.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-
|
|
2
|
-
export { g as createDyrectedApp } from './app-
|
|
1
|
+
import { c as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-Dk3SzV1a.cjs';
|
|
2
|
+
export { g as createDyrectedApp } from './app-Dk3SzV1a.cjs';
|
|
3
3
|
import * as hono from 'hono';
|
|
4
4
|
import { Hono, Context } from 'hono';
|
|
5
5
|
import * as hono_utils_http_status from 'hono/utils/http-status';
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-
|
|
2
|
-
export { g as createDyrectedApp } from './app-
|
|
1
|
+
import { c as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-Dk3SzV1a.js';
|
|
2
|
+
export { g as createDyrectedApp } from './app-Dk3SzV1a.js';
|
|
3
3
|
import * as hono from 'hono';
|
|
4
4
|
import { Hono, Context } from 'hono';
|
|
5
5
|
import * as hono_utils_http_status from 'hono/utils/http-status';
|
package/dist/server.js
CHANGED