cms-renderer 0.2.9 → 0.3.1
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.
|
@@ -0,0 +1,1389 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// ../../node_modules/ret/dist/types/tokens.js
|
|
28
|
+
var require_tokens = __commonJS({
|
|
29
|
+
"../../node_modules/ret/dist/types/tokens.js"(exports) {
|
|
30
|
+
"use strict";
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// ../../node_modules/ret/dist/types/types.js
|
|
36
|
+
var require_types = __commonJS({
|
|
37
|
+
"../../node_modules/ret/dist/types/types.js"(exports) {
|
|
38
|
+
"use strict";
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.types = void 0;
|
|
41
|
+
var types;
|
|
42
|
+
(function(types2) {
|
|
43
|
+
types2[types2["ROOT"] = 0] = "ROOT";
|
|
44
|
+
types2[types2["GROUP"] = 1] = "GROUP";
|
|
45
|
+
types2[types2["POSITION"] = 2] = "POSITION";
|
|
46
|
+
types2[types2["SET"] = 3] = "SET";
|
|
47
|
+
types2[types2["RANGE"] = 4] = "RANGE";
|
|
48
|
+
types2[types2["REPETITION"] = 5] = "REPETITION";
|
|
49
|
+
types2[types2["REFERENCE"] = 6] = "REFERENCE";
|
|
50
|
+
types2[types2["CHAR"] = 7] = "CHAR";
|
|
51
|
+
})(types = exports.types || (exports.types = {}));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// ../../node_modules/ret/dist/types/set-lookup.js
|
|
56
|
+
var require_set_lookup = __commonJS({
|
|
57
|
+
"../../node_modules/ret/dist/types/set-lookup.js"(exports) {
|
|
58
|
+
"use strict";
|
|
59
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// ../../node_modules/ret/dist/types/index.js
|
|
64
|
+
var require_types2 = __commonJS({
|
|
65
|
+
"../../node_modules/ret/dist/types/index.js"(exports) {
|
|
66
|
+
"use strict";
|
|
67
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
68
|
+
if (k2 === void 0) k2 = k;
|
|
69
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
70
|
+
return m[k];
|
|
71
|
+
} });
|
|
72
|
+
}) : (function(o, m, k, k2) {
|
|
73
|
+
if (k2 === void 0) k2 = k;
|
|
74
|
+
o[k2] = m[k];
|
|
75
|
+
}));
|
|
76
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
77
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
|
|
78
|
+
};
|
|
79
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
80
|
+
__exportStar(require_tokens(), exports);
|
|
81
|
+
__exportStar(require_types(), exports);
|
|
82
|
+
__exportStar(require_set_lookup(), exports);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// ../../node_modules/ret/dist/sets.js
|
|
87
|
+
var require_sets = __commonJS({
|
|
88
|
+
"../../node_modules/ret/dist/sets.js"(exports) {
|
|
89
|
+
"use strict";
|
|
90
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
91
|
+
exports.anyChar = exports.notWhitespace = exports.whitespace = exports.notInts = exports.ints = exports.notWords = exports.words = void 0;
|
|
92
|
+
var types_1 = require_types2();
|
|
93
|
+
var INTS = () => [{ type: types_1.types.RANGE, from: 48, to: 57 }];
|
|
94
|
+
var WORDS = () => [
|
|
95
|
+
{ type: types_1.types.CHAR, value: 95 },
|
|
96
|
+
{ type: types_1.types.RANGE, from: 97, to: 122 },
|
|
97
|
+
{ type: types_1.types.RANGE, from: 65, to: 90 },
|
|
98
|
+
{ type: types_1.types.RANGE, from: 48, to: 57 }
|
|
99
|
+
];
|
|
100
|
+
var WHITESPACE = () => [
|
|
101
|
+
{ type: types_1.types.CHAR, value: 9 },
|
|
102
|
+
{ type: types_1.types.CHAR, value: 10 },
|
|
103
|
+
{ type: types_1.types.CHAR, value: 11 },
|
|
104
|
+
{ type: types_1.types.CHAR, value: 12 },
|
|
105
|
+
{ type: types_1.types.CHAR, value: 13 },
|
|
106
|
+
{ type: types_1.types.CHAR, value: 32 },
|
|
107
|
+
{ type: types_1.types.CHAR, value: 160 },
|
|
108
|
+
{ type: types_1.types.CHAR, value: 5760 },
|
|
109
|
+
{ type: types_1.types.RANGE, from: 8192, to: 8202 },
|
|
110
|
+
{ type: types_1.types.CHAR, value: 8232 },
|
|
111
|
+
{ type: types_1.types.CHAR, value: 8233 },
|
|
112
|
+
{ type: types_1.types.CHAR, value: 8239 },
|
|
113
|
+
{ type: types_1.types.CHAR, value: 8287 },
|
|
114
|
+
{ type: types_1.types.CHAR, value: 12288 },
|
|
115
|
+
{ type: types_1.types.CHAR, value: 65279 }
|
|
116
|
+
];
|
|
117
|
+
var NOTANYCHAR = () => [
|
|
118
|
+
{ type: types_1.types.CHAR, value: 10 },
|
|
119
|
+
{ type: types_1.types.CHAR, value: 13 },
|
|
120
|
+
{ type: types_1.types.CHAR, value: 8232 },
|
|
121
|
+
{ type: types_1.types.CHAR, value: 8233 }
|
|
122
|
+
];
|
|
123
|
+
exports.words = () => ({ type: types_1.types.SET, set: WORDS(), not: false });
|
|
124
|
+
exports.notWords = () => ({ type: types_1.types.SET, set: WORDS(), not: true });
|
|
125
|
+
exports.ints = () => ({ type: types_1.types.SET, set: INTS(), not: false });
|
|
126
|
+
exports.notInts = () => ({ type: types_1.types.SET, set: INTS(), not: true });
|
|
127
|
+
exports.whitespace = () => ({ type: types_1.types.SET, set: WHITESPACE(), not: false });
|
|
128
|
+
exports.notWhitespace = () => ({ type: types_1.types.SET, set: WHITESPACE(), not: true });
|
|
129
|
+
exports.anyChar = () => ({ type: types_1.types.SET, set: NOTANYCHAR(), not: true });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// ../../node_modules/ret/dist/util.js
|
|
134
|
+
var require_util = __commonJS({
|
|
135
|
+
"../../node_modules/ret/dist/util.js"(exports) {
|
|
136
|
+
"use strict";
|
|
137
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
138
|
+
if (k2 === void 0) k2 = k;
|
|
139
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
140
|
+
return m[k];
|
|
141
|
+
} });
|
|
142
|
+
}) : (function(o, m, k, k2) {
|
|
143
|
+
if (k2 === void 0) k2 = k;
|
|
144
|
+
o[k2] = m[k];
|
|
145
|
+
}));
|
|
146
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
147
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
148
|
+
}) : function(o, v) {
|
|
149
|
+
o["default"] = v;
|
|
150
|
+
});
|
|
151
|
+
var __importStar = exports && exports.__importStar || function(mod) {
|
|
152
|
+
if (mod && mod.__esModule) return mod;
|
|
153
|
+
var result = {};
|
|
154
|
+
if (mod != null) {
|
|
155
|
+
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
156
|
+
}
|
|
157
|
+
__setModuleDefault(result, mod);
|
|
158
|
+
return result;
|
|
159
|
+
};
|
|
160
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
161
|
+
exports.tokenizeClass = exports.strToChars = void 0;
|
|
162
|
+
var types_1 = require_types2();
|
|
163
|
+
var sets = __importStar(require_sets());
|
|
164
|
+
var CTRL = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?";
|
|
165
|
+
exports.strToChars = (str) => {
|
|
166
|
+
const charsRegex = /(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g;
|
|
167
|
+
return str.replace(charsRegex, (s, b, lbs, a16, b16, dctrl, eslsh) => {
|
|
168
|
+
if (lbs) {
|
|
169
|
+
return s;
|
|
170
|
+
}
|
|
171
|
+
let code = b ? 8 : a16 ? parseInt(a16, 16) : b16 ? parseInt(b16, 16) : dctrl ? CTRL.indexOf(dctrl) : {
|
|
172
|
+
0: 0,
|
|
173
|
+
t: 9,
|
|
174
|
+
n: 10,
|
|
175
|
+
v: 11,
|
|
176
|
+
f: 12,
|
|
177
|
+
r: 13
|
|
178
|
+
}[eslsh];
|
|
179
|
+
let c = String.fromCharCode(code);
|
|
180
|
+
return /[[\]{}^$.|?*+()]/.test(c) ? `\\${c}` : c;
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
exports.tokenizeClass = (str, regexpStr) => {
|
|
184
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
185
|
+
let tokens = [], rs, c;
|
|
186
|
+
const regexp = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(((?:\\)])|(((?:\\)?([^\]])))))|(\])|(?:\\)?([^])/g;
|
|
187
|
+
while ((rs = regexp.exec(str)) !== null) {
|
|
188
|
+
const p = (_g = (_f = (_e = (_d = (_c = (_b = (_a = rs[1] && sets.words()) !== null && _a !== void 0 ? _a : rs[2] && sets.ints()) !== null && _b !== void 0 ? _b : rs[3] && sets.whitespace()) !== null && _c !== void 0 ? _c : rs[4] && sets.notWords()) !== null && _d !== void 0 ? _d : rs[5] && sets.notInts()) !== null && _e !== void 0 ? _e : rs[6] && sets.notWhitespace()) !== null && _f !== void 0 ? _f : rs[7] && {
|
|
189
|
+
type: types_1.types.RANGE,
|
|
190
|
+
from: (rs[8] || rs[9]).charCodeAt(0),
|
|
191
|
+
to: (c = rs[10]).charCodeAt(c.length - 1)
|
|
192
|
+
}) !== null && _g !== void 0 ? _g : (c = rs[16]) && { type: types_1.types.CHAR, value: c.charCodeAt(0) };
|
|
193
|
+
if (p) {
|
|
194
|
+
tokens.push(p);
|
|
195
|
+
} else {
|
|
196
|
+
return [tokens, regexp.lastIndex];
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Unterminated character class`);
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// ../../node_modules/ret/dist/tokenizer.js
|
|
205
|
+
var require_tokenizer = __commonJS({
|
|
206
|
+
"../../node_modules/ret/dist/tokenizer.js"(exports) {
|
|
207
|
+
"use strict";
|
|
208
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
209
|
+
if (k2 === void 0) k2 = k;
|
|
210
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
211
|
+
return m[k];
|
|
212
|
+
} });
|
|
213
|
+
}) : (function(o, m, k, k2) {
|
|
214
|
+
if (k2 === void 0) k2 = k;
|
|
215
|
+
o[k2] = m[k];
|
|
216
|
+
}));
|
|
217
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
218
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
219
|
+
}) : function(o, v) {
|
|
220
|
+
o["default"] = v;
|
|
221
|
+
});
|
|
222
|
+
var __importStar = exports && exports.__importStar || function(mod) {
|
|
223
|
+
if (mod && mod.__esModule) return mod;
|
|
224
|
+
var result = {};
|
|
225
|
+
if (mod != null) {
|
|
226
|
+
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
227
|
+
}
|
|
228
|
+
__setModuleDefault(result, mod);
|
|
229
|
+
return result;
|
|
230
|
+
};
|
|
231
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
232
|
+
exports.tokenizer = void 0;
|
|
233
|
+
var util = __importStar(require_util());
|
|
234
|
+
var types_1 = require_types2();
|
|
235
|
+
var sets = __importStar(require_sets());
|
|
236
|
+
var captureGroupFirstChar = /^[a-zA-Z_$]$/i;
|
|
237
|
+
var captureGroupChars = /^[a-zA-Z0-9_$]$/i;
|
|
238
|
+
var digit = /\d/;
|
|
239
|
+
exports.tokenizer = (regexpStr) => {
|
|
240
|
+
let i = 0, c;
|
|
241
|
+
let start = { type: types_1.types.ROOT, stack: [] };
|
|
242
|
+
let lastGroup = start;
|
|
243
|
+
let last = start.stack;
|
|
244
|
+
let groupStack = [];
|
|
245
|
+
let referenceQueue = [];
|
|
246
|
+
let groupCount = 0;
|
|
247
|
+
const repeatErr = (col) => {
|
|
248
|
+
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Nothing to repeat at column ${col - 1}`);
|
|
249
|
+
};
|
|
250
|
+
let str = util.strToChars(regexpStr);
|
|
251
|
+
while (i < str.length) {
|
|
252
|
+
switch (c = str[i++]) {
|
|
253
|
+
// Handle escaped characters, inclues a few sets.
|
|
254
|
+
case "\\":
|
|
255
|
+
if (i === str.length) {
|
|
256
|
+
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: \\ at end of pattern`);
|
|
257
|
+
}
|
|
258
|
+
switch (c = str[i++]) {
|
|
259
|
+
case "b":
|
|
260
|
+
last.push({ type: types_1.types.POSITION, value: "b" });
|
|
261
|
+
break;
|
|
262
|
+
case "B":
|
|
263
|
+
last.push({ type: types_1.types.POSITION, value: "B" });
|
|
264
|
+
break;
|
|
265
|
+
case "w":
|
|
266
|
+
last.push(sets.words());
|
|
267
|
+
break;
|
|
268
|
+
case "W":
|
|
269
|
+
last.push(sets.notWords());
|
|
270
|
+
break;
|
|
271
|
+
case "d":
|
|
272
|
+
last.push(sets.ints());
|
|
273
|
+
break;
|
|
274
|
+
case "D":
|
|
275
|
+
last.push(sets.notInts());
|
|
276
|
+
break;
|
|
277
|
+
case "s":
|
|
278
|
+
last.push(sets.whitespace());
|
|
279
|
+
break;
|
|
280
|
+
case "S":
|
|
281
|
+
last.push(sets.notWhitespace());
|
|
282
|
+
break;
|
|
283
|
+
default:
|
|
284
|
+
if (digit.test(c)) {
|
|
285
|
+
let digits = c;
|
|
286
|
+
while (i < str.length && digit.test(str[i])) {
|
|
287
|
+
digits += str[i++];
|
|
288
|
+
}
|
|
289
|
+
let value = parseInt(digits, 10);
|
|
290
|
+
const reference = { type: types_1.types.REFERENCE, value };
|
|
291
|
+
last.push(reference);
|
|
292
|
+
referenceQueue.push({ reference, stack: last, index: last.length - 1 });
|
|
293
|
+
} else {
|
|
294
|
+
last.push({ type: types_1.types.CHAR, value: c.charCodeAt(0) });
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
break;
|
|
298
|
+
// Positionals.
|
|
299
|
+
case "^":
|
|
300
|
+
last.push({ type: types_1.types.POSITION, value: "^" });
|
|
301
|
+
break;
|
|
302
|
+
case "$":
|
|
303
|
+
last.push({ type: types_1.types.POSITION, value: "$" });
|
|
304
|
+
break;
|
|
305
|
+
// Handle custom sets.
|
|
306
|
+
case "[": {
|
|
307
|
+
let not;
|
|
308
|
+
if (str[i] === "^") {
|
|
309
|
+
not = true;
|
|
310
|
+
i++;
|
|
311
|
+
} else {
|
|
312
|
+
not = false;
|
|
313
|
+
}
|
|
314
|
+
let classTokens = util.tokenizeClass(str.slice(i), regexpStr);
|
|
315
|
+
i += classTokens[1];
|
|
316
|
+
last.push({
|
|
317
|
+
type: types_1.types.SET,
|
|
318
|
+
set: classTokens[0],
|
|
319
|
+
not
|
|
320
|
+
});
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
// Class of any character except \n.
|
|
324
|
+
case ".":
|
|
325
|
+
last.push(sets.anyChar());
|
|
326
|
+
break;
|
|
327
|
+
// Push group onto stack.
|
|
328
|
+
case "(": {
|
|
329
|
+
let group = {
|
|
330
|
+
type: types_1.types.GROUP,
|
|
331
|
+
stack: [],
|
|
332
|
+
remember: true
|
|
333
|
+
};
|
|
334
|
+
if (str[i] === "?") {
|
|
335
|
+
c = str[i + 1];
|
|
336
|
+
i += 2;
|
|
337
|
+
if (c === "=") {
|
|
338
|
+
group.followedBy = true;
|
|
339
|
+
group.remember = false;
|
|
340
|
+
} else if (c === "!") {
|
|
341
|
+
group.notFollowedBy = true;
|
|
342
|
+
group.remember = false;
|
|
343
|
+
} else if (c === "<") {
|
|
344
|
+
let name = "";
|
|
345
|
+
if (captureGroupFirstChar.test(str[i])) {
|
|
346
|
+
name += str[i];
|
|
347
|
+
i++;
|
|
348
|
+
} else {
|
|
349
|
+
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Invalid capture group name, character '${str[i]}' after '<' at column ${i + 1}`);
|
|
350
|
+
}
|
|
351
|
+
while (i < str.length && captureGroupChars.test(str[i])) {
|
|
352
|
+
name += str[i];
|
|
353
|
+
i++;
|
|
354
|
+
}
|
|
355
|
+
if (!name) {
|
|
356
|
+
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Invalid capture group name, character '${str[i]}' after '<' at column ${i + 1}`);
|
|
357
|
+
}
|
|
358
|
+
if (str[i] !== ">") {
|
|
359
|
+
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Unclosed capture group name, expected '>', found '${str[i]}' at column ${i + 1}`);
|
|
360
|
+
}
|
|
361
|
+
group.name = name;
|
|
362
|
+
i++;
|
|
363
|
+
} else if (c === ":") {
|
|
364
|
+
group.remember = false;
|
|
365
|
+
} else {
|
|
366
|
+
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Invalid group, character '${c}' after '?' at column ${i - 1}`);
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
groupCount += 1;
|
|
370
|
+
}
|
|
371
|
+
last.push(group);
|
|
372
|
+
groupStack.push(lastGroup);
|
|
373
|
+
lastGroup = group;
|
|
374
|
+
last = group.stack;
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
// Pop group out of stack.
|
|
378
|
+
case ")":
|
|
379
|
+
if (groupStack.length === 0) {
|
|
380
|
+
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Unmatched ) at column ${i - 1}`);
|
|
381
|
+
}
|
|
382
|
+
lastGroup = groupStack.pop();
|
|
383
|
+
last = lastGroup.options ? lastGroup.options[lastGroup.options.length - 1] : lastGroup.stack;
|
|
384
|
+
break;
|
|
385
|
+
// Use pipe character to give more choices.
|
|
386
|
+
case "|": {
|
|
387
|
+
if (!lastGroup.options) {
|
|
388
|
+
lastGroup.options = [lastGroup.stack];
|
|
389
|
+
delete lastGroup.stack;
|
|
390
|
+
}
|
|
391
|
+
let stack = [];
|
|
392
|
+
lastGroup.options.push(stack);
|
|
393
|
+
last = stack;
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
// Repetition.
|
|
397
|
+
// For every repetition, remove last element from last stack
|
|
398
|
+
// then insert back a RANGE object.
|
|
399
|
+
// This design is chosen because there could be more than
|
|
400
|
+
// one repetition symbols in a regex i.e. `a?+{2,3}`.
|
|
401
|
+
case "{": {
|
|
402
|
+
let rs = /^(\d+)(,(\d+)?)?\}/.exec(str.slice(i)), min, max;
|
|
403
|
+
if (rs !== null) {
|
|
404
|
+
if (last.length === 0) {
|
|
405
|
+
repeatErr(i);
|
|
406
|
+
}
|
|
407
|
+
min = parseInt(rs[1], 10);
|
|
408
|
+
max = rs[2] ? rs[3] ? parseInt(rs[3], 10) : Infinity : min;
|
|
409
|
+
i += rs[0].length;
|
|
410
|
+
last.push({
|
|
411
|
+
type: types_1.types.REPETITION,
|
|
412
|
+
min,
|
|
413
|
+
max,
|
|
414
|
+
value: last.pop()
|
|
415
|
+
});
|
|
416
|
+
} else {
|
|
417
|
+
last.push({
|
|
418
|
+
type: types_1.types.CHAR,
|
|
419
|
+
value: 123
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
case "?":
|
|
425
|
+
if (last.length === 0) {
|
|
426
|
+
repeatErr(i);
|
|
427
|
+
}
|
|
428
|
+
last.push({
|
|
429
|
+
type: types_1.types.REPETITION,
|
|
430
|
+
min: 0,
|
|
431
|
+
max: 1,
|
|
432
|
+
value: last.pop()
|
|
433
|
+
});
|
|
434
|
+
break;
|
|
435
|
+
case "+":
|
|
436
|
+
if (last.length === 0) {
|
|
437
|
+
repeatErr(i);
|
|
438
|
+
}
|
|
439
|
+
last.push({
|
|
440
|
+
type: types_1.types.REPETITION,
|
|
441
|
+
min: 1,
|
|
442
|
+
max: Infinity,
|
|
443
|
+
value: last.pop()
|
|
444
|
+
});
|
|
445
|
+
break;
|
|
446
|
+
case "*":
|
|
447
|
+
if (last.length === 0) {
|
|
448
|
+
repeatErr(i);
|
|
449
|
+
}
|
|
450
|
+
last.push({
|
|
451
|
+
type: types_1.types.REPETITION,
|
|
452
|
+
min: 0,
|
|
453
|
+
max: Infinity,
|
|
454
|
+
value: last.pop()
|
|
455
|
+
});
|
|
456
|
+
break;
|
|
457
|
+
// Default is a character that is not `\[](){}?+*^$`.
|
|
458
|
+
default:
|
|
459
|
+
last.push({
|
|
460
|
+
type: types_1.types.CHAR,
|
|
461
|
+
value: c.charCodeAt(0)
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if (groupStack.length !== 0) {
|
|
466
|
+
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Unterminated group`);
|
|
467
|
+
}
|
|
468
|
+
updateReferences(referenceQueue, groupCount);
|
|
469
|
+
return start;
|
|
470
|
+
};
|
|
471
|
+
function updateReferences(referenceQueue, groupCount) {
|
|
472
|
+
for (const elem of referenceQueue.reverse()) {
|
|
473
|
+
if (groupCount < elem.reference.value) {
|
|
474
|
+
elem.reference.type = types_1.types.CHAR;
|
|
475
|
+
const valueString = elem.reference.value.toString();
|
|
476
|
+
elem.reference.value = parseInt(valueString, 8);
|
|
477
|
+
if (!/^[0-7]+$/.test(valueString)) {
|
|
478
|
+
let i = 0;
|
|
479
|
+
while (valueString[i] !== "8" && valueString[i] !== "9") {
|
|
480
|
+
i += 1;
|
|
481
|
+
}
|
|
482
|
+
if (i === 0) {
|
|
483
|
+
elem.reference.value = valueString.charCodeAt(0);
|
|
484
|
+
i += 1;
|
|
485
|
+
} else {
|
|
486
|
+
elem.reference.value = parseInt(valueString.slice(0, i), 8);
|
|
487
|
+
}
|
|
488
|
+
if (valueString.length > i) {
|
|
489
|
+
const tail = elem.stack.splice(elem.index + 1);
|
|
490
|
+
for (const char of valueString.slice(i)) {
|
|
491
|
+
elem.stack.push({
|
|
492
|
+
type: types_1.types.CHAR,
|
|
493
|
+
value: char.charCodeAt(0)
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
elem.stack.push(...tail);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
// ../../node_modules/ret/dist/sets-lookup.js
|
|
506
|
+
var require_sets_lookup = __commonJS({
|
|
507
|
+
"../../node_modules/ret/dist/sets-lookup.js"(exports) {
|
|
508
|
+
"use strict";
|
|
509
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
510
|
+
if (k2 === void 0) k2 = k;
|
|
511
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
512
|
+
return m[k];
|
|
513
|
+
} });
|
|
514
|
+
}) : (function(o, m, k, k2) {
|
|
515
|
+
if (k2 === void 0) k2 = k;
|
|
516
|
+
o[k2] = m[k];
|
|
517
|
+
}));
|
|
518
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
519
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
520
|
+
}) : function(o, v) {
|
|
521
|
+
o["default"] = v;
|
|
522
|
+
});
|
|
523
|
+
var __importStar = exports && exports.__importStar || function(mod) {
|
|
524
|
+
if (mod && mod.__esModule) return mod;
|
|
525
|
+
var result = {};
|
|
526
|
+
if (mod != null) {
|
|
527
|
+
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
528
|
+
}
|
|
529
|
+
__setModuleDefault(result, mod);
|
|
530
|
+
return result;
|
|
531
|
+
};
|
|
532
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
533
|
+
exports.NOTANYCHAR = exports.WHITESPACE = exports.WORDS = exports.INTS = void 0;
|
|
534
|
+
var Sets = __importStar(require_sets());
|
|
535
|
+
var types_1 = require_types2();
|
|
536
|
+
function setToLookup(tokens) {
|
|
537
|
+
let lookup = {};
|
|
538
|
+
let len = 0;
|
|
539
|
+
for (const token of tokens) {
|
|
540
|
+
if (token.type === types_1.types.CHAR) {
|
|
541
|
+
lookup[token.value] = true;
|
|
542
|
+
}
|
|
543
|
+
if (token.type === types_1.types.RANGE) {
|
|
544
|
+
lookup[`${token.from}-${token.to}`] = true;
|
|
545
|
+
}
|
|
546
|
+
len += 1;
|
|
547
|
+
}
|
|
548
|
+
return {
|
|
549
|
+
lookup: () => Object.assign({}, lookup),
|
|
550
|
+
len
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
exports.INTS = setToLookup(Sets.ints().set);
|
|
554
|
+
exports.WORDS = setToLookup(Sets.words().set);
|
|
555
|
+
exports.WHITESPACE = setToLookup(Sets.whitespace().set);
|
|
556
|
+
exports.NOTANYCHAR = setToLookup(Sets.anyChar().set);
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
// ../../node_modules/ret/dist/write-set-tokens.js
|
|
561
|
+
var require_write_set_tokens = __commonJS({
|
|
562
|
+
"../../node_modules/ret/dist/write-set-tokens.js"(exports) {
|
|
563
|
+
"use strict";
|
|
564
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
565
|
+
if (k2 === void 0) k2 = k;
|
|
566
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
567
|
+
return m[k];
|
|
568
|
+
} });
|
|
569
|
+
}) : (function(o, m, k, k2) {
|
|
570
|
+
if (k2 === void 0) k2 = k;
|
|
571
|
+
o[k2] = m[k];
|
|
572
|
+
}));
|
|
573
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
574
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
575
|
+
}) : function(o, v) {
|
|
576
|
+
o["default"] = v;
|
|
577
|
+
});
|
|
578
|
+
var __importStar = exports && exports.__importStar || function(mod) {
|
|
579
|
+
if (mod && mod.__esModule) return mod;
|
|
580
|
+
var result = {};
|
|
581
|
+
if (mod != null) {
|
|
582
|
+
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
583
|
+
}
|
|
584
|
+
__setModuleDefault(result, mod);
|
|
585
|
+
return result;
|
|
586
|
+
};
|
|
587
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
588
|
+
exports.writeSetTokens = exports.setChar = void 0;
|
|
589
|
+
var types_1 = require_types2();
|
|
590
|
+
var sets = __importStar(require_sets_lookup());
|
|
591
|
+
function setChar(charCode) {
|
|
592
|
+
return charCode === 94 ? "\\^" : charCode === 92 ? "\\\\" : charCode === 93 ? "\\]" : charCode === 45 ? "\\-" : String.fromCharCode(charCode);
|
|
593
|
+
}
|
|
594
|
+
exports.setChar = setChar;
|
|
595
|
+
function isSameSet(set, { lookup, len }) {
|
|
596
|
+
if (len !== set.length) {
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
const map = lookup();
|
|
600
|
+
for (const elem of set) {
|
|
601
|
+
if (elem.type === types_1.types.SET) {
|
|
602
|
+
return false;
|
|
603
|
+
}
|
|
604
|
+
const key = elem.type === types_1.types.CHAR ? elem.value : `${elem.from}-${elem.to}`;
|
|
605
|
+
if (map[key]) {
|
|
606
|
+
map[key] = false;
|
|
607
|
+
} else {
|
|
608
|
+
return false;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return true;
|
|
612
|
+
}
|
|
613
|
+
function writeSetTokens(set, isNested = false) {
|
|
614
|
+
if (isSameSet(set.set, sets.INTS)) {
|
|
615
|
+
return set.not ? "\\D" : "\\d";
|
|
616
|
+
}
|
|
617
|
+
if (isSameSet(set.set, sets.WORDS)) {
|
|
618
|
+
return set.not ? "\\W" : "\\w";
|
|
619
|
+
}
|
|
620
|
+
if (set.not && isSameSet(set.set, sets.NOTANYCHAR)) {
|
|
621
|
+
return ".";
|
|
622
|
+
}
|
|
623
|
+
if (isSameSet(set.set, sets.WHITESPACE)) {
|
|
624
|
+
return set.not ? "\\S" : "\\s";
|
|
625
|
+
}
|
|
626
|
+
let tokenString = "";
|
|
627
|
+
for (let i = 0; i < set.set.length; i++) {
|
|
628
|
+
const subset = set.set[i];
|
|
629
|
+
tokenString += writeSetToken(subset);
|
|
630
|
+
}
|
|
631
|
+
const contents = `${set.not ? "^" : ""}${tokenString}`;
|
|
632
|
+
return isNested ? contents : `[${contents}]`;
|
|
633
|
+
}
|
|
634
|
+
exports.writeSetTokens = writeSetTokens;
|
|
635
|
+
function writeSetToken(set) {
|
|
636
|
+
if (set.type === types_1.types.CHAR) {
|
|
637
|
+
return setChar(set.value);
|
|
638
|
+
} else if (set.type === types_1.types.RANGE) {
|
|
639
|
+
return `${setChar(set.from)}-${setChar(set.to)}`;
|
|
640
|
+
}
|
|
641
|
+
return writeSetTokens(set, true);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
// ../../node_modules/ret/dist/reconstruct.js
|
|
647
|
+
var require_reconstruct = __commonJS({
|
|
648
|
+
"../../node_modules/ret/dist/reconstruct.js"(exports) {
|
|
649
|
+
"use strict";
|
|
650
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
651
|
+
exports.reconstruct = void 0;
|
|
652
|
+
var types_1 = require_types2();
|
|
653
|
+
var write_set_tokens_1 = require_write_set_tokens();
|
|
654
|
+
var reduceStack = (stack) => stack.map(exports.reconstruct).join("");
|
|
655
|
+
var createAlternate = (token) => {
|
|
656
|
+
if ("options" in token) {
|
|
657
|
+
return token.options.map(reduceStack).join("|");
|
|
658
|
+
} else if ("stack" in token) {
|
|
659
|
+
return reduceStack(token.stack);
|
|
660
|
+
} else {
|
|
661
|
+
throw new Error(`options or stack must be Root or Group token`);
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
exports.reconstruct = (token) => {
|
|
665
|
+
switch (token.type) {
|
|
666
|
+
case types_1.types.ROOT:
|
|
667
|
+
return createAlternate(token);
|
|
668
|
+
case types_1.types.CHAR: {
|
|
669
|
+
const c = String.fromCharCode(token.value);
|
|
670
|
+
return (/[[\\{}$^.|?*+()]/.test(c) ? "\\" : "") + c;
|
|
671
|
+
}
|
|
672
|
+
case types_1.types.POSITION:
|
|
673
|
+
if (token.value === "^" || token.value === "$") {
|
|
674
|
+
return token.value;
|
|
675
|
+
} else {
|
|
676
|
+
return `\\${token.value}`;
|
|
677
|
+
}
|
|
678
|
+
case types_1.types.REFERENCE:
|
|
679
|
+
return `\\${token.value}`;
|
|
680
|
+
case types_1.types.SET:
|
|
681
|
+
return write_set_tokens_1.writeSetTokens(token);
|
|
682
|
+
case types_1.types.GROUP: {
|
|
683
|
+
const prefix = token.name ? `?<${token.name}>` : token.remember ? "" : token.followedBy ? "?=" : token.notFollowedBy ? "?!" : "?:";
|
|
684
|
+
return `(${prefix}${createAlternate(token)})`;
|
|
685
|
+
}
|
|
686
|
+
case types_1.types.REPETITION: {
|
|
687
|
+
const { min, max } = token;
|
|
688
|
+
let endWith;
|
|
689
|
+
if (min === 0 && max === 1) {
|
|
690
|
+
endWith = "?";
|
|
691
|
+
} else if (min === 1 && max === Infinity) {
|
|
692
|
+
endWith = "+";
|
|
693
|
+
} else if (min === 0 && max === Infinity) {
|
|
694
|
+
endWith = "*";
|
|
695
|
+
} else if (max === Infinity) {
|
|
696
|
+
endWith = `{${min},}`;
|
|
697
|
+
} else if (min === max) {
|
|
698
|
+
endWith = `{${min}}`;
|
|
699
|
+
} else {
|
|
700
|
+
endWith = `{${min},${max}}`;
|
|
701
|
+
}
|
|
702
|
+
return `${exports.reconstruct(token.value)}${endWith}`;
|
|
703
|
+
}
|
|
704
|
+
case types_1.types.RANGE:
|
|
705
|
+
return `${write_set_tokens_1.setChar(token.from)}-${write_set_tokens_1.setChar(token.to)}`;
|
|
706
|
+
default:
|
|
707
|
+
throw new Error(`Invalid token type ${token}`);
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
// ../../node_modules/ret/dist/index.js
|
|
714
|
+
var require_dist = __commonJS({
|
|
715
|
+
"../../node_modules/ret/dist/index.js"(exports, module) {
|
|
716
|
+
"use strict";
|
|
717
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
718
|
+
if (k2 === void 0) k2 = k;
|
|
719
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
720
|
+
return m[k];
|
|
721
|
+
} });
|
|
722
|
+
}) : (function(o, m, k, k2) {
|
|
723
|
+
if (k2 === void 0) k2 = k;
|
|
724
|
+
o[k2] = m[k];
|
|
725
|
+
}));
|
|
726
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
727
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
|
|
728
|
+
};
|
|
729
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
730
|
+
exports.types = void 0;
|
|
731
|
+
var types_1 = require_types2();
|
|
732
|
+
Object.defineProperty(exports, "types", { enumerable: true, get: function() {
|
|
733
|
+
return types_1.types;
|
|
734
|
+
} });
|
|
735
|
+
__exportStar(require_tokenizer(), exports);
|
|
736
|
+
__exportStar(require_reconstruct(), exports);
|
|
737
|
+
var tokenizer_1 = require_tokenizer();
|
|
738
|
+
var reconstruct_1 = require_reconstruct();
|
|
739
|
+
__exportStar(require_types2(), exports);
|
|
740
|
+
exports.default = tokenizer_1.tokenizer;
|
|
741
|
+
module.exports = tokenizer_1.tokenizer;
|
|
742
|
+
module.exports.types = types_1.types;
|
|
743
|
+
module.exports.reconstruct = reconstruct_1.reconstruct;
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
// ../../node_modules/safe-regex2/index.js
|
|
748
|
+
var require_safe_regex2 = __commonJS({
|
|
749
|
+
"../../node_modules/safe-regex2/index.js"(exports, module) {
|
|
750
|
+
"use strict";
|
|
751
|
+
var parse = require_dist();
|
|
752
|
+
var types = parse.types;
|
|
753
|
+
function safeRegex2(re, opts) {
|
|
754
|
+
if (!opts) opts = {};
|
|
755
|
+
const replimit = opts.limit === void 0 ? 25 : opts.limit;
|
|
756
|
+
if (isRegExp(re)) re = re.source;
|
|
757
|
+
else if (typeof re !== "string") re = String(re);
|
|
758
|
+
try {
|
|
759
|
+
re = parse(re);
|
|
760
|
+
} catch {
|
|
761
|
+
return false;
|
|
762
|
+
}
|
|
763
|
+
let reps = 0;
|
|
764
|
+
return (function walk(node, starHeight) {
|
|
765
|
+
let i;
|
|
766
|
+
let ok2;
|
|
767
|
+
let len;
|
|
768
|
+
if (node.type === types.REPETITION) {
|
|
769
|
+
starHeight++;
|
|
770
|
+
reps++;
|
|
771
|
+
if (starHeight > 1) return false;
|
|
772
|
+
if (reps > replimit) return false;
|
|
773
|
+
}
|
|
774
|
+
if (node.options) {
|
|
775
|
+
for (i = 0, len = node.options.length; i < len; i++) {
|
|
776
|
+
ok2 = walk({ stack: node.options[i] }, starHeight);
|
|
777
|
+
if (!ok2) return false;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
const stack = node.stack || node.value?.stack;
|
|
781
|
+
if (!stack) return true;
|
|
782
|
+
for (i = 0; i < stack.length; i++) {
|
|
783
|
+
ok2 = walk(stack[i], starHeight);
|
|
784
|
+
if (!ok2) return false;
|
|
785
|
+
}
|
|
786
|
+
return true;
|
|
787
|
+
})(re, 0);
|
|
788
|
+
}
|
|
789
|
+
function isRegExp(x) {
|
|
790
|
+
return {}.toString.call(x) === "[object RegExp]";
|
|
791
|
+
}
|
|
792
|
+
module.exports = safeRegex2;
|
|
793
|
+
module.exports.default = safeRegex2;
|
|
794
|
+
module.exports.safeRegex = safeRegex2;
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
// lib/custom-schemas.ts
|
|
799
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
800
|
+
import { dirname } from "path";
|
|
801
|
+
|
|
802
|
+
// ../../packages/cms-schema/src/documents/registry.ts
|
|
803
|
+
import { z } from "zod";
|
|
804
|
+
var schemaNameValidator = z.string().min(1, "Schema name must be a non-empty string").refine((name) => name.trim().length > 0, "Schema name must not be only whitespace");
|
|
805
|
+
var documentSchemaConfigValidator = z.object({
|
|
806
|
+
schema: z.custom(
|
|
807
|
+
(val) => val !== null && typeof val === "object" && "_def" in val,
|
|
808
|
+
{ message: "schema must be a valid Zod schema" }
|
|
809
|
+
),
|
|
810
|
+
titleField: z.string().optional(),
|
|
811
|
+
displayName: z.string().optional(),
|
|
812
|
+
description: z.string().optional(),
|
|
813
|
+
validateContent: z.function().optional()
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
// ../../packages/cms-schema/src/documents/schemas/country.ts
|
|
817
|
+
import { z as z2 } from "zod";
|
|
818
|
+
var LanguageReferenceSchema = z2.object({
|
|
819
|
+
_type: z2.literal("reference"),
|
|
820
|
+
_ref: z2.string().uuid("Language reference must be a valid UUID"),
|
|
821
|
+
_schema: z2.literal("language")
|
|
822
|
+
});
|
|
823
|
+
var CountrySchema = z2.object({
|
|
824
|
+
/** 2-letter ISO 3166-1 alpha-2 country code */
|
|
825
|
+
code: z2.string().length(2, "Country code must be 2 characters"),
|
|
826
|
+
/** English name of the country */
|
|
827
|
+
name: z2.string().min(1, "Country name required"),
|
|
828
|
+
/** Flag emoji (optional but recommended) */
|
|
829
|
+
flag: z2.string().optional(),
|
|
830
|
+
/**
|
|
831
|
+
* List of supported languages (at least one required).
|
|
832
|
+
* Supports either:
|
|
833
|
+
* - Language codes (new format)
|
|
834
|
+
* - Document references to languages (legacy format for backward compatibility)
|
|
835
|
+
*/
|
|
836
|
+
languages: z2.array(
|
|
837
|
+
z2.union([z2.string().length(2, "Language code must be 2 characters"), LanguageReferenceSchema])
|
|
838
|
+
).min(1, "At least one language required")
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
// ../../packages/cms-schema/src/documents/schemas/language.ts
|
|
842
|
+
import { z as z3 } from "zod";
|
|
843
|
+
var LanguageSchema = z3.object({
|
|
844
|
+
/** 2-letter ISO 639-1 language code */
|
|
845
|
+
code: z3.string().length(2, "Language code must be 2 characters"),
|
|
846
|
+
/** English name of the language */
|
|
847
|
+
name: z3.string().min(1, "Language name required"),
|
|
848
|
+
/** Name in the language itself (optional but recommended) */
|
|
849
|
+
nativeName: z3.string().optional()
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
// ../../packages/cms-schema/src/documents/unified-registry.ts
|
|
853
|
+
import { z as z7 } from "zod";
|
|
854
|
+
|
|
855
|
+
// ../../packages/cms-schema/src/documents/rehydration.ts
|
|
856
|
+
import { z as z6 } from "zod";
|
|
857
|
+
|
|
858
|
+
// ../../packages/cms-schema/src/fields/complex/media.ts
|
|
859
|
+
import { z as z5 } from "zod";
|
|
860
|
+
|
|
861
|
+
// ../../packages/cms-schema/src/validation/image.ts
|
|
862
|
+
import { z as z4 } from "zod";
|
|
863
|
+
var ALLOWED_MIME_TYPES = ["image/jpeg", "image/png", "image/webp"];
|
|
864
|
+
var MAX_FILE_SIZE = 10 * 1024 * 1024;
|
|
865
|
+
var MIN_FILE_SIZE = 1024;
|
|
866
|
+
var MAX_DIMENSION = 8192;
|
|
867
|
+
var MIN_DIMENSION = 10;
|
|
868
|
+
var MimeTypeSchema = z4.enum(ALLOWED_MIME_TYPES);
|
|
869
|
+
var FileSizeSchema = z4.number().int().min(MIN_FILE_SIZE, `File too small. Minimum: ${MIN_FILE_SIZE} bytes`).max(MAX_FILE_SIZE, `File too large. Maximum: ${MAX_FILE_SIZE / 1024 / 1024}MB`);
|
|
870
|
+
var DimensionSchema = z4.number().int().min(MIN_DIMENSION, `Dimension too small. Minimum: ${MIN_DIMENSION}px`).max(MAX_DIMENSION, `Dimension too large. Maximum: ${MAX_DIMENSION}px`);
|
|
871
|
+
var UploadRequestSchema = z4.object({
|
|
872
|
+
filename: z4.string().min(1, "Filename is required").max(255, "Filename too long").regex(/^[^<>:"/\\|?*]+$/, "Filename contains invalid characters"),
|
|
873
|
+
mimeType: MimeTypeSchema,
|
|
874
|
+
fileSize: FileSizeSchema
|
|
875
|
+
});
|
|
876
|
+
var ConfirmUploadSchema = z4.object({
|
|
877
|
+
assetId: z4.uuid().optional(),
|
|
878
|
+
width: DimensionSchema,
|
|
879
|
+
height: DimensionSchema
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
// ../../packages/cms-schema/src/fields/complex/media.ts
|
|
883
|
+
var ImageAssetSchema = z5.object({
|
|
884
|
+
/** UUID primary key */
|
|
885
|
+
id: z5.uuid(),
|
|
886
|
+
/** R2/S3 storage URL for the original file */
|
|
887
|
+
url: z5.url(),
|
|
888
|
+
/** Image width in pixels */
|
|
889
|
+
width: DimensionSchema,
|
|
890
|
+
/** Image height in pixels */
|
|
891
|
+
height: DimensionSchema,
|
|
892
|
+
/** Original filename from upload */
|
|
893
|
+
originalFilename: z5.string().min(1).max(255),
|
|
894
|
+
/** MIME type (only web-safe formats allowed) */
|
|
895
|
+
mimeType: MimeTypeSchema,
|
|
896
|
+
/** File size in bytes */
|
|
897
|
+
fileSize: FileSizeSchema,
|
|
898
|
+
/** Base64-encoded tiny preview for blur-up loading */
|
|
899
|
+
lqip: z5.string().optional()
|
|
900
|
+
});
|
|
901
|
+
var HotspotSchema = z5.object({
|
|
902
|
+
x: z5.number().min(0).max(1),
|
|
903
|
+
y: z5.number().min(0).max(1)
|
|
904
|
+
});
|
|
905
|
+
var CropSchema = z5.object({
|
|
906
|
+
/** X coordinate of top-left corner in pixels */
|
|
907
|
+
x: z5.number().int().nonnegative(),
|
|
908
|
+
/** Y coordinate of top-left corner in pixels */
|
|
909
|
+
y: z5.number().int().nonnegative(),
|
|
910
|
+
/** Width of crop region in pixels (must be > 0) */
|
|
911
|
+
width: z5.number().int().positive(),
|
|
912
|
+
/** Height of crop region in pixels (must be > 0) */
|
|
913
|
+
height: z5.number().int().positive()
|
|
914
|
+
});
|
|
915
|
+
var ImageReferenceSchema = z5.object({
|
|
916
|
+
// Alt text is REQUIRED for accessibility
|
|
917
|
+
alt: z5.string().min(1, "Alt text is required for accessibility"),
|
|
918
|
+
// Optional metadata
|
|
919
|
+
caption: z5.string().max(500).optional(),
|
|
920
|
+
attribution: z5.string().max(255).optional(),
|
|
921
|
+
// Reference to the ImageAsset with stored transformation
|
|
922
|
+
_asset: z5.object({
|
|
923
|
+
id: z5.uuid(),
|
|
924
|
+
transformation: z5.string().nullable().optional()
|
|
925
|
+
})
|
|
926
|
+
});
|
|
927
|
+
var fileSchema = z5.object({
|
|
928
|
+
url: z5.url(),
|
|
929
|
+
name: z5.string(),
|
|
930
|
+
size: z5.number().int().positive(),
|
|
931
|
+
type: z5.string()
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
// ../../packages/cms-schema/src/utils/safe-regex.ts
|
|
935
|
+
var import_safe_regex2 = __toESM(require_safe_regex2(), 1);
|
|
936
|
+
function validateSafeRegex(pattern) {
|
|
937
|
+
if (pattern.length > 500) {
|
|
938
|
+
return "Regex pattern is too long (max 500 characters)";
|
|
939
|
+
}
|
|
940
|
+
if (!(0, import_safe_regex2.default)(pattern)) {
|
|
941
|
+
return "Regex pattern is potentially unsafe (ReDoS risk)";
|
|
942
|
+
}
|
|
943
|
+
try {
|
|
944
|
+
new RegExp(pattern);
|
|
945
|
+
} catch (err2) {
|
|
946
|
+
return `Invalid regex: ${err2 instanceof Error ? err2.message : "Unknown"}`;
|
|
947
|
+
}
|
|
948
|
+
return null;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
// ../../packages/cms-schema/src/documents/rehydration.ts
|
|
952
|
+
var RehydrationError = class extends Error {
|
|
953
|
+
constructor(message, fieldName, fieldType) {
|
|
954
|
+
super(message);
|
|
955
|
+
this.fieldName = fieldName;
|
|
956
|
+
this.fieldType = fieldType;
|
|
957
|
+
this.name = "RehydrationError";
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
function rehydrateField(field) {
|
|
961
|
+
try {
|
|
962
|
+
let schema = createBaseSchema(field.type, field.constraints);
|
|
963
|
+
if (!field.required) {
|
|
964
|
+
schema = schema.optional();
|
|
965
|
+
}
|
|
966
|
+
return schema;
|
|
967
|
+
} catch (err2) {
|
|
968
|
+
throw new RehydrationError(
|
|
969
|
+
`Failed to rehydrate field "${field.name}": ${err2 instanceof Error ? err2.message : "Unknown error"}`,
|
|
970
|
+
field.name,
|
|
971
|
+
field.type
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
function createBaseSchema(type, constraints) {
|
|
976
|
+
switch (type) {
|
|
977
|
+
case "string":
|
|
978
|
+
return applyStringConstraints(z6.string(), constraints);
|
|
979
|
+
case "number":
|
|
980
|
+
return applyNumberConstraints(z6.number(), constraints);
|
|
981
|
+
case "boolean":
|
|
982
|
+
return z6.boolean();
|
|
983
|
+
case "image":
|
|
984
|
+
return ImageReferenceSchema;
|
|
985
|
+
case "date":
|
|
986
|
+
return z6.string().date("Invalid date format. Expected YYYY-MM-DD");
|
|
987
|
+
case "datetime":
|
|
988
|
+
return z6.string().datetime({ offset: true, message: "Invalid datetime format. Expected ISO 8601" });
|
|
989
|
+
case "url":
|
|
990
|
+
return applyStringConstraints(z6.string().url("Invalid URL format"), constraints);
|
|
991
|
+
case "email":
|
|
992
|
+
return applyStringConstraints(z6.string().email("Invalid email format"), constraints);
|
|
993
|
+
case "enum": {
|
|
994
|
+
const values = constraints?.enumValues;
|
|
995
|
+
if (!values || values.length === 0) {
|
|
996
|
+
throw new Error("Enum field requires at least one enumValues in constraints");
|
|
997
|
+
}
|
|
998
|
+
return z6.enum(values);
|
|
999
|
+
}
|
|
1000
|
+
case "reference":
|
|
1001
|
+
return z6.record(z6.string(), z6.unknown());
|
|
1002
|
+
case "array": {
|
|
1003
|
+
const itemType = constraints?.arrayItemType ?? "string";
|
|
1004
|
+
const itemSchema = createPrimitiveSchema(itemType);
|
|
1005
|
+
return applyArrayConstraints(z6.array(itemSchema), constraints);
|
|
1006
|
+
}
|
|
1007
|
+
default:
|
|
1008
|
+
throw new Error(`Unknown field type: ${type}`);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
function createPrimitiveSchema(type) {
|
|
1012
|
+
switch (type) {
|
|
1013
|
+
case "string":
|
|
1014
|
+
return z6.string();
|
|
1015
|
+
case "number":
|
|
1016
|
+
return z6.number();
|
|
1017
|
+
case "boolean":
|
|
1018
|
+
return z6.boolean();
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
function applyStringConstraints(schema, constraints) {
|
|
1022
|
+
if (!constraints) return schema;
|
|
1023
|
+
if (constraints.minLength !== void 0 && constraints.maxLength !== void 0 && constraints.minLength > constraints.maxLength) {
|
|
1024
|
+
throw new Error(
|
|
1025
|
+
`Invalid string constraints: minLength (${constraints.minLength}) cannot be greater than maxLength (${constraints.maxLength})`
|
|
1026
|
+
);
|
|
1027
|
+
}
|
|
1028
|
+
let result = schema;
|
|
1029
|
+
if (constraints.minLength !== void 0) {
|
|
1030
|
+
result = result.min(
|
|
1031
|
+
constraints.minLength,
|
|
1032
|
+
`Must be at least ${constraints.minLength} characters`
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
if (constraints.maxLength !== void 0) {
|
|
1036
|
+
result = result.max(
|
|
1037
|
+
constraints.maxLength,
|
|
1038
|
+
`Must be at most ${constraints.maxLength} characters`
|
|
1039
|
+
);
|
|
1040
|
+
}
|
|
1041
|
+
if (constraints.pattern) {
|
|
1042
|
+
const safetyError = validateSafeRegex(constraints.pattern);
|
|
1043
|
+
if (safetyError) {
|
|
1044
|
+
throw new Error(safetyError);
|
|
1045
|
+
}
|
|
1046
|
+
try {
|
|
1047
|
+
result = result.regex(new RegExp(constraints.pattern), "Invalid format");
|
|
1048
|
+
} catch {
|
|
1049
|
+
throw new Error(`Invalid regex pattern: ${constraints.pattern}`);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
return result;
|
|
1053
|
+
}
|
|
1054
|
+
function applyNumberConstraints(schema, constraints) {
|
|
1055
|
+
if (!constraints) return schema;
|
|
1056
|
+
if (constraints.min !== void 0 && constraints.max !== void 0 && constraints.min > constraints.max) {
|
|
1057
|
+
throw new Error(
|
|
1058
|
+
`Invalid number constraints: min (${constraints.min}) cannot be greater than max (${constraints.max})`
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
let result = schema;
|
|
1062
|
+
if (constraints.min !== void 0) {
|
|
1063
|
+
result = result.min(constraints.min, `Must be at least ${constraints.min}`);
|
|
1064
|
+
}
|
|
1065
|
+
if (constraints.max !== void 0) {
|
|
1066
|
+
result = result.max(constraints.max, `Must be at most ${constraints.max}`);
|
|
1067
|
+
}
|
|
1068
|
+
if (constraints.integer) {
|
|
1069
|
+
result = result.int("Must be an integer");
|
|
1070
|
+
}
|
|
1071
|
+
return result;
|
|
1072
|
+
}
|
|
1073
|
+
function applyArrayConstraints(schema, constraints) {
|
|
1074
|
+
if (!constraints) return schema;
|
|
1075
|
+
if (constraints.minItems !== void 0 && constraints.maxItems !== void 0 && constraints.minItems > constraints.maxItems) {
|
|
1076
|
+
throw new Error(
|
|
1077
|
+
`Invalid array constraints: minItems (${constraints.minItems}) cannot be greater than maxItems (${constraints.maxItems})`
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1080
|
+
let result = schema;
|
|
1081
|
+
if (constraints.minItems !== void 0) {
|
|
1082
|
+
result = result.min(constraints.minItems, `Must have at least ${constraints.minItems} items`);
|
|
1083
|
+
}
|
|
1084
|
+
if (constraints.maxItems !== void 0) {
|
|
1085
|
+
result = result.max(constraints.maxItems, `Must have at most ${constraints.maxItems} items`);
|
|
1086
|
+
}
|
|
1087
|
+
return result;
|
|
1088
|
+
}
|
|
1089
|
+
function rehydrateSchema(fields) {
|
|
1090
|
+
if (!Array.isArray(fields) || fields.length === 0) {
|
|
1091
|
+
throw new RehydrationError("Schema must have at least one field");
|
|
1092
|
+
}
|
|
1093
|
+
const shape = {};
|
|
1094
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
1095
|
+
for (const field of fields) {
|
|
1096
|
+
if (seenNames.has(field.name)) {
|
|
1097
|
+
throw new RehydrationError(`Duplicate field name: "${field.name}"`);
|
|
1098
|
+
}
|
|
1099
|
+
seenNames.add(field.name);
|
|
1100
|
+
if (!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(field.name)) {
|
|
1101
|
+
throw new RehydrationError(
|
|
1102
|
+
`Invalid field name "${field.name}": must start with a letter and contain only alphanumeric characters and underscores`,
|
|
1103
|
+
field.name
|
|
1104
|
+
);
|
|
1105
|
+
}
|
|
1106
|
+
shape[field.name] = rehydrateField(field);
|
|
1107
|
+
}
|
|
1108
|
+
return z6.object(shape);
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// ../../packages/cms-schema/src/documents/schema-hash.ts
|
|
1112
|
+
import hash from "object-hash";
|
|
1113
|
+
|
|
1114
|
+
// ../../packages/cms-schema/src/documents/validations/country.ts
|
|
1115
|
+
import { TRPCError } from "@trpc/server";
|
|
1116
|
+
|
|
1117
|
+
// ../../packages/cms-schema/src/documents/generate-zod-code.ts
|
|
1118
|
+
function generateZodSchemaCode(schemaName, fields) {
|
|
1119
|
+
const lines = [];
|
|
1120
|
+
lines.push(`import { z } from 'zod';`);
|
|
1121
|
+
lines.push("");
|
|
1122
|
+
const hasImageField = fields.some((f) => f.type === "image");
|
|
1123
|
+
if (hasImageField) {
|
|
1124
|
+
appendImageReferenceSchema(lines);
|
|
1125
|
+
lines.push("");
|
|
1126
|
+
}
|
|
1127
|
+
appendSchemaBody(lines, schemaName, fields);
|
|
1128
|
+
return lines.join("\n");
|
|
1129
|
+
}
|
|
1130
|
+
function generateCombinedZodSchemaCode(schemas) {
|
|
1131
|
+
const lines = [];
|
|
1132
|
+
lines.push(`import { z } from 'zod';`);
|
|
1133
|
+
lines.push("");
|
|
1134
|
+
const hasImageField = schemas.some((s) => s.fields.some((f) => f.type === "image"));
|
|
1135
|
+
if (hasImageField) {
|
|
1136
|
+
appendImageReferenceSchema(lines);
|
|
1137
|
+
lines.push("");
|
|
1138
|
+
}
|
|
1139
|
+
for (let i = 0; i < schemas.length; i++) {
|
|
1140
|
+
const schema = schemas[i];
|
|
1141
|
+
if (i > 0) lines.push("");
|
|
1142
|
+
appendSchemaBody(lines, schema.name, schema.fields);
|
|
1143
|
+
}
|
|
1144
|
+
return lines.join("\n");
|
|
1145
|
+
}
|
|
1146
|
+
function appendSchemaBody(lines, schemaName, fields) {
|
|
1147
|
+
const varName = toCamelCase(schemaName) + "Schema";
|
|
1148
|
+
lines.push(`export const ${varName} = z.object({`);
|
|
1149
|
+
for (const field of fields) {
|
|
1150
|
+
const fieldCode = generateFieldCode(field);
|
|
1151
|
+
if (field.description) {
|
|
1152
|
+
lines.push(` /** ${field.description} */`);
|
|
1153
|
+
}
|
|
1154
|
+
lines.push(` ${field.name}: ${fieldCode},`);
|
|
1155
|
+
}
|
|
1156
|
+
lines.push("});");
|
|
1157
|
+
lines.push("");
|
|
1158
|
+
lines.push(`export type ${toPascalCase(schemaName)} = z.infer<typeof ${varName}>;`);
|
|
1159
|
+
lines.push("");
|
|
1160
|
+
}
|
|
1161
|
+
function appendImageReferenceSchema(lines) {
|
|
1162
|
+
lines.push("const ImageReferenceSchema = z.object({");
|
|
1163
|
+
lines.push(" alt: z.string().min(1, 'Alt text is required for accessibility'),");
|
|
1164
|
+
lines.push(" caption: z.string().max(500).optional(),");
|
|
1165
|
+
lines.push(" attribution: z.string().max(255).optional(),");
|
|
1166
|
+
lines.push(" _asset: z.object({");
|
|
1167
|
+
lines.push(" id: z.string().uuid(),");
|
|
1168
|
+
lines.push(" }),");
|
|
1169
|
+
lines.push("});");
|
|
1170
|
+
}
|
|
1171
|
+
function generateFieldCode(field) {
|
|
1172
|
+
let code = generateBaseTypeCode(field.type, field.constraints);
|
|
1173
|
+
if (!field.required) {
|
|
1174
|
+
code += ".optional()";
|
|
1175
|
+
}
|
|
1176
|
+
return code;
|
|
1177
|
+
}
|
|
1178
|
+
function generateBaseTypeCode(type, constraints) {
|
|
1179
|
+
switch (type) {
|
|
1180
|
+
case "string":
|
|
1181
|
+
return applyStringConstraintCode("z.string()", constraints);
|
|
1182
|
+
case "number":
|
|
1183
|
+
return applyNumberConstraintCode("z.number()", constraints);
|
|
1184
|
+
case "boolean":
|
|
1185
|
+
return "z.boolean()";
|
|
1186
|
+
case "image":
|
|
1187
|
+
return "ImageReferenceSchema";
|
|
1188
|
+
case "date":
|
|
1189
|
+
return "z.string().date('Invalid date format. Expected YYYY-MM-DD')";
|
|
1190
|
+
case "datetime":
|
|
1191
|
+
return "z.string().datetime({ offset: true, message: 'Invalid datetime format. Expected ISO 8601' })";
|
|
1192
|
+
case "url":
|
|
1193
|
+
return applyStringConstraintCode("z.string().url('Invalid URL format')", constraints);
|
|
1194
|
+
case "email":
|
|
1195
|
+
return applyStringConstraintCode("z.string().email('Invalid email format')", constraints);
|
|
1196
|
+
case "enum": {
|
|
1197
|
+
const values = constraints?.enumValues;
|
|
1198
|
+
if (!values || values.length === 0) {
|
|
1199
|
+
return "z.enum([''])";
|
|
1200
|
+
}
|
|
1201
|
+
const formatted = values.map((v) => `'${escapeString(v)}'`).join(", ");
|
|
1202
|
+
return `z.enum([${formatted}])`;
|
|
1203
|
+
}
|
|
1204
|
+
case "reference":
|
|
1205
|
+
return "z.record(z.string(), z.unknown())";
|
|
1206
|
+
case "array": {
|
|
1207
|
+
const itemType = constraints?.arrayItemType ?? "string";
|
|
1208
|
+
const itemCode = generatePrimitiveCode(itemType);
|
|
1209
|
+
return applyArrayConstraintCode(`z.array(${itemCode})`, constraints);
|
|
1210
|
+
}
|
|
1211
|
+
default:
|
|
1212
|
+
return "z.unknown()";
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
function generatePrimitiveCode(type) {
|
|
1216
|
+
switch (type) {
|
|
1217
|
+
case "string":
|
|
1218
|
+
return "z.string()";
|
|
1219
|
+
case "number":
|
|
1220
|
+
return "z.number()";
|
|
1221
|
+
case "boolean":
|
|
1222
|
+
return "z.boolean()";
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
function applyStringConstraintCode(base, constraints) {
|
|
1226
|
+
if (!constraints) return base;
|
|
1227
|
+
let code = base;
|
|
1228
|
+
if (constraints.minLength !== void 0) {
|
|
1229
|
+
code += `.min(${constraints.minLength}, 'Must be at least ${constraints.minLength} characters')`;
|
|
1230
|
+
}
|
|
1231
|
+
if (constraints.maxLength !== void 0) {
|
|
1232
|
+
code += `.max(${constraints.maxLength}, 'Must be at most ${constraints.maxLength} characters')`;
|
|
1233
|
+
}
|
|
1234
|
+
if (constraints.pattern) {
|
|
1235
|
+
code += `.regex(/${escapeRegex(constraints.pattern)}/, 'Invalid format')`;
|
|
1236
|
+
}
|
|
1237
|
+
return code;
|
|
1238
|
+
}
|
|
1239
|
+
function applyNumberConstraintCode(base, constraints) {
|
|
1240
|
+
if (!constraints) return base;
|
|
1241
|
+
let code = base;
|
|
1242
|
+
if (constraints.integer) {
|
|
1243
|
+
code += `.int('Must be an integer')`;
|
|
1244
|
+
}
|
|
1245
|
+
if (constraints.min !== void 0) {
|
|
1246
|
+
code += `.min(${constraints.min}, 'Must be at least ${constraints.min}')`;
|
|
1247
|
+
}
|
|
1248
|
+
if (constraints.max !== void 0) {
|
|
1249
|
+
code += `.max(${constraints.max}, 'Must be at most ${constraints.max}')`;
|
|
1250
|
+
}
|
|
1251
|
+
return code;
|
|
1252
|
+
}
|
|
1253
|
+
function applyArrayConstraintCode(base, constraints) {
|
|
1254
|
+
if (!constraints) return base;
|
|
1255
|
+
let code = base;
|
|
1256
|
+
if (constraints.minItems !== void 0) {
|
|
1257
|
+
code += `.min(${constraints.minItems}, 'Must have at least ${constraints.minItems} items')`;
|
|
1258
|
+
}
|
|
1259
|
+
if (constraints.maxItems !== void 0) {
|
|
1260
|
+
code += `.max(${constraints.maxItems}, 'Must have at most ${constraints.maxItems} items')`;
|
|
1261
|
+
}
|
|
1262
|
+
return code;
|
|
1263
|
+
}
|
|
1264
|
+
function escapeString(str) {
|
|
1265
|
+
return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
1266
|
+
}
|
|
1267
|
+
function escapeRegex(pattern) {
|
|
1268
|
+
return pattern.replace(/\//g, "\\/");
|
|
1269
|
+
}
|
|
1270
|
+
function toCamelCase(str) {
|
|
1271
|
+
return str.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
1272
|
+
}
|
|
1273
|
+
function toPascalCase(str) {
|
|
1274
|
+
const camel = toCamelCase(str);
|
|
1275
|
+
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
// lib/cms-api.ts
|
|
1279
|
+
import { createTRPCClient, httpBatchLink } from "@trpc/client";
|
|
1280
|
+
import superjson from "superjson";
|
|
1281
|
+
function getCmsApiUrl(cmsUrl) {
|
|
1282
|
+
return new URL("/api/trpc", cmsUrl).toString();
|
|
1283
|
+
}
|
|
1284
|
+
function createFetchWithApiKey(apiKey, websiteId) {
|
|
1285
|
+
return async (url, options) => {
|
|
1286
|
+
let finalUrl = url;
|
|
1287
|
+
const urlObj = new URL(url.toString());
|
|
1288
|
+
if (apiKey) {
|
|
1289
|
+
urlObj.searchParams.set("api_key", apiKey);
|
|
1290
|
+
}
|
|
1291
|
+
if (websiteId) {
|
|
1292
|
+
urlObj.searchParams.set("website_id", websiteId);
|
|
1293
|
+
}
|
|
1294
|
+
if (apiKey || websiteId) {
|
|
1295
|
+
finalUrl = urlObj.toString();
|
|
1296
|
+
}
|
|
1297
|
+
const response = await fetch(finalUrl, options);
|
|
1298
|
+
return response;
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
function createCmsClient(options) {
|
|
1302
|
+
const url = getCmsApiUrl(options.cmsUrl);
|
|
1303
|
+
return createTRPCClient({
|
|
1304
|
+
links: [
|
|
1305
|
+
httpBatchLink({
|
|
1306
|
+
url,
|
|
1307
|
+
transformer: superjson,
|
|
1308
|
+
fetch: createFetchWithApiKey(options.apiKey, options.websiteId)
|
|
1309
|
+
})
|
|
1310
|
+
]
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
function getCmsClient(options) {
|
|
1314
|
+
return createCmsClient(options);
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
// lib/custom-schemas.ts
|
|
1318
|
+
async function fetchAllCustomSchemaFields(options) {
|
|
1319
|
+
const { websiteId } = options;
|
|
1320
|
+
const client = getCmsClient(options);
|
|
1321
|
+
const summaries = await client.customSchema.list.query({
|
|
1322
|
+
websiteId,
|
|
1323
|
+
includeSystem: false
|
|
1324
|
+
});
|
|
1325
|
+
const schemas = await Promise.all(
|
|
1326
|
+
summaries.map(async (summary) => {
|
|
1327
|
+
const detail = await client.customSchema.getByName.query({
|
|
1328
|
+
websiteId,
|
|
1329
|
+
name: summary.name
|
|
1330
|
+
});
|
|
1331
|
+
return {
|
|
1332
|
+
name: detail.name,
|
|
1333
|
+
displayName: detail.displayName,
|
|
1334
|
+
description: detail.description ?? null,
|
|
1335
|
+
fields: detail.fields,
|
|
1336
|
+
routeSlugField: detail.routeSlugField ?? null,
|
|
1337
|
+
version: detail.version
|
|
1338
|
+
};
|
|
1339
|
+
})
|
|
1340
|
+
);
|
|
1341
|
+
return schemas;
|
|
1342
|
+
}
|
|
1343
|
+
async function fetchCustomSchemaFields(options, schemaName) {
|
|
1344
|
+
const { websiteId } = options;
|
|
1345
|
+
const client = getCmsClient(options);
|
|
1346
|
+
const detail = await client.customSchema.getByName.query({
|
|
1347
|
+
websiteId,
|
|
1348
|
+
name: schemaName
|
|
1349
|
+
});
|
|
1350
|
+
return {
|
|
1351
|
+
name: detail.name,
|
|
1352
|
+
displayName: detail.displayName,
|
|
1353
|
+
description: detail.description ?? null,
|
|
1354
|
+
fields: detail.fields,
|
|
1355
|
+
routeSlugField: detail.routeSlugField ?? null,
|
|
1356
|
+
version: detail.version
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
function buildZodSchemas(schemas) {
|
|
1360
|
+
const result = {};
|
|
1361
|
+
for (const schema of schemas) {
|
|
1362
|
+
result[schema.name] = rehydrateSchema(schema.fields);
|
|
1363
|
+
}
|
|
1364
|
+
return result;
|
|
1365
|
+
}
|
|
1366
|
+
function buildZodSchemaCode(schemas) {
|
|
1367
|
+
const result = {};
|
|
1368
|
+
for (const schema of schemas) {
|
|
1369
|
+
result[schema.name] = generateZodSchemaCode(schema.name, schema.fields);
|
|
1370
|
+
}
|
|
1371
|
+
return result;
|
|
1372
|
+
}
|
|
1373
|
+
async function saveZodSchemaCode(schemas, filePath) {
|
|
1374
|
+
if (schemas.length === 0) {
|
|
1375
|
+
console.warn("[saveZodSchemaCode] No schemas provided \u2014 skipping file write.");
|
|
1376
|
+
return;
|
|
1377
|
+
}
|
|
1378
|
+
const code = generateCombinedZodSchemaCode(schemas);
|
|
1379
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
1380
|
+
await writeFile(filePath, code, "utf-8");
|
|
1381
|
+
}
|
|
1382
|
+
export {
|
|
1383
|
+
buildZodSchemaCode,
|
|
1384
|
+
buildZodSchemas,
|
|
1385
|
+
fetchAllCustomSchemaFields,
|
|
1386
|
+
fetchCustomSchemaFields,
|
|
1387
|
+
saveZodSchemaCode
|
|
1388
|
+
};
|
|
1389
|
+
//# sourceMappingURL=custom-schemas.js.map
|