@blinkk/root-cms 3.0.1-beta.3 → 3.0.1-beta.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blinkk/root-cms",
3
- "version": "3.0.1-beta.3",
3
+ "version": "3.0.1-beta.4",
4
4
  "author": "s@blinkk.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -152,10 +152,10 @@
152
152
  "vite": "8.0.3",
153
153
  "vitest": "4.1.2",
154
154
  "yjs": "13.6.27",
155
- "@blinkk/root": "3.0.1-beta.3"
155
+ "@blinkk/root": "3.0.1-beta.4"
156
156
  },
157
157
  "peerDependencies": {
158
- "@blinkk/root": "3.0.1-beta.3",
158
+ "@blinkk/root": "3.0.1-beta.4",
159
159
  "firebase-admin": ">=11",
160
160
  "firebase-functions": ">=4"
161
161
  },
@@ -1,298 +0,0 @@
1
- // core/validation.ts
2
- function validateFields(fieldsData, schema) {
3
- if (fieldsData === null || fieldsData === void 0) {
4
- return [];
5
- }
6
- if (typeof fieldsData !== "object" || Array.isArray(fieldsData)) {
7
- return [
8
- {
9
- path: "",
10
- message: "Expected object for fields data",
11
- expected: "object",
12
- received: getType(fieldsData)
13
- }
14
- ];
15
- }
16
- const errors = [];
17
- for (const field of schema.fields) {
18
- if (!field.id) {
19
- continue;
20
- }
21
- if (!(field.id in fieldsData)) {
22
- continue;
23
- }
24
- const value = fieldsData[field.id];
25
- errors.push(...validateValue(value, field, field.id));
26
- }
27
- return errors;
28
- }
29
- function validateValue(value, field, path) {
30
- if (value === void 0) {
31
- return [];
32
- }
33
- switch (field.type) {
34
- case "string":
35
- case "select":
36
- if (typeof value !== "string") {
37
- return [createError(path, "string", value)];
38
- }
39
- return [];
40
- case "number":
41
- if (typeof value !== "number") {
42
- return [createError(path, "number", value)];
43
- }
44
- if (isNaN(value)) {
45
- return [createError(path, "number", value)];
46
- }
47
- return [];
48
- case "boolean":
49
- if (typeof value !== "boolean") {
50
- return [createError(path, "boolean", value)];
51
- }
52
- return [];
53
- case "date":
54
- case "datetime": {
55
- if (typeof value !== "object" || Array.isArray(value)) {
56
- return [createError(path, "object", value)];
57
- }
58
- const errors = [];
59
- const seconds = value.seconds;
60
- const nanoseconds = value.nanoseconds;
61
- if (seconds === void 0) {
62
- errors.push({
63
- path: `${path}.seconds`,
64
- message: "Required",
65
- expected: "number",
66
- received: "undefined"
67
- });
68
- } else if (typeof seconds !== "number") {
69
- errors.push(createError(`${path}.seconds`, "number", seconds));
70
- }
71
- if (nanoseconds === void 0) {
72
- errors.push({
73
- path: `${path}.nanoseconds`,
74
- message: "Required",
75
- expected: "number",
76
- received: "undefined"
77
- });
78
- } else if (typeof nanoseconds !== "number") {
79
- errors.push(createError(`${path}.nanoseconds`, "number", nanoseconds));
80
- }
81
- return errors;
82
- }
83
- case "multiselect":
84
- if (!Array.isArray(value)) {
85
- return [createError(path, "array", value)];
86
- }
87
- return value.flatMap((item, index) => {
88
- if (typeof item !== "string") {
89
- return [createError(`${path}.${index}`, "string", item)];
90
- }
91
- return [];
92
- });
93
- case "image":
94
- case "file": {
95
- if (typeof value !== "object" || Array.isArray(value)) {
96
- return [createError(path, "object", value)];
97
- }
98
- const errors = [];
99
- if (value.src === void 0) {
100
- errors.push({
101
- path: `${path}.src`,
102
- message: "Required",
103
- expected: "string",
104
- received: "undefined"
105
- });
106
- } else if (typeof value.src !== "string") {
107
- errors.push(createError(`${path}.src`, "string", value.src));
108
- }
109
- if (value.alt !== void 0 && typeof value.alt !== "string") {
110
- errors.push(createError(`${path}.alt`, "string", value.alt));
111
- }
112
- return errors;
113
- }
114
- case "object": {
115
- if (typeof value !== "object" || Array.isArray(value)) {
116
- return [createError(path, "object", value)];
117
- }
118
- const objectField = field;
119
- const errors = [];
120
- for (const nestedField of objectField.fields) {
121
- if (!nestedField.id || !(nestedField.id in value)) {
122
- continue;
123
- }
124
- errors.push(
125
- ...validateValue(
126
- value[nestedField.id],
127
- nestedField,
128
- `${path}.${nestedField.id}`
129
- )
130
- );
131
- }
132
- return errors;
133
- }
134
- case "array": {
135
- if (!Array.isArray(value)) {
136
- return [createError(path, "array", value)];
137
- }
138
- const arrayField = field;
139
- const itemField = arrayField.of;
140
- return value.flatMap((item, index) => {
141
- return validateValue(item, itemField, `${path}.${index}`);
142
- });
143
- }
144
- case "oneof": {
145
- if (typeof value !== "object" || Array.isArray(value)) {
146
- return [createError(path, "object", value)];
147
- }
148
- const oneOfField = field;
149
- const typeName = value._type;
150
- const typeMap = /* @__PURE__ */ new Map();
151
- const typeNames = [];
152
- for (const type of oneOfField.types) {
153
- if (typeof type === "string") {
154
- typeNames.push(type);
155
- continue;
156
- }
157
- typeMap.set(type.name, type);
158
- typeNames.push(type.name);
159
- }
160
- if (!typeNames.includes(typeName)) {
161
- const expectedStr = typeNames.map((t) => `'${t}'`).join(" | ");
162
- return [
163
- {
164
- path: `${path}._type`,
165
- message: `Invalid discriminator value. Expected ${expectedStr}`,
166
- expected: "valid discriminator value",
167
- received: typeName
168
- }
169
- ];
170
- }
171
- const matchedSchema = typeMap.get(typeName);
172
- if (!matchedSchema) {
173
- return [];
174
- }
175
- const errors = [];
176
- for (const nestedField of matchedSchema.fields) {
177
- if (!nestedField.id || !(nestedField.id in value)) {
178
- continue;
179
- }
180
- errors.push(
181
- ...validateValue(
182
- value[nestedField.id],
183
- nestedField,
184
- `${path}.${nestedField.id}`
185
- )
186
- );
187
- }
188
- return errors;
189
- }
190
- case "richtext": {
191
- if (typeof value !== "object" || Array.isArray(value)) {
192
- return [createError(path, "object", value)];
193
- }
194
- const errors = [];
195
- if (value.blocks === void 0) {
196
- errors.push({
197
- path: `${path}.blocks`,
198
- message: "Required",
199
- expected: "array",
200
- received: "undefined"
201
- });
202
- } else if (!Array.isArray(value.blocks)) {
203
- errors.push(createError(`${path}.blocks`, "array", value.blocks));
204
- } else {
205
- value.blocks.forEach((block, index) => {
206
- if (typeof block !== "object" || block === null) {
207
- errors.push(
208
- createError(`${path}.blocks.${index}`, "object", block)
209
- );
210
- return;
211
- }
212
- if (block.type === void 0) {
213
- errors.push({
214
- path: `${path}.blocks.${index}.type`,
215
- message: "Required",
216
- expected: "string",
217
- received: "undefined"
218
- });
219
- } else if (typeof block.type !== "string") {
220
- errors.push(
221
- createError(`${path}.blocks.${index}.type`, "string", block.type)
222
- );
223
- }
224
- });
225
- }
226
- return errors;
227
- }
228
- case "reference": {
229
- if (typeof value !== "object" || Array.isArray(value)) {
230
- return [createError(path, "object", value)];
231
- }
232
- const errors = [];
233
- const requiredFields = ["id", "collection", "slug"];
234
- for (const req of requiredFields) {
235
- if (value[req] === void 0) {
236
- errors.push({
237
- path: `${path}.${req}`,
238
- message: "Required",
239
- expected: "string",
240
- received: "undefined"
241
- });
242
- } else if (typeof value[req] !== "string") {
243
- errors.push(createError(`${path}.${req}`, "string", value[req]));
244
- }
245
- }
246
- return errors;
247
- }
248
- case "references": {
249
- if (!Array.isArray(value)) {
250
- return [createError(path, "array", value)];
251
- }
252
- return value.flatMap((item, index) => {
253
- if (typeof item !== "object" || item === null || Array.isArray(item)) {
254
- return [createError(`${path}.${index}`, "object", item)];
255
- }
256
- const errors = [];
257
- const requiredFields = ["id", "collection", "slug"];
258
- for (const req of requiredFields) {
259
- if (item[req] === void 0) {
260
- errors.push({
261
- path: `${path}.${index}.${req}`,
262
- message: "Required",
263
- expected: "string",
264
- received: "undefined"
265
- });
266
- } else if (typeof item[req] !== "string") {
267
- errors.push(
268
- createError(`${path}.${index}.${req}`, "string", item[req])
269
- );
270
- }
271
- }
272
- return errors;
273
- });
274
- }
275
- default:
276
- console.warn(`Unknown field type: ${field.type}`);
277
- return [];
278
- }
279
- }
280
- function getType(value) {
281
- if (value === null) return "null";
282
- if (Array.isArray(value)) return "array";
283
- if (typeof value === "number" && Number.isNaN(value)) return "nan";
284
- return typeof value;
285
- }
286
- function createError(path, expected, receivedValue) {
287
- const received = getType(receivedValue);
288
- return {
289
- path,
290
- message: `Expected ${expected}, received ${received}`,
291
- expected,
292
- received
293
- };
294
- }
295
-
296
- export {
297
- validateFields
298
- };