@stndrds/schema 0.1.0-alpha.57 → 0.1.0-alpha.58
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/{chunk-DPRLHGPO.js → chunk-2OS63USQ.js} +270 -916
- package/dist/{chunk-YVUSATKC.mjs → chunk-JRY236AO.mjs} +76 -722
- package/dist/chunk-NEVERCM3.js +41 -0
- package/dist/chunk-SV4BCGQU.mjs +617 -0
- package/dist/chunk-U4AB53AM.js +617 -0
- package/dist/chunk-V2RPPE2Y.mjs +41 -0
- package/dist/index.d.mts +51 -29
- package/dist/index.d.ts +51 -29
- package/dist/index.js +10 -100
- package/dist/index.mjs +76 -166
- package/dist/{runtime-BqJdmg_4.d.mts → runtime-C4vB_EcQ.d.ts} +5 -1645
- package/dist/{runtime-BqJdmg_4.d.ts → runtime-SCsDOQi0.d.mts} +5 -1645
- package/dist/runtime.d.mts +3 -1
- package/dist/runtime.d.ts +3 -1
- package/dist/runtime.js +4 -2
- package/dist/runtime.mjs +3 -1
- package/dist/utils.d.mts +154 -0
- package/dist/utils.d.ts +154 -0
- package/dist/utils.js +19 -0
- package/dist/utils.mjs +19 -0
- package/dist/validation/validators.d.mts +4 -0
- package/dist/validation/validators.d.ts +4 -0
- package/dist/validation/validators.js +121 -0
- package/dist/validation/validators.mjs +121 -0
- package/dist/validators-BgmWgr-G.d.mts +1488 -0
- package/dist/validators-miARInAq.d.ts +1488 -0
- package/package.json +12 -2
|
@@ -1,40 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
asTenantId,
|
|
3
|
+
asUserId,
|
|
4
|
+
generateId
|
|
5
|
+
} from "./chunk-V2RPPE2Y.mjs";
|
|
6
|
+
import {
|
|
7
|
+
computeRecordStatus,
|
|
8
|
+
formatZodErrors,
|
|
9
|
+
parseAttributeConfig,
|
|
10
|
+
validateDraftOrThrow,
|
|
11
|
+
validateObject,
|
|
12
|
+
validateObjectOrThrow
|
|
13
|
+
} from "./chunk-SV4BCGQU.mjs";
|
|
1
14
|
import {
|
|
2
15
|
__require
|
|
3
16
|
} from "./chunk-Y6FXYEAI.mjs";
|
|
4
17
|
|
|
5
18
|
// src/runtime/auth/workflow-jwt.service.ts
|
|
6
19
|
import { SignJWT, importPKCS8, importSPKI, jwtVerify } from "jose";
|
|
7
|
-
|
|
8
|
-
// src/utils.ts
|
|
9
|
-
function asTenantId(id) {
|
|
10
|
-
return id;
|
|
11
|
-
}
|
|
12
|
-
function asUserId(id) {
|
|
13
|
-
return id;
|
|
14
|
-
}
|
|
15
|
-
function generateId() {
|
|
16
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
17
|
-
return crypto.randomUUID();
|
|
18
|
-
}
|
|
19
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
20
|
-
const r = Math.random() * 16 | 0;
|
|
21
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
22
|
-
return v.toString(16);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
function generatePrefixedId(prefix) {
|
|
26
|
-
return `${prefix}_${generateId()}`;
|
|
27
|
-
}
|
|
28
|
-
function slugify(input) {
|
|
29
|
-
return input.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().replace(/[^a-z0-9\s_-]/g, "").trim().replace(/\s+/g, "-").replace(/-+/g, "-");
|
|
30
|
-
}
|
|
31
|
-
function generateTemplateName(label) {
|
|
32
|
-
const slug = slugify(label) || "template";
|
|
33
|
-
const suffix = generateId().slice(0, 8);
|
|
34
|
-
return `${slug}-${suffix}`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// src/runtime/auth/workflow-jwt.service.ts
|
|
38
20
|
var WorkflowJwtService = class _WorkflowJwtService {
|
|
39
21
|
constructor(config) {
|
|
40
22
|
this.config = config;
|
|
@@ -212,6 +194,26 @@ var WorkflowJwtService = class _WorkflowJwtService {
|
|
|
212
194
|
}
|
|
213
195
|
};
|
|
214
196
|
|
|
197
|
+
// src/lib/object-helpers.ts
|
|
198
|
+
function isEmpty(obj) {
|
|
199
|
+
if (obj === null || obj === void 0) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
if (typeof obj !== "object") {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
return Object.keys(obj).length === 0;
|
|
206
|
+
}
|
|
207
|
+
function isNotEmpty(obj) {
|
|
208
|
+
return obj !== null && obj !== void 0 && typeof obj === "object" && Object.keys(obj).length > 0;
|
|
209
|
+
}
|
|
210
|
+
function toUndefinedIfEmpty(obj) {
|
|
211
|
+
return isNotEmpty(obj) ? obj : void 0;
|
|
212
|
+
}
|
|
213
|
+
function hasProperties(obj) {
|
|
214
|
+
return isNotEmpty(obj);
|
|
215
|
+
}
|
|
216
|
+
|
|
215
217
|
// src/runtime/cache.ts
|
|
216
218
|
function fnv1aHash(str) {
|
|
217
219
|
let hash = 2166136261;
|
|
@@ -222,7 +224,7 @@ function fnv1aHash(str) {
|
|
|
222
224
|
return hash.toString(16).padStart(8, "0");
|
|
223
225
|
}
|
|
224
226
|
function hashOptions(options) {
|
|
225
|
-
if (
|
|
227
|
+
if (isEmpty(options)) {
|
|
226
228
|
return "default";
|
|
227
229
|
}
|
|
228
230
|
const sortedJson = JSON.stringify(options, (_, value) => {
|
|
@@ -1345,12 +1347,6 @@ function or(...rules) {
|
|
|
1345
1347
|
function inValues(field, values) {
|
|
1346
1348
|
return { field, operator: "in", value: values };
|
|
1347
1349
|
}
|
|
1348
|
-
function isEmpty(field) {
|
|
1349
|
-
return { field, operator: "isEmpty", value: null };
|
|
1350
|
-
}
|
|
1351
|
-
function isNotEmpty(field) {
|
|
1352
|
-
return { field, operator: "isNotEmpty", value: null };
|
|
1353
|
-
}
|
|
1354
1350
|
|
|
1355
1351
|
// src/types/workflows/definition.ts
|
|
1356
1352
|
function isWorkflowDefinition(obj) {
|
|
@@ -1460,16 +1456,6 @@ function setContextValue(context, path, value) {
|
|
|
1460
1456
|
}
|
|
1461
1457
|
current[parts[parts.length - 1]] = value;
|
|
1462
1458
|
}
|
|
1463
|
-
function mergeFormToSlot(context, nodeId, slotId) {
|
|
1464
|
-
const formData = context.forms[nodeId];
|
|
1465
|
-
if (!formData) {
|
|
1466
|
-
return;
|
|
1467
|
-
}
|
|
1468
|
-
if (!context.slots[slotId]) {
|
|
1469
|
-
context.slots[slotId] = {};
|
|
1470
|
-
}
|
|
1471
|
-
Object.assign(context.slots[slotId], formData);
|
|
1472
|
-
}
|
|
1473
1459
|
|
|
1474
1460
|
// src/types/workflows/theme.ts
|
|
1475
1461
|
var DEFAULT_THEME = {
|
|
@@ -1823,9 +1809,9 @@ function compareValues(actual, operator, expected) {
|
|
|
1823
1809
|
return typeof actual === "string" && typeof expected === "string" ? actual.endsWith(expected) : false;
|
|
1824
1810
|
// Presence
|
|
1825
1811
|
case "isEmpty":
|
|
1826
|
-
return
|
|
1812
|
+
return isEmptyValue(actual);
|
|
1827
1813
|
case "isNotEmpty":
|
|
1828
|
-
return !
|
|
1814
|
+
return !isEmptyValue(actual);
|
|
1829
1815
|
// Set membership
|
|
1830
1816
|
case "in":
|
|
1831
1817
|
if (Array.isArray(expected)) {
|
|
@@ -1841,7 +1827,7 @@ function compareValues(actual, operator, expected) {
|
|
|
1841
1827
|
return false;
|
|
1842
1828
|
}
|
|
1843
1829
|
}
|
|
1844
|
-
function
|
|
1830
|
+
function isEmptyValue(value) {
|
|
1845
1831
|
if (value === null || value === void 0) {
|
|
1846
1832
|
return true;
|
|
1847
1833
|
}
|
|
@@ -1851,7 +1837,7 @@ function isEmpty2(value) {
|
|
|
1851
1837
|
if (Array.isArray(value) && value.length === 0) {
|
|
1852
1838
|
return true;
|
|
1853
1839
|
}
|
|
1854
|
-
if (typeof value === "object" &&
|
|
1840
|
+
if (typeof value === "object" && isEmpty(value)) {
|
|
1855
1841
|
return true;
|
|
1856
1842
|
}
|
|
1857
1843
|
return false;
|
|
@@ -2096,7 +2082,7 @@ var DocumentExecutor = class {
|
|
|
2096
2082
|
validateSlotReferences(node, workflowSlots) {
|
|
2097
2083
|
const errors = [];
|
|
2098
2084
|
if (node.targetSlotIds && node.targetSlotIds.length > 0) {
|
|
2099
|
-
const slotIdSet =
|
|
2085
|
+
const slotIdSet = workflowSlots.reduce((set, s) => set.add(s.id), /* @__PURE__ */ new Set());
|
|
2100
2086
|
for (const slotId of node.targetSlotIds) {
|
|
2101
2087
|
if (!slotIdSet.has(slotId)) {
|
|
2102
2088
|
errors.push(
|
|
@@ -2132,24 +2118,25 @@ var FormExecutor = class {
|
|
|
2132
2118
|
}
|
|
2133
2119
|
execute(node, context) {
|
|
2134
2120
|
const { input } = context;
|
|
2135
|
-
if (
|
|
2121
|
+
if (isEmpty(input)) {
|
|
2136
2122
|
const requiredParticipationId = node.participantId ?? void 0;
|
|
2137
2123
|
return wait(`Waiting for form submission: ${node.label}`, {
|
|
2138
2124
|
requiredParticipationId
|
|
2139
2125
|
});
|
|
2140
2126
|
}
|
|
2127
|
+
const formInput = input;
|
|
2141
2128
|
const slotIds = this.extractSlotIds(node);
|
|
2142
2129
|
if (slotIds.size === 0) {
|
|
2143
2130
|
return error("MISSING_FIELDS", "FormNode must have fields or rows with slot references");
|
|
2144
2131
|
}
|
|
2145
2132
|
const contextUpdates = {
|
|
2146
2133
|
forms: {
|
|
2147
|
-
[node.id]:
|
|
2134
|
+
[node.id]: formInput
|
|
2148
2135
|
},
|
|
2149
2136
|
slots: {}
|
|
2150
2137
|
};
|
|
2151
2138
|
for (const slotId of slotIds) {
|
|
2152
|
-
const slotInput =
|
|
2139
|
+
const slotInput = formInput[slotId] ?? {};
|
|
2153
2140
|
if (!contextUpdates.slots) {
|
|
2154
2141
|
contextUpdates.slots = {};
|
|
2155
2142
|
}
|
|
@@ -2177,9 +2164,9 @@ var FormExecutor = class {
|
|
|
2177
2164
|
}
|
|
2178
2165
|
canExecute(node, context) {
|
|
2179
2166
|
if (node.participantId && context.executorId) {
|
|
2180
|
-
return
|
|
2167
|
+
return hasProperties(context.input);
|
|
2181
2168
|
}
|
|
2182
|
-
return
|
|
2169
|
+
return hasProperties(context.input);
|
|
2183
2170
|
}
|
|
2184
2171
|
validate(node) {
|
|
2185
2172
|
const errors = [];
|
|
@@ -3471,9 +3458,6 @@ var ConcurrentModificationError = class extends SchemaError {
|
|
|
3471
3458
|
);
|
|
3472
3459
|
}
|
|
3473
3460
|
};
|
|
3474
|
-
function isConcurrentModificationError(error2) {
|
|
3475
|
-
return error2 instanceof ConcurrentModificationError;
|
|
3476
|
-
}
|
|
3477
3461
|
|
|
3478
3462
|
// src/format.ts
|
|
3479
3463
|
import { getCountryByIso3 } from "@stndrds/constants";
|
|
@@ -4302,7 +4286,8 @@ function createMockPermissionsRepository(stores) {
|
|
|
4302
4286
|
getUserRoles(userProfileId) {
|
|
4303
4287
|
const tenantId = getTenantId();
|
|
4304
4288
|
const roleIds = Array.from(stores.userRoles.values()).filter((ur) => ur.userProfileId === userProfileId && ur.tenantId === tenantId).map((ur) => ur.roleId);
|
|
4305
|
-
const
|
|
4289
|
+
const roleIdsSet = new Set(roleIds);
|
|
4290
|
+
const roles = Array.from(stores.roles.values()).filter((r) => roleIdsSet.has(r.id));
|
|
4306
4291
|
return Promise.resolve(roles);
|
|
4307
4292
|
},
|
|
4308
4293
|
assignRole(input) {
|
|
@@ -4518,7 +4503,7 @@ function createMockViewOverlaysRepository(stores) {
|
|
|
4518
4503
|
const views = Array.from(stores.views.values()).filter(
|
|
4519
4504
|
(v) => v.tenantId === tenantId && v.objectName === objectName && v.type === type
|
|
4520
4505
|
);
|
|
4521
|
-
const viewIds =
|
|
4506
|
+
const viewIds = views.reduce((set, v) => set.add(v.id), /* @__PURE__ */ new Set());
|
|
4522
4507
|
return Promise.resolve(
|
|
4523
4508
|
Array.from(stores.viewOverlays.values()).find(
|
|
4524
4509
|
(o) => o.tenantId === tenantId && o.userId === userId && o.isUserDefault === true && viewIds.has(o.viewId)
|
|
@@ -4603,7 +4588,7 @@ function createMockViewOverlaysRepository(stores) {
|
|
|
4603
4588
|
const views = Array.from(stores.views.values()).filter(
|
|
4604
4589
|
(v) => v.tenantId === tenantId && v.objectName === objectName && v.type === type
|
|
4605
4590
|
);
|
|
4606
|
-
const viewIds =
|
|
4591
|
+
const viewIds = views.reduce((set, v) => set.add(v.id), /* @__PURE__ */ new Set());
|
|
4607
4592
|
for (const overlay of stores.viewOverlays.values()) {
|
|
4608
4593
|
if (overlay.tenantId === tenantId && overlay.userId === userId && overlay.isUserDefault === true && viewIds.has(overlay.viewId)) {
|
|
4609
4594
|
overlay.isUserDefault = false;
|
|
@@ -7899,13 +7884,13 @@ var WorkflowBuilder = class {
|
|
|
7899
7884
|
if (!this.startNodeId) {
|
|
7900
7885
|
throw new Error("[WorkflowBuilder] A start node is required. Use .start() to add one.");
|
|
7901
7886
|
}
|
|
7902
|
-
if (
|
|
7887
|
+
if (isEmpty(this.data.nodes)) {
|
|
7903
7888
|
throw new Error("[WorkflowBuilder] At least one node is required.");
|
|
7904
7889
|
}
|
|
7905
7890
|
if (!this.data.slots || this.data.slots.length === 0) {
|
|
7906
7891
|
throw new Error("[WorkflowBuilder] At least one slot is required. Use .slot() to add slots.");
|
|
7907
7892
|
}
|
|
7908
|
-
const hasEndNode = Object.values(this.data.nodes).some((n) => n.type === "end");
|
|
7893
|
+
const hasEndNode = this.data.nodes ? Object.values(this.data.nodes).some((n) => n.type === "end") : false;
|
|
7909
7894
|
if (!hasEndNode) {
|
|
7910
7895
|
throw new Error(
|
|
7911
7896
|
"[WorkflowBuilder] At least one end node is required. Use .end() to add one."
|
|
@@ -7936,7 +7921,7 @@ var WorkflowBuilder = class {
|
|
|
7936
7921
|
}
|
|
7937
7922
|
}
|
|
7938
7923
|
validateSlotReferences() {
|
|
7939
|
-
const slotIds =
|
|
7924
|
+
const slotIds = this.data.slots?.reduce((set, s) => set.add(s.id), /* @__PURE__ */ new Set()) ?? /* @__PURE__ */ new Set();
|
|
7940
7925
|
for (const node of Object.values(this.data.nodes ?? {})) {
|
|
7941
7926
|
if (node.type === "form") {
|
|
7942
7927
|
const referencedSlots = /* @__PURE__ */ new Set();
|
|
@@ -8041,22 +8026,6 @@ function isBehaviorProperty(property) {
|
|
|
8041
8026
|
function isPresentationProperty(property) {
|
|
8042
8027
|
return PRESENTATION_PROPERTIES.includes(property);
|
|
8043
8028
|
}
|
|
8044
|
-
function getPropertyProtectionLevel(property) {
|
|
8045
|
-
if (isIdentityProperty(property)) return "identity";
|
|
8046
|
-
if (isBehaviorProperty(property)) return "behavior";
|
|
8047
|
-
if (isPresentationProperty(property)) return "presentation";
|
|
8048
|
-
return "unknown";
|
|
8049
|
-
}
|
|
8050
|
-
function filterPropertiesByCategory(properties, category) {
|
|
8051
|
-
switch (category) {
|
|
8052
|
-
case "identity":
|
|
8053
|
-
return properties.filter(isIdentityProperty);
|
|
8054
|
-
case "behavior":
|
|
8055
|
-
return properties.filter(isBehaviorProperty);
|
|
8056
|
-
case "presentation":
|
|
8057
|
-
return properties.filter(isPresentationProperty);
|
|
8058
|
-
}
|
|
8059
|
-
}
|
|
8060
8029
|
|
|
8061
8030
|
// src/types/errors.ts
|
|
8062
8031
|
var RecordReferencedError = class extends Error {
|
|
@@ -8170,563 +8139,6 @@ function isSystemAttributeObject(attr) {
|
|
|
8170
8139
|
return attr.system === true;
|
|
8171
8140
|
}
|
|
8172
8141
|
|
|
8173
|
-
// src/validation/validators.ts
|
|
8174
|
-
import { z as z5 } from "zod";
|
|
8175
|
-
var regexPatternCache = /* @__PURE__ */ new Map();
|
|
8176
|
-
function getCachedRegex(pattern) {
|
|
8177
|
-
let cached = regexPatternCache.get(pattern);
|
|
8178
|
-
if (!cached) {
|
|
8179
|
-
cached = new RegExp(pattern);
|
|
8180
|
-
regexPatternCache.set(pattern, cached);
|
|
8181
|
-
}
|
|
8182
|
-
return cached;
|
|
8183
|
-
}
|
|
8184
|
-
var DEFAULT_VALIDATION_MESSAGES = {
|
|
8185
|
-
required: (attr) => `${attr.label} is required`,
|
|
8186
|
-
invalidType: (attr, expected) => `${attr.label} must be a ${expected}`,
|
|
8187
|
-
minLength: (attr, min) => `${attr.label} must be at least ${min} characters`,
|
|
8188
|
-
maxLength: (attr, max) => `${attr.label} must be at most ${max} characters`,
|
|
8189
|
-
invalidPattern: (attr) => `${attr.label} format is invalid`,
|
|
8190
|
-
minValue: (attr, min) => `${attr.label} must be at least ${min}`,
|
|
8191
|
-
maxValue: (attr, max) => `${attr.label} must be at most ${max}`,
|
|
8192
|
-
mustBeInteger: (attr) => `${attr.label} must be an integer`,
|
|
8193
|
-
invalidDate: (attr) => `${attr.label} must be a valid date`,
|
|
8194
|
-
invalidOption: (attr, options) => `${attr.label} must be one of: ${options.join(", ")}`,
|
|
8195
|
-
invalidId: (attr) => `${attr.label} must be a valid ID`,
|
|
8196
|
-
minItems: (attr, min) => `${attr.label} must have at least ${min} item${min > 1 ? "s" : ""}`,
|
|
8197
|
-
maxItems: (attr, max) => `${attr.label} must have at most ${max} item${max > 1 ? "s" : ""}`,
|
|
8198
|
-
invalidRichtext: (attr) => `${attr.label} must be valid rich text content`,
|
|
8199
|
-
invalidPhone: (attr) => `${attr.label} must be a valid phone number`,
|
|
8200
|
-
invalidCurrency: (attr) => `${attr.label} must be a valid currency value`,
|
|
8201
|
-
invalidLocation: (attr) => `${attr.label} must be a valid location`
|
|
8202
|
-
};
|
|
8203
|
-
var baseConfigSchema = z5.object({
|
|
8204
|
-
disabled: z5.boolean().optional(),
|
|
8205
|
-
placeholder: z5.string().optional(),
|
|
8206
|
-
description: z5.string().optional(),
|
|
8207
|
-
defaultValue: z5.unknown().optional(),
|
|
8208
|
-
icon: z5.string().optional(),
|
|
8209
|
-
order: z5.number().int().optional(),
|
|
8210
|
-
hidden: z5.boolean().optional(),
|
|
8211
|
-
archived: z5.boolean().optional(),
|
|
8212
|
-
deprecated: z5.boolean().optional(),
|
|
8213
|
-
metadata: z5.record(z5.string(), z5.unknown()).optional()
|
|
8214
|
-
});
|
|
8215
|
-
var optionSchema = z5.object({
|
|
8216
|
-
id: z5.string().min(1),
|
|
8217
|
-
label: z5.string().min(1),
|
|
8218
|
-
value: z5.string().min(1),
|
|
8219
|
-
color: z5.string().optional(),
|
|
8220
|
-
icon: z5.string().optional(),
|
|
8221
|
-
description: z5.string().optional(),
|
|
8222
|
-
group: z5.enum(["idle", "in_progress", "finished"]).optional()
|
|
8223
|
-
});
|
|
8224
|
-
var optionsArraySchema = z5.array(optionSchema).min(1).refine(
|
|
8225
|
-
(options) => {
|
|
8226
|
-
const values = options.map((o) => o.value);
|
|
8227
|
-
return new Set(values).size === values.length;
|
|
8228
|
-
},
|
|
8229
|
-
{ message: "Duplicate option values are not allowed" }
|
|
8230
|
-
);
|
|
8231
|
-
var relationTargetSchema = z5.object({
|
|
8232
|
-
object: z5.string().min(1),
|
|
8233
|
-
displayTemplate: z5.string().optional(),
|
|
8234
|
-
filter: z5.record(z5.string(), z5.unknown()).optional()
|
|
8235
|
-
});
|
|
8236
|
-
var textConfigSchema = baseConfigSchema.extend({
|
|
8237
|
-
minLength: z5.number().int().min(0).optional(),
|
|
8238
|
-
maxLength: z5.number().int().min(1).optional(),
|
|
8239
|
-
pattern: z5.string().optional()
|
|
8240
|
-
});
|
|
8241
|
-
var textareaConfigSchema = baseConfigSchema;
|
|
8242
|
-
var richtextConfigSchema = baseConfigSchema.extend({
|
|
8243
|
-
features: z5.array(
|
|
8244
|
-
z5.enum(["headings", "bold", "italic", "lists", "links", "images", "codeBlocks", "tables"])
|
|
8245
|
-
).optional()
|
|
8246
|
-
});
|
|
8247
|
-
var numberConfigSchema = baseConfigSchema.extend({
|
|
8248
|
-
min: z5.number().optional(),
|
|
8249
|
-
max: z5.number().optional(),
|
|
8250
|
-
unit: z5.enum(["integer", "decimal", "percentage"]).optional(),
|
|
8251
|
-
decimals: z5.number().int().min(0).optional()
|
|
8252
|
-
});
|
|
8253
|
-
var checkboxConfigSchema = baseConfigSchema;
|
|
8254
|
-
var dateConfigSchema = baseConfigSchema.extend({
|
|
8255
|
-
dateFormat: z5.enum(["short", "long", "full", "relative"]).optional(),
|
|
8256
|
-
minDate: z5.string().optional(),
|
|
8257
|
-
maxDate: z5.string().optional()
|
|
8258
|
-
});
|
|
8259
|
-
var phoneConfigSchema = baseConfigSchema.extend({
|
|
8260
|
-
defaultCountryCode: z5.string().length(3).optional()
|
|
8261
|
-
});
|
|
8262
|
-
var currencyConfigSchema = baseConfigSchema.extend({
|
|
8263
|
-
defaultCurrency: z5.string().length(3).optional(),
|
|
8264
|
-
allowedCurrencies: z5.array(z5.string().length(3)).optional()
|
|
8265
|
-
});
|
|
8266
|
-
var statusConfigSchema = baseConfigSchema.extend({
|
|
8267
|
-
options: optionsArraySchema
|
|
8268
|
-
});
|
|
8269
|
-
var locationConfigSchema = baseConfigSchema.extend({
|
|
8270
|
-
granularity: z5.enum(["full", "address", "city", "state", "country", "coordinates"]),
|
|
8271
|
-
enableAutocomplete: z5.boolean().optional(),
|
|
8272
|
-
enableMap: z5.boolean().optional(),
|
|
8273
|
-
defaultCountry: z5.string().length(3).optional(),
|
|
8274
|
-
allowedCountries: z5.array(z5.string().length(3)).optional(),
|
|
8275
|
-
displayFormat: z5.enum(["single_line", "multi_line", "compact"]).optional()
|
|
8276
|
-
});
|
|
8277
|
-
var selectConfigSchema = baseConfigSchema.extend({
|
|
8278
|
-
options: optionsArraySchema
|
|
8279
|
-
});
|
|
8280
|
-
var multiselectConfigSchema = baseConfigSchema.extend({
|
|
8281
|
-
options: optionsArraySchema
|
|
8282
|
-
});
|
|
8283
|
-
var fileConfigSchema = baseConfigSchema.extend({
|
|
8284
|
-
maxFiles: z5.number().int().min(1).optional(),
|
|
8285
|
-
maxSize: z5.number().int().min(1).optional(),
|
|
8286
|
-
allowedTypes: z5.array(z5.string()).optional(),
|
|
8287
|
-
multiple: z5.boolean().optional()
|
|
8288
|
-
});
|
|
8289
|
-
var userConfigSchema = baseConfigSchema.extend({
|
|
8290
|
-
allowedRoles: z5.array(z5.string()).optional(),
|
|
8291
|
-
multiple: z5.boolean().optional()
|
|
8292
|
-
});
|
|
8293
|
-
var relationConfigSchema = baseConfigSchema.extend({
|
|
8294
|
-
targets: z5.array(relationTargetSchema).min(1),
|
|
8295
|
-
cardinality: z5.enum(["one", "many"]),
|
|
8296
|
-
minItems: z5.number().int().min(0).optional(),
|
|
8297
|
-
maxItems: z5.number().int().min(1).optional()
|
|
8298
|
-
});
|
|
8299
|
-
var ratingConfigSchema = baseConfigSchema.extend({
|
|
8300
|
-
max: z5.number().int().min(1).optional(),
|
|
8301
|
-
iconType: z5.enum(["star", "heart", "thumbs", "number"]).optional()
|
|
8302
|
-
});
|
|
8303
|
-
var formulaConfigSchema = baseConfigSchema.extend({
|
|
8304
|
-
expression: z5.string().min(1),
|
|
8305
|
-
returnType: z5.enum(["text", "number", "boolean", "date"]),
|
|
8306
|
-
decimals: z5.number().int().min(0).max(10).optional(),
|
|
8307
|
-
allowRelations: z5.boolean().optional()
|
|
8308
|
-
});
|
|
8309
|
-
var rollupConfigSchema = baseConfigSchema.extend({
|
|
8310
|
-
relationAttribute: z5.string().min(1).optional(),
|
|
8311
|
-
relationPath: z5.string().optional(),
|
|
8312
|
-
targetAttribute: z5.string().min(1),
|
|
8313
|
-
function: z5.enum([
|
|
8314
|
-
// Numeric aggregates
|
|
8315
|
-
"sum",
|
|
8316
|
-
"avg",
|
|
8317
|
-
// Date aggregates
|
|
8318
|
-
"earliest",
|
|
8319
|
-
"latest",
|
|
8320
|
-
// Count (universal)
|
|
8321
|
-
"count",
|
|
8322
|
-
"countValues",
|
|
8323
|
-
"countUniqueValues",
|
|
8324
|
-
"countEmpty",
|
|
8325
|
-
// Percent (universal)
|
|
8326
|
-
"percentEmpty",
|
|
8327
|
-
"percentNotEmpty",
|
|
8328
|
-
// Lookup (universal)
|
|
8329
|
-
"original"
|
|
8330
|
-
]),
|
|
8331
|
-
decimals: z5.number().int().min(0).max(10).optional(),
|
|
8332
|
-
targetAttributeType: z5.string().optional(),
|
|
8333
|
-
targetAttributeOptions: z5.array(
|
|
8334
|
-
z5.object({
|
|
8335
|
-
id: z5.string(),
|
|
8336
|
-
label: z5.string(),
|
|
8337
|
-
value: z5.string(),
|
|
8338
|
-
color: z5.string().optional(),
|
|
8339
|
-
icon: z5.string().optional(),
|
|
8340
|
-
description: z5.string().optional(),
|
|
8341
|
-
group: z5.enum(["idle", "in_progress", "finished"]).optional()
|
|
8342
|
-
})
|
|
8343
|
-
).optional()
|
|
8344
|
-
});
|
|
8345
|
-
var documentConfigSchema = baseConfigSchema.extend({
|
|
8346
|
-
templateId: z5.string().optional(),
|
|
8347
|
-
allowedTemplates: z5.array(z5.string()).optional(),
|
|
8348
|
-
multiple: z5.boolean().optional(),
|
|
8349
|
-
maxDocuments: z5.number().int().min(1).optional(),
|
|
8350
|
-
autoProcess: z5.boolean().optional()
|
|
8351
|
-
});
|
|
8352
|
-
var attributeConfigSchemas = {
|
|
8353
|
-
text: textConfigSchema,
|
|
8354
|
-
textarea: textareaConfigSchema,
|
|
8355
|
-
richtext: richtextConfigSchema,
|
|
8356
|
-
number: numberConfigSchema,
|
|
8357
|
-
checkbox: checkboxConfigSchema,
|
|
8358
|
-
date: dateConfigSchema,
|
|
8359
|
-
phone: phoneConfigSchema,
|
|
8360
|
-
currency: currencyConfigSchema,
|
|
8361
|
-
status: statusConfigSchema,
|
|
8362
|
-
location: locationConfigSchema,
|
|
8363
|
-
select: selectConfigSchema,
|
|
8364
|
-
multiselect: multiselectConfigSchema,
|
|
8365
|
-
file: fileConfigSchema,
|
|
8366
|
-
user: userConfigSchema,
|
|
8367
|
-
relation: relationConfigSchema,
|
|
8368
|
-
rating: ratingConfigSchema,
|
|
8369
|
-
formula: formulaConfigSchema,
|
|
8370
|
-
rollup: rollupConfigSchema,
|
|
8371
|
-
document: documentConfigSchema
|
|
8372
|
-
};
|
|
8373
|
-
function getAttributeConfigSchema(type) {
|
|
8374
|
-
return attributeConfigSchemas[type];
|
|
8375
|
-
}
|
|
8376
|
-
function validateAttributeConfig(type, config) {
|
|
8377
|
-
const schema = getAttributeConfigSchema(type);
|
|
8378
|
-
const result = schema.safeParse(config);
|
|
8379
|
-
if (result.success) {
|
|
8380
|
-
return { success: true, data: result.data };
|
|
8381
|
-
}
|
|
8382
|
-
return {
|
|
8383
|
-
success: false,
|
|
8384
|
-
errors: result.error.issues.map((err) => `${err.path.join(".")}: ${err.message}`)
|
|
8385
|
-
};
|
|
8386
|
-
}
|
|
8387
|
-
function parseAttributeConfig(type, config) {
|
|
8388
|
-
const schema = getAttributeConfigSchema(type);
|
|
8389
|
-
return schema.strip().parse(config);
|
|
8390
|
-
}
|
|
8391
|
-
function safeParseAttributeConfig(type, config) {
|
|
8392
|
-
const schema = getAttributeConfigSchema(type);
|
|
8393
|
-
const result = schema.strip().safeParse(config);
|
|
8394
|
-
return result.success ? result.data : void 0;
|
|
8395
|
-
}
|
|
8396
|
-
function createTextValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8397
|
-
let schema = z5.string();
|
|
8398
|
-
if (attr.minLength !== void 0) {
|
|
8399
|
-
schema = schema.min(attr.minLength, messages.minLength(attr, attr.minLength));
|
|
8400
|
-
}
|
|
8401
|
-
if (attr.maxLength !== void 0) {
|
|
8402
|
-
schema = schema.max(attr.maxLength, messages.maxLength(attr, attr.maxLength));
|
|
8403
|
-
}
|
|
8404
|
-
if (attr.pattern) {
|
|
8405
|
-
schema = schema.regex(getCachedRegex(attr.pattern), messages.invalidPattern(attr));
|
|
8406
|
-
}
|
|
8407
|
-
return schema;
|
|
8408
|
-
}
|
|
8409
|
-
function createNumberValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8410
|
-
let schema = z5.number();
|
|
8411
|
-
if (attr.min !== void 0) {
|
|
8412
|
-
schema = schema.min(attr.min, messages.minValue(attr, attr.min));
|
|
8413
|
-
}
|
|
8414
|
-
if (attr.max !== void 0) {
|
|
8415
|
-
schema = schema.max(attr.max, messages.maxValue(attr, attr.max));
|
|
8416
|
-
}
|
|
8417
|
-
if (attr.unit === "integer") {
|
|
8418
|
-
schema = schema.int(messages.mustBeInteger(attr));
|
|
8419
|
-
}
|
|
8420
|
-
return schema;
|
|
8421
|
-
}
|
|
8422
|
-
function createCheckboxValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8423
|
-
return z5.boolean();
|
|
8424
|
-
}
|
|
8425
|
-
function createDateValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8426
|
-
return z5.coerce.date({ message: messages.invalidDate(attr) });
|
|
8427
|
-
}
|
|
8428
|
-
function createPhoneValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8429
|
-
return z5.object(
|
|
8430
|
-
{
|
|
8431
|
-
countryCode: z5.string().length(3),
|
|
8432
|
-
phoneNumber: z5.string().min(1)
|
|
8433
|
-
},
|
|
8434
|
-
{ message: messages.invalidPhone(attr) }
|
|
8435
|
-
);
|
|
8436
|
-
}
|
|
8437
|
-
function createCurrencyValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8438
|
-
return z5.object(
|
|
8439
|
-
{
|
|
8440
|
-
code: z5.string().length(3),
|
|
8441
|
-
value: z5.number().min(0)
|
|
8442
|
-
},
|
|
8443
|
-
{ message: messages.invalidCurrency(attr) }
|
|
8444
|
-
);
|
|
8445
|
-
}
|
|
8446
|
-
function createStatusValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8447
|
-
const validValues = attr.options.map((opt) => opt.value);
|
|
8448
|
-
return z5.enum(validValues, {
|
|
8449
|
-
message: messages.invalidOption(attr, validValues)
|
|
8450
|
-
});
|
|
8451
|
-
}
|
|
8452
|
-
function createSelectValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8453
|
-
const validValues = attr.options.map((opt) => opt.value);
|
|
8454
|
-
return z5.enum(validValues, {
|
|
8455
|
-
message: messages.invalidOption(attr, validValues)
|
|
8456
|
-
});
|
|
8457
|
-
}
|
|
8458
|
-
function createMultiselectValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8459
|
-
const validValues = attr.options.map((opt) => opt.value);
|
|
8460
|
-
return z5.array(
|
|
8461
|
-
z5.enum(validValues, {
|
|
8462
|
-
message: messages.invalidOption(attr, validValues)
|
|
8463
|
-
})
|
|
8464
|
-
);
|
|
8465
|
-
}
|
|
8466
|
-
function createLocationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8467
|
-
return z5.object(
|
|
8468
|
-
{
|
|
8469
|
-
address: z5.string().optional(),
|
|
8470
|
-
address2: z5.string().optional(),
|
|
8471
|
-
city: z5.string().optional(),
|
|
8472
|
-
state: z5.string().optional(),
|
|
8473
|
-
postalCode: z5.string().optional(),
|
|
8474
|
-
country: z5.string().length(3).optional(),
|
|
8475
|
-
latitude: z5.number().optional(),
|
|
8476
|
-
longitude: z5.number().optional()
|
|
8477
|
-
},
|
|
8478
|
-
{ message: messages.invalidLocation(attr) }
|
|
8479
|
-
);
|
|
8480
|
-
}
|
|
8481
|
-
function createFileValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8482
|
-
const uuidSchema = z5.uuid({
|
|
8483
|
-
message: messages.invalidId(attr)
|
|
8484
|
-
});
|
|
8485
|
-
if (attr.multiple) {
|
|
8486
|
-
let arraySchema = z5.array(uuidSchema);
|
|
8487
|
-
if (attr.maxFiles) {
|
|
8488
|
-
arraySchema = arraySchema.max(attr.maxFiles, messages.maxItems(attr, attr.maxFiles));
|
|
8489
|
-
}
|
|
8490
|
-
return arraySchema;
|
|
8491
|
-
}
|
|
8492
|
-
return uuidSchema;
|
|
8493
|
-
}
|
|
8494
|
-
function createUserValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8495
|
-
const uuidSchema = z5.uuid({
|
|
8496
|
-
message: messages.invalidId(attr)
|
|
8497
|
-
});
|
|
8498
|
-
if (attr.multiple) {
|
|
8499
|
-
return z5.array(uuidSchema);
|
|
8500
|
-
}
|
|
8501
|
-
return uuidSchema;
|
|
8502
|
-
}
|
|
8503
|
-
function createSingleRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8504
|
-
const uuidSchema = z5.uuid({
|
|
8505
|
-
message: messages.invalidId(attr)
|
|
8506
|
-
});
|
|
8507
|
-
return z5.union([uuidSchema, z5.null()]);
|
|
8508
|
-
}
|
|
8509
|
-
function createMultiRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8510
|
-
const uuidSchema = z5.uuid({
|
|
8511
|
-
message: messages.invalidId(attr)
|
|
8512
|
-
});
|
|
8513
|
-
let arraySchema = z5.array(uuidSchema);
|
|
8514
|
-
if (attr.minItems !== void 0) {
|
|
8515
|
-
arraySchema = arraySchema.min(attr.minItems, messages.minItems(attr, attr.minItems));
|
|
8516
|
-
}
|
|
8517
|
-
if (attr.maxItems !== void 0) {
|
|
8518
|
-
arraySchema = arraySchema.max(attr.maxItems, messages.maxItems(attr, attr.maxItems));
|
|
8519
|
-
}
|
|
8520
|
-
return arraySchema;
|
|
8521
|
-
}
|
|
8522
|
-
function createRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8523
|
-
if (attr.cardinality === "many") {
|
|
8524
|
-
return createMultiRelationValidator(attr, messages);
|
|
8525
|
-
}
|
|
8526
|
-
return createSingleRelationValidator(attr, messages);
|
|
8527
|
-
}
|
|
8528
|
-
function createRatingValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8529
|
-
let schema = z5.number().min(0);
|
|
8530
|
-
if (attr.max !== void 0) {
|
|
8531
|
-
schema = schema.max(attr.max, messages.maxValue(attr, attr.max));
|
|
8532
|
-
}
|
|
8533
|
-
return schema;
|
|
8534
|
-
}
|
|
8535
|
-
function createFormulaValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8536
|
-
return z5.unknown();
|
|
8537
|
-
}
|
|
8538
|
-
function createRollupValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8539
|
-
return z5.unknown();
|
|
8540
|
-
}
|
|
8541
|
-
function createTextAreaValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8542
|
-
return z5.string();
|
|
8543
|
-
}
|
|
8544
|
-
function createRichtextValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8545
|
-
return z5.string({
|
|
8546
|
-
message: messages.invalidRichtext(attr)
|
|
8547
|
-
});
|
|
8548
|
-
}
|
|
8549
|
-
function createAttributeValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8550
|
-
switch (attr.type) {
|
|
8551
|
-
case "text":
|
|
8552
|
-
return createTextValidator(attr, messages);
|
|
8553
|
-
case "textarea":
|
|
8554
|
-
return createTextAreaValidator(attr, messages);
|
|
8555
|
-
case "richtext":
|
|
8556
|
-
return createRichtextValidator(attr, messages);
|
|
8557
|
-
case "number":
|
|
8558
|
-
return createNumberValidator(attr, messages);
|
|
8559
|
-
case "checkbox":
|
|
8560
|
-
return createCheckboxValidator(attr, messages);
|
|
8561
|
-
case "date":
|
|
8562
|
-
return createDateValidator(attr, messages);
|
|
8563
|
-
case "phone":
|
|
8564
|
-
return createPhoneValidator(attr, messages);
|
|
8565
|
-
case "currency":
|
|
8566
|
-
return createCurrencyValidator(attr, messages);
|
|
8567
|
-
case "status":
|
|
8568
|
-
return createStatusValidator(attr, messages);
|
|
8569
|
-
case "location":
|
|
8570
|
-
return createLocationValidator(attr, messages);
|
|
8571
|
-
case "select":
|
|
8572
|
-
return createSelectValidator(attr, messages);
|
|
8573
|
-
case "multiselect":
|
|
8574
|
-
return createMultiselectValidator(attr, messages);
|
|
8575
|
-
case "file":
|
|
8576
|
-
return createFileValidator(attr, messages);
|
|
8577
|
-
case "user":
|
|
8578
|
-
return createUserValidator(attr, messages);
|
|
8579
|
-
case "relation":
|
|
8580
|
-
return createRelationValidator(attr, messages);
|
|
8581
|
-
case "rating":
|
|
8582
|
-
return createRatingValidator(attr, messages);
|
|
8583
|
-
case "formula":
|
|
8584
|
-
return createFormulaValidator(attr, messages);
|
|
8585
|
-
case "rollup":
|
|
8586
|
-
return createRollupValidator(attr, messages);
|
|
8587
|
-
default:
|
|
8588
|
-
return z5.unknown();
|
|
8589
|
-
}
|
|
8590
|
-
}
|
|
8591
|
-
function isEmptyValue(value) {
|
|
8592
|
-
if (value === null || value === void 0) return true;
|
|
8593
|
-
if (typeof value === "string" && value.trim() === "") return true;
|
|
8594
|
-
if (value instanceof Date) return false;
|
|
8595
|
-
if (typeof value === "object" && !Array.isArray(value)) {
|
|
8596
|
-
return Object.values(value).every(
|
|
8597
|
-
(v) => v === null || v === void 0 || typeof v === "string" && v.trim() === ""
|
|
8598
|
-
);
|
|
8599
|
-
}
|
|
8600
|
-
return false;
|
|
8601
|
-
}
|
|
8602
|
-
function withEmptyToNull(validator) {
|
|
8603
|
-
return z5.preprocess((val) => isEmptyValue(val) ? null : val, validator.nullish());
|
|
8604
|
-
}
|
|
8605
|
-
function createFormAttributeValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
8606
|
-
const validator = createAttributeValidator(attr, messages);
|
|
8607
|
-
if (!attr.required) {
|
|
8608
|
-
return withEmptyToNull(validator);
|
|
8609
|
-
}
|
|
8610
|
-
return validator;
|
|
8611
|
-
}
|
|
8612
|
-
function createObjectValidator(objectDef) {
|
|
8613
|
-
const shape = {};
|
|
8614
|
-
for (const attr of objectDef.attributes) {
|
|
8615
|
-
const validator = createAttributeValidator(attr);
|
|
8616
|
-
shape[attr.name] = attr.required ? validator : withEmptyToNull(validator);
|
|
8617
|
-
}
|
|
8618
|
-
return z5.object(shape).passthrough();
|
|
8619
|
-
}
|
|
8620
|
-
function validateAttribute(attr, value) {
|
|
8621
|
-
const validator = createAttributeValidator(attr);
|
|
8622
|
-
if (!attr.required && (value === void 0 || value === null)) {
|
|
8623
|
-
return { success: true, data: { [attr.name]: value } };
|
|
8624
|
-
}
|
|
8625
|
-
const result = validator.safeParse(value);
|
|
8626
|
-
if (result.success) {
|
|
8627
|
-
return {
|
|
8628
|
-
success: true,
|
|
8629
|
-
data: { [attr.name]: result.data }
|
|
8630
|
-
};
|
|
8631
|
-
}
|
|
8632
|
-
return {
|
|
8633
|
-
success: false,
|
|
8634
|
-
errors: result.error.issues.map((err) => ({
|
|
8635
|
-
path: [attr.name, ...err.path.map(String)],
|
|
8636
|
-
message: err.message
|
|
8637
|
-
}))
|
|
8638
|
-
};
|
|
8639
|
-
}
|
|
8640
|
-
function validateObject(objectDef, data) {
|
|
8641
|
-
const validator = createObjectValidator(objectDef);
|
|
8642
|
-
const result = validator.safeParse(data);
|
|
8643
|
-
if (result.success) {
|
|
8644
|
-
return {
|
|
8645
|
-
success: true,
|
|
8646
|
-
data: result.data
|
|
8647
|
-
};
|
|
8648
|
-
}
|
|
8649
|
-
return {
|
|
8650
|
-
success: false,
|
|
8651
|
-
errors: result.error.issues.map((err) => ({
|
|
8652
|
-
path: err.path.map(String),
|
|
8653
|
-
message: err.message
|
|
8654
|
-
}))
|
|
8655
|
-
};
|
|
8656
|
-
}
|
|
8657
|
-
function validateObjectOrThrow(objectDef, data) {
|
|
8658
|
-
const result = validateObject(objectDef, data);
|
|
8659
|
-
if (!result.success) {
|
|
8660
|
-
const errorMessages = result.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
8661
|
-
throw new Error(`Validation failed for ${objectDef.label}:
|
|
8662
|
-
${errorMessages}`);
|
|
8663
|
-
}
|
|
8664
|
-
return result.data;
|
|
8665
|
-
}
|
|
8666
|
-
function createDraftValidator(objectDef) {
|
|
8667
|
-
const shape = {};
|
|
8668
|
-
for (const attr of objectDef.attributes) {
|
|
8669
|
-
const validator = createAttributeValidator(attr);
|
|
8670
|
-
shape[attr.name] = withEmptyToNull(validator);
|
|
8671
|
-
}
|
|
8672
|
-
return z5.object(shape).passthrough();
|
|
8673
|
-
}
|
|
8674
|
-
function validateDraft(objectDef, data) {
|
|
8675
|
-
const validator = createDraftValidator(objectDef);
|
|
8676
|
-
const result = validator.safeParse(data);
|
|
8677
|
-
if (result.success) {
|
|
8678
|
-
return {
|
|
8679
|
-
success: true,
|
|
8680
|
-
data: result.data
|
|
8681
|
-
};
|
|
8682
|
-
}
|
|
8683
|
-
return {
|
|
8684
|
-
success: false,
|
|
8685
|
-
errors: result.error.issues.map((err) => ({
|
|
8686
|
-
path: err.path.map(String),
|
|
8687
|
-
message: err.message
|
|
8688
|
-
}))
|
|
8689
|
-
};
|
|
8690
|
-
}
|
|
8691
|
-
function validateDraftOrThrow(objectDef, data) {
|
|
8692
|
-
const result = validateDraft(objectDef, data);
|
|
8693
|
-
if (!result.success) {
|
|
8694
|
-
const errorMessages = result.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
8695
|
-
throw new Error(`Draft validation failed for ${objectDef.label}:
|
|
8696
|
-
${errorMessages}`);
|
|
8697
|
-
}
|
|
8698
|
-
return result.data;
|
|
8699
|
-
}
|
|
8700
|
-
function isValuePresent(value) {
|
|
8701
|
-
if (value === void 0 || value === null) {
|
|
8702
|
-
return false;
|
|
8703
|
-
}
|
|
8704
|
-
if (typeof value === "string" && value.trim() === "") {
|
|
8705
|
-
return false;
|
|
8706
|
-
}
|
|
8707
|
-
return true;
|
|
8708
|
-
}
|
|
8709
|
-
function getMissingRequiredAttributes(objectDef, data) {
|
|
8710
|
-
const missing = [];
|
|
8711
|
-
for (const attr of objectDef.attributes) {
|
|
8712
|
-
if (attr.required && !isValuePresent(data[attr.name])) {
|
|
8713
|
-
missing.push(attr);
|
|
8714
|
-
}
|
|
8715
|
-
}
|
|
8716
|
-
return missing;
|
|
8717
|
-
}
|
|
8718
|
-
function isRecordComplete(objectDef, data) {
|
|
8719
|
-
const missing = getMissingRequiredAttributes(objectDef, data);
|
|
8720
|
-
if (missing.length > 0) {
|
|
8721
|
-
return false;
|
|
8722
|
-
}
|
|
8723
|
-
const validation = validateObject(objectDef, data);
|
|
8724
|
-
return validation.success;
|
|
8725
|
-
}
|
|
8726
|
-
function computeRecordStatus(objectDef, data) {
|
|
8727
|
-
return isRecordComplete(objectDef, data) ? "complete" : "draft";
|
|
8728
|
-
}
|
|
8729
|
-
|
|
8730
8142
|
// src/runtime/services/audit/helpers.ts
|
|
8731
8143
|
function buildAuditChanges(oldValues, newValues, fieldsToCheck) {
|
|
8732
8144
|
const changes = [];
|
|
@@ -10238,7 +9650,7 @@ async function preloadSchemas(records, schemaService) {
|
|
|
10238
9650
|
if (records.length === 0) {
|
|
10239
9651
|
return schemasByObjectId;
|
|
10240
9652
|
}
|
|
10241
|
-
const uniqueObjectIds = [...
|
|
9653
|
+
const uniqueObjectIds = [...records.reduce((set, r) => set.add(r.objectId), /* @__PURE__ */ new Set())];
|
|
10242
9654
|
await Promise.all(
|
|
10243
9655
|
uniqueObjectIds.map(async (objId) => {
|
|
10244
9656
|
const schema = await schemaService.getObjectSchema(objId);
|
|
@@ -10885,8 +10297,10 @@ var RelationService = class extends BaseService {
|
|
|
10885
10297
|
const [attributeId, recordId] = c.split(":");
|
|
10886
10298
|
return { compositeId: c, attributeId, recordId };
|
|
10887
10299
|
});
|
|
10888
|
-
const uniqueRecordIds = [...
|
|
10889
|
-
const uniqueAttributeIds = [
|
|
10300
|
+
const uniqueRecordIds = [...parsed.reduce((set, p) => set.add(p.recordId), /* @__PURE__ */ new Set())];
|
|
10301
|
+
const uniqueAttributeIds = [
|
|
10302
|
+
...parsed.reduce((set, p) => set.add(p.attributeId), /* @__PURE__ */ new Set())
|
|
10303
|
+
];
|
|
10890
10304
|
const records = await this.recordResolver.findByIds(uniqueRecordIds);
|
|
10891
10305
|
if (records.length === 0) {
|
|
10892
10306
|
return [];
|
|
@@ -10895,7 +10309,7 @@ var RelationService = class extends BaseService {
|
|
|
10895
10309
|
const attributePromises = uniqueAttributeIds.map((id) => this.findAttributeById(id));
|
|
10896
10310
|
const attributes = await Promise.all(attributePromises);
|
|
10897
10311
|
const attributeMap = new Map(uniqueAttributeIds.map((id, i) => [id, attributes[i]]));
|
|
10898
|
-
const uniqueObjectIds = [...
|
|
10312
|
+
const uniqueObjectIds = [...records.reduce((set, r) => set.add(r.objectId), /* @__PURE__ */ new Set())];
|
|
10899
10313
|
const schemaPromises = uniqueObjectIds.map((id) => this.schemaService.getObjectSchema(id));
|
|
10900
10314
|
const schemas = await Promise.all(schemaPromises);
|
|
10901
10315
|
const schemaMap = new Map(uniqueObjectIds.map((id, i) => [id, schemas[i]]));
|
|
@@ -11148,7 +10562,10 @@ var RollupService = class extends BaseService {
|
|
|
11148
10562
|
return values.filter((v) => v != null && v !== "").length;
|
|
11149
10563
|
case "countUniqueValues": {
|
|
11150
10564
|
const nonEmpty = values.filter((v) => v != null && v !== "");
|
|
11151
|
-
return
|
|
10565
|
+
return nonEmpty.reduce(
|
|
10566
|
+
(set, v) => set.add(JSON.stringify(v)),
|
|
10567
|
+
/* @__PURE__ */ new Set()
|
|
10568
|
+
).size;
|
|
11152
10569
|
}
|
|
11153
10570
|
case "countEmpty":
|
|
11154
10571
|
return values.filter((v) => v == null || v === "").length;
|
|
@@ -13987,7 +13404,7 @@ var WorkflowService = class extends BaseService {
|
|
|
13987
13404
|
};
|
|
13988
13405
|
const validationResult = WorkflowDefinitionSchema.safeParse(definition);
|
|
13989
13406
|
if (!validationResult.success) {
|
|
13990
|
-
const errors = validationResult.error.
|
|
13407
|
+
const errors = formatZodErrors(validationResult.error).map((err) => err.message);
|
|
13991
13408
|
throw new SchemaError(
|
|
13992
13409
|
`Invalid workflow definition: ${errors.join(", ")}`,
|
|
13993
13410
|
SchemaErrorCode.VALIDATION_FAILED
|
|
@@ -14029,7 +13446,7 @@ var WorkflowService = class extends BaseService {
|
|
|
14029
13446
|
};
|
|
14030
13447
|
const validationResult = WorkflowDefinitionSchema.safeParse(updated);
|
|
14031
13448
|
if (!validationResult.success) {
|
|
14032
|
-
const errors = validationResult.error.
|
|
13449
|
+
const errors = formatZodErrors(validationResult.error).map((err) => err.message);
|
|
14033
13450
|
throw new SchemaError(
|
|
14034
13451
|
`Invalid workflow definition: ${errors.join(", ")}`,
|
|
14035
13452
|
SchemaErrorCode.VALIDATION_FAILED
|
|
@@ -14058,7 +13475,7 @@ var WorkflowService = class extends BaseService {
|
|
|
14058
13475
|
}
|
|
14059
13476
|
const validationResult = WorkflowDefinitionSchema.safeParse(existing);
|
|
14060
13477
|
if (!validationResult.success) {
|
|
14061
|
-
const errors = validationResult.error.
|
|
13478
|
+
const errors = formatZodErrors(validationResult.error).map((err) => err.message);
|
|
14062
13479
|
throw new SchemaError(
|
|
14063
13480
|
`Cannot publish invalid workflow: ${errors.join(", ")}`,
|
|
14064
13481
|
SchemaErrorCode.VALIDATION_FAILED
|
|
@@ -15143,7 +14560,7 @@ var DocumentService = class extends BaseService {
|
|
|
15143
14560
|
const template = await this.templateService.getTemplateOrThrow(document2.templateId);
|
|
15144
14561
|
const slots = await this.getSlots(documentId);
|
|
15145
14562
|
const requiredSlots = template.slots.filter((s) => s.required);
|
|
15146
|
-
const filledSlotNames =
|
|
14563
|
+
const filledSlotNames = slots.reduce((set, s) => set.add(s.slotName), /* @__PURE__ */ new Set());
|
|
15147
14564
|
const allRequiredFilled = requiredSlots.every((s) => filledSlotNames.has(s.name));
|
|
15148
14565
|
if (!allRequiredFilled) {
|
|
15149
14566
|
return await this.updateStatus(documentId, "draft");
|
|
@@ -16717,7 +16134,7 @@ var PermissionService = class extends BaseService {
|
|
|
16717
16134
|
DEFAULT_ROLE_PERMISSIONS
|
|
16718
16135
|
} = await import("./default-roles-42X3TJI5.mjs");
|
|
16719
16136
|
const existingRoles = await this.getRoles();
|
|
16720
|
-
const existingRoleNames =
|
|
16137
|
+
const existingRoleNames = existingRoles.reduce((set, r) => set.add(r.name), /* @__PURE__ */ new Set());
|
|
16721
16138
|
for (const roleName of Object.values(DEFAULT_ROLES)) {
|
|
16722
16139
|
if (existingRoleNames.has(roleName)) {
|
|
16723
16140
|
continue;
|
|
@@ -17211,7 +16628,7 @@ var ViewService = class extends BaseService {
|
|
|
17211
16628
|
*/
|
|
17212
16629
|
async hasUserCustomizations(viewId, userId) {
|
|
17213
16630
|
const overlay = await this.adapter.viewOverlays.findByViewAndUser(viewId, userId);
|
|
17214
|
-
return overlay !== null &&
|
|
16631
|
+
return overlay !== null && hasProperties(overlay.configOverrides);
|
|
17215
16632
|
}
|
|
17216
16633
|
// ============================================================================
|
|
17217
16634
|
// OVERLAY MERGE LOGIC
|
|
@@ -17586,8 +17003,9 @@ async function handleDryRun(adapter, nativeObject, existingObject, result, optio
|
|
|
17586
17003
|
if (options.verbose) {
|
|
17587
17004
|
console.info(`[SyncService] Would ${isNew ? "create" : "update"} object: ${nativeObject.name}`);
|
|
17588
17005
|
}
|
|
17006
|
+
const existingAttrs = existingObject ? await adapter.attributes.findByObjectId(existingObject.id) : [];
|
|
17589
17007
|
for (const attr of nativeObject.attributes) {
|
|
17590
|
-
const existingAttr =
|
|
17008
|
+
const existingAttr = existingAttrs.find((a) => a.name === attr.name) ?? null;
|
|
17591
17009
|
if (existingAttr) {
|
|
17592
17010
|
result.attributesUpdated++;
|
|
17593
17011
|
} else {
|
|
@@ -17609,8 +17027,9 @@ async function upsertObject(adapter, nativeObject, _options) {
|
|
|
17609
17027
|
});
|
|
17610
17028
|
}
|
|
17611
17029
|
async function syncAttributes(adapter, nativeObject, dbObject, existingObject, result) {
|
|
17030
|
+
const existingAttrs = existingObject ? await adapter.attributes.findByObjectId(dbObject.id) : [];
|
|
17612
17031
|
for (const [index, attr] of nativeObject.attributes.entries()) {
|
|
17613
|
-
const existingAttr =
|
|
17032
|
+
const existingAttr = existingAttrs.find((a) => a.name === attr.name) ?? null;
|
|
17614
17033
|
await adapter.attributes.upsert({
|
|
17615
17034
|
objectId: dbObject.id,
|
|
17616
17035
|
name: attr.name,
|
|
@@ -17704,8 +17123,6 @@ export {
|
|
|
17704
17123
|
isIdentityProperty,
|
|
17705
17124
|
isBehaviorProperty,
|
|
17706
17125
|
isPresentationProperty,
|
|
17707
|
-
getPropertyProtectionLevel,
|
|
17708
|
-
filterPropertiesByCategory,
|
|
17709
17126
|
RELATION_TARGET_ANY,
|
|
17710
17127
|
isUniversalRelation,
|
|
17711
17128
|
RecordReferencedError,
|
|
@@ -17734,8 +17151,6 @@ export {
|
|
|
17734
17151
|
and,
|
|
17735
17152
|
or,
|
|
17736
17153
|
inValues,
|
|
17737
|
-
isEmpty,
|
|
17738
|
-
isNotEmpty,
|
|
17739
17154
|
isWorkflowDefinition,
|
|
17740
17155
|
isWorkflowPublished,
|
|
17741
17156
|
isSystemWorkflow,
|
|
@@ -17754,7 +17169,6 @@ export {
|
|
|
17754
17169
|
createEmptyContext,
|
|
17755
17170
|
getContextValue,
|
|
17756
17171
|
setContextValue,
|
|
17757
|
-
mergeFormToSlot,
|
|
17758
17172
|
DEFAULT_THEME,
|
|
17759
17173
|
mergeWithDefaults,
|
|
17760
17174
|
generateCssVariables,
|
|
@@ -17788,12 +17202,10 @@ export {
|
|
|
17788
17202
|
WorkflowConfigSchema,
|
|
17789
17203
|
WorkflowStatusSchema,
|
|
17790
17204
|
WorkflowDefinitionSchema,
|
|
17791
|
-
|
|
17792
|
-
|
|
17793
|
-
|
|
17794
|
-
|
|
17795
|
-
slugify,
|
|
17796
|
-
generateTemplateName,
|
|
17205
|
+
isEmpty,
|
|
17206
|
+
isNotEmpty,
|
|
17207
|
+
toUndefinedIfEmpty,
|
|
17208
|
+
hasProperties,
|
|
17797
17209
|
EMPTY_VALUE_PLACEHOLDER,
|
|
17798
17210
|
formatAttributeValue,
|
|
17799
17211
|
SchemaErrorCode,
|
|
@@ -17818,7 +17230,6 @@ export {
|
|
|
17818
17230
|
RoleNotFoundError,
|
|
17819
17231
|
isForbiddenError,
|
|
17820
17232
|
ConcurrentModificationError,
|
|
17821
|
-
isConcurrentModificationError,
|
|
17822
17233
|
text,
|
|
17823
17234
|
textarea,
|
|
17824
17235
|
richtext,
|
|
@@ -17876,63 +17287,6 @@ export {
|
|
|
17876
17287
|
SYSTEM_TEMPLATES,
|
|
17877
17288
|
getSystemTemplate,
|
|
17878
17289
|
isSystemTemplate,
|
|
17879
|
-
DEFAULT_VALIDATION_MESSAGES,
|
|
17880
|
-
textConfigSchema,
|
|
17881
|
-
textareaConfigSchema,
|
|
17882
|
-
richtextConfigSchema,
|
|
17883
|
-
numberConfigSchema,
|
|
17884
|
-
checkboxConfigSchema,
|
|
17885
|
-
dateConfigSchema,
|
|
17886
|
-
phoneConfigSchema,
|
|
17887
|
-
currencyConfigSchema,
|
|
17888
|
-
statusConfigSchema,
|
|
17889
|
-
locationConfigSchema,
|
|
17890
|
-
selectConfigSchema,
|
|
17891
|
-
multiselectConfigSchema,
|
|
17892
|
-
fileConfigSchema,
|
|
17893
|
-
userConfigSchema,
|
|
17894
|
-
relationConfigSchema,
|
|
17895
|
-
ratingConfigSchema,
|
|
17896
|
-
formulaConfigSchema,
|
|
17897
|
-
rollupConfigSchema,
|
|
17898
|
-
documentConfigSchema,
|
|
17899
|
-
attributeConfigSchemas,
|
|
17900
|
-
getAttributeConfigSchema,
|
|
17901
|
-
validateAttributeConfig,
|
|
17902
|
-
parseAttributeConfig,
|
|
17903
|
-
safeParseAttributeConfig,
|
|
17904
|
-
createTextValidator,
|
|
17905
|
-
createNumberValidator,
|
|
17906
|
-
createCheckboxValidator,
|
|
17907
|
-
createDateValidator,
|
|
17908
|
-
createPhoneValidator,
|
|
17909
|
-
createCurrencyValidator,
|
|
17910
|
-
createStatusValidator,
|
|
17911
|
-
createSelectValidator,
|
|
17912
|
-
createMultiselectValidator,
|
|
17913
|
-
createLocationValidator,
|
|
17914
|
-
createFileValidator,
|
|
17915
|
-
createUserValidator,
|
|
17916
|
-
createSingleRelationValidator,
|
|
17917
|
-
createMultiRelationValidator,
|
|
17918
|
-
createRelationValidator,
|
|
17919
|
-
createRatingValidator,
|
|
17920
|
-
createFormulaValidator,
|
|
17921
|
-
createRollupValidator,
|
|
17922
|
-
createTextAreaValidator,
|
|
17923
|
-
createRichtextValidator,
|
|
17924
|
-
createAttributeValidator,
|
|
17925
|
-
createFormAttributeValidator,
|
|
17926
|
-
createObjectValidator,
|
|
17927
|
-
validateAttribute,
|
|
17928
|
-
validateObject,
|
|
17929
|
-
validateObjectOrThrow,
|
|
17930
|
-
createDraftValidator,
|
|
17931
|
-
validateDraft,
|
|
17932
|
-
validateDraftOrThrow,
|
|
17933
|
-
getMissingRequiredAttributes,
|
|
17934
|
-
isRecordComplete,
|
|
17935
|
-
computeRecordStatus,
|
|
17936
17290
|
WorkflowJwtService,
|
|
17937
17291
|
hashOptions,
|
|
17938
17292
|
cacheKeys,
|