kosmio 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/dist/KosmioThemeProvider-DzH5uTqT.js +145 -0
- package/dist/LanguageContext-DlN7MgUs.js +161 -0
- package/dist/MobileRouteTransition-C16D4K5c.js +124 -0
- package/dist/NativeBackButtonHandler-CcLHewdm.js +105 -0
- package/dist/OfflineSyncContext-CRwPM5kh.js +34 -0
- package/dist/ViewportContext-z-ZwlTIZ.js +214 -0
- package/dist/app.js +123 -0
- package/dist/classNames-CcykAxZN.js +6 -0
- package/dist/context.js +16 -0
- package/dist/core.js +55 -0
- package/dist/formRegistry-Lvs6aL14.js +3468 -0
- package/dist/i18n.js +9 -0
- package/dist/index.js +185 -0
- package/dist/localizedRouter-BjT5yIzl.js +721 -0
- package/dist/offlineWriteQueue-C31IjyB_.js +275 -0
- package/dist/permissions.js +181 -0
- package/dist/platform.js +11 -0
- package/dist/queryClient-ZtNrT-lA.js +27 -0
- package/dist/shortcuts-n31uRPcv.js +147 -0
- package/dist/styles.css +1 -0
- package/dist/styles.js +1 -0
- package/dist/systemBars-C3QiEL7z.js +136 -0
- package/dist/theme.js +8 -0
- package/dist/ui.js +88 -0
- package/package.json +84 -0
- package/types/app.d.ts +98 -0
- package/types/context.d.ts +110 -0
- package/types/core.d.ts +210 -0
- package/types/global.d.ts +1 -0
- package/types/i18n.d.ts +79 -0
- package/types/index.d.ts +8 -0
- package/types/permissions.d.ts +61 -0
- package/types/platform.d.ts +71 -0
- package/types/theme.d.ts +67 -0
- package/types/ui.d.ts +875 -0
|
@@ -0,0 +1,721 @@
|
|
|
1
|
+
import { useQueryClient as ce, useMutation as de, useQuery as fe } from "@tanstack/react-query";
|
|
2
|
+
import { b as pe, r as me, f as ye, e as v, s as he } from "./offlineWriteQueue-C31IjyB_.js";
|
|
3
|
+
import be from "axios";
|
|
4
|
+
function W(e, t, r) {
|
|
5
|
+
return function(n, a, p) {
|
|
6
|
+
return fe({
|
|
7
|
+
queryKey: r(n, a),
|
|
8
|
+
queryFn: () => e.call(t, { pathParams: a, data: n }),
|
|
9
|
+
enabled: p?.enabled ?? !0,
|
|
10
|
+
...p
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function F(e, t, { afterSuccess: r } = {}) {
|
|
15
|
+
return function() {
|
|
16
|
+
const n = ce();
|
|
17
|
+
return de({
|
|
18
|
+
mutationFn: ({ req: a, pathParams: p, config: m }) => e.call(t, { pathParams: p, data: a, config: m }),
|
|
19
|
+
onSuccess: (a, p, m) => {
|
|
20
|
+
r && !pe(a) && r(n, a, p, m);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function ge({
|
|
26
|
+
client: e,
|
|
27
|
+
basePath: t,
|
|
28
|
+
resource: r = "resource",
|
|
29
|
+
mapOne: i = (M) => M,
|
|
30
|
+
mapMany: n = (M) => Array.isArray(M) ? M.map(i) : [],
|
|
31
|
+
updateMethod: a = "PUT",
|
|
32
|
+
makeKeys: p,
|
|
33
|
+
asOptions: m = !1,
|
|
34
|
+
listAdapter: s,
|
|
35
|
+
detailAdapter: l
|
|
36
|
+
}) {
|
|
37
|
+
if (!e) throw new Error("client required");
|
|
38
|
+
if (!t) throw new Error("basePath required");
|
|
39
|
+
const M = (o) => o?.toOption ? o.toOption() : { value: o?.id ?? "", label: o?.name ?? "" }, A = m ? (o) => Array.isArray(o) ? o.map(M) : [] : typeof s == "function" ? s : (o) => Array.isArray(o) ? o : [], O = m ? (o) => o == null ? o : M(o) : typeof l == "function" ? l : (o) => o, u = {
|
|
40
|
+
list: { method: "GET", path: `${t}/`, responseMapper: (o) => n(o) },
|
|
41
|
+
create: { method: "POST", path: `${t}/`, responseMapper: (o) => i(o) },
|
|
42
|
+
detail: { method: "GET", path: ({ id: o }) => `${t}/${o}/`, responseMapper: (o) => i(o) },
|
|
43
|
+
update: { method: a, path: ({ id: o }) => `${t}/${o}/`, responseMapper: (o) => i(o) },
|
|
44
|
+
remove: { method: "DELETE", path: ({ id: o }) => `${t}/${o}/` },
|
|
45
|
+
archive: { method: "POST", path: ({ id: o }) => `${t}/${o}/archive/`, responseMapper: (o) => i(o) },
|
|
46
|
+
unarchive: { method: "POST", path: ({ id: o }) => `${t}/${o}/unarchive/`, responseMapper: (o) => i(o) }
|
|
47
|
+
}, d = p || {
|
|
48
|
+
all: () => [r],
|
|
49
|
+
list: (o) => [r, "list", o ?? {}],
|
|
50
|
+
detail: (o) => [r, "detail", o]
|
|
51
|
+
}, b = W(e, u.list, (o) => d.list ? d.list(o) : d.all()), P = W(e, u.detail, (o, E) => d.detail(E?.id));
|
|
52
|
+
function $(o, E, g) {
|
|
53
|
+
const S = b(o, E, g), q = A(S.data);
|
|
54
|
+
return { ...S, data: Array.isArray(q) ? q : [] };
|
|
55
|
+
}
|
|
56
|
+
function w(o, E, g) {
|
|
57
|
+
const S = P(o, E, g);
|
|
58
|
+
return { ...S, data: S.data == null ? S.data : O(S.data) };
|
|
59
|
+
}
|
|
60
|
+
const c = F(e, u.create, {
|
|
61
|
+
afterSuccess: (o) => o.invalidateQueries({ queryKey: d.all() })
|
|
62
|
+
}), j = F(e, u.update, {
|
|
63
|
+
afterSuccess: (o, E, { pathParams: g }) => {
|
|
64
|
+
g?.id && o.invalidateQueries({ queryKey: d.detail(g.id) }), o.invalidateQueries({ queryKey: d.all() });
|
|
65
|
+
}
|
|
66
|
+
}), f = F(e, u.remove, {
|
|
67
|
+
afterSuccess: (o, E, { pathParams: g }) => {
|
|
68
|
+
o.invalidateQueries({ queryKey: d.all() }), g?.id && o.removeQueries({ queryKey: d.detail(g.id) });
|
|
69
|
+
}
|
|
70
|
+
}), y = F(e, u.archive, {
|
|
71
|
+
afterSuccess: (o, E, { pathParams: g }) => {
|
|
72
|
+
o.invalidateQueries({ queryKey: d.all() }), g?.id && o.invalidateQueries({ queryKey: d.detail(g.id) });
|
|
73
|
+
}
|
|
74
|
+
}), h = F(e, u.unarchive, {
|
|
75
|
+
afterSuccess: (o, E, { pathParams: g }) => {
|
|
76
|
+
o.invalidateQueries({ queryKey: d.all() }), g?.id && o.invalidateQueries({ queryKey: d.detail(g.id) });
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return { useList: $, useDetail: w, useCreate: c, useUpdate: j, useDelete: f, useArchive: y, useUnarchive: h, endpoints: u, keys: d };
|
|
80
|
+
}
|
|
81
|
+
const R = Object.freeze({
|
|
82
|
+
STRING: "string",
|
|
83
|
+
NUMBER: "number",
|
|
84
|
+
BOOLEAN: "boolean",
|
|
85
|
+
OBJECT: "object",
|
|
86
|
+
DATE: "date",
|
|
87
|
+
ARRAY: "array",
|
|
88
|
+
STRING_ARRAY: "string[]",
|
|
89
|
+
ENUM: "enum"
|
|
90
|
+
}), te = "__enum_type__";
|
|
91
|
+
function H(e, t) {
|
|
92
|
+
return Object.prototype.hasOwnProperty.call(e, t);
|
|
93
|
+
}
|
|
94
|
+
function Ae(e) {
|
|
95
|
+
return Array.isArray(e) ? [...e] : e && typeof e == "object" ? { ...e } : e;
|
|
96
|
+
}
|
|
97
|
+
function Oe(e) {
|
|
98
|
+
const t = String(e ?? R.STRING).toLowerCase().trim();
|
|
99
|
+
return t === R.ARRAY || t.endsWith("[]") ? [] : t === R.BOOLEAN || t === "bool" ? !1 : ["number", "int", "integer", "float", "decimal"].includes(t) || ["object", "json", "map"].includes(t) ? null : "";
|
|
100
|
+
}
|
|
101
|
+
function Ee(e, t) {
|
|
102
|
+
return Object.freeze({
|
|
103
|
+
kind: te,
|
|
104
|
+
name: String(e ?? "").trim() || null,
|
|
105
|
+
values: Array.isArray(t) ? [...t] : []
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function Me(e) {
|
|
109
|
+
return !!(e && typeof e == "object" && e.kind === te);
|
|
110
|
+
}
|
|
111
|
+
function re(e, t) {
|
|
112
|
+
return Me(e) ? { type: R.ENUM, enum: [...e.values], enumTypeName: e.name } : Array.isArray(e) ? { type: R.ENUM, enum: [...e], enumTypeName: null } : e && typeof e == "object" && Array.isArray(e.values) ? {
|
|
113
|
+
type: R.ENUM,
|
|
114
|
+
enum: [...e.values],
|
|
115
|
+
enumTypeName: e.name ?? null
|
|
116
|
+
} : t && Array.isArray(t) ? { type: R.ENUM, enum: [...t], enumTypeName: null } : {
|
|
117
|
+
type: String(e ?? R.STRING).toLowerCase().trim() || R.STRING,
|
|
118
|
+
enum: Array.isArray(t) ? [...t] : null,
|
|
119
|
+
enumTypeName: null
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function Pe(e, t) {
|
|
123
|
+
return Object.freeze({ group: e, index: t });
|
|
124
|
+
}
|
|
125
|
+
function K(e = {}) {
|
|
126
|
+
const t = e && typeof e == "object" ? e : {}, {
|
|
127
|
+
name: r,
|
|
128
|
+
type: i = R.STRING,
|
|
129
|
+
required: n = !1,
|
|
130
|
+
post: a = !0,
|
|
131
|
+
edit: p = !0,
|
|
132
|
+
formGrouping: m = null,
|
|
133
|
+
default: s,
|
|
134
|
+
...l
|
|
135
|
+
} = t, M = re(i, l.enum), A = H(t, "default") ? Ae(s) : Oe(M.type);
|
|
136
|
+
return Object.freeze({
|
|
137
|
+
name: r,
|
|
138
|
+
type: i,
|
|
139
|
+
required: !!n,
|
|
140
|
+
post: typeof a == "boolean" ? a : !0,
|
|
141
|
+
edit: typeof p == "boolean" ? p : !0,
|
|
142
|
+
formGrouping: m,
|
|
143
|
+
default: A,
|
|
144
|
+
hasExplicitDefault: H(t, "default"),
|
|
145
|
+
...l
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
K.grouping = Pe;
|
|
149
|
+
K.types = R;
|
|
150
|
+
K.enum = Ee;
|
|
151
|
+
function L(e) {
|
|
152
|
+
return String(e ?? "").trim().replace(/[^a-zA-Z0-9]+/g, " ").split(" ").filter(Boolean).map((i) => i.charAt(0).toUpperCase() + i.slice(1)).join("") || "Entity";
|
|
153
|
+
}
|
|
154
|
+
class Ce {
|
|
155
|
+
constructor(t = {}) {
|
|
156
|
+
t && typeof t == "object" && Object.assign(this, t);
|
|
157
|
+
}
|
|
158
|
+
toJSON() {
|
|
159
|
+
return { ...this };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const C = "string";
|
|
163
|
+
function N(e, t) {
|
|
164
|
+
return Object.prototype.hasOwnProperty.call(e, t);
|
|
165
|
+
}
|
|
166
|
+
function ne(e) {
|
|
167
|
+
const t = String(e ?? C).toLowerCase().trim();
|
|
168
|
+
return t === "array" || t.endsWith("[]") ? [] : t === "boolean" || t === "bool" ? !1 : ["number", "int", "integer", "float", "decimal"].includes(t) || ["object", "json", "map"].includes(t) ? null : "";
|
|
169
|
+
}
|
|
170
|
+
function x(e) {
|
|
171
|
+
return Array.isArray(e) ? [...e] : e && typeof e == "object" ? { ...e } : e;
|
|
172
|
+
}
|
|
173
|
+
function ie(e = {}) {
|
|
174
|
+
return N(e, "default") ? x(e.default) : ne(e?.type);
|
|
175
|
+
}
|
|
176
|
+
function J(e, t) {
|
|
177
|
+
const r = {};
|
|
178
|
+
if (!e || typeof e != "object") return r;
|
|
179
|
+
for (const i of t)
|
|
180
|
+
N(e, i) && (r[i] = e[i]);
|
|
181
|
+
return r;
|
|
182
|
+
}
|
|
183
|
+
function we(e, t) {
|
|
184
|
+
const r = {};
|
|
185
|
+
if (!e || typeof e != "object") return r;
|
|
186
|
+
for (const i of t)
|
|
187
|
+
N(e, i) && e[i] !== void 0 && (r[i] = e[i]);
|
|
188
|
+
return r;
|
|
189
|
+
}
|
|
190
|
+
function je(e) {
|
|
191
|
+
return e == null ? !1 : typeof e == "string" ? e.trim() !== "" : Array.isArray(e) ? e.length > 0 : typeof e == "object" ? Object.keys(e).length > 0 : !0;
|
|
192
|
+
}
|
|
193
|
+
function I(e, t) {
|
|
194
|
+
return t.filter((r) => !je(e[r]));
|
|
195
|
+
}
|
|
196
|
+
function Se(e) {
|
|
197
|
+
const t = {};
|
|
198
|
+
for (const [r, i] of Object.entries(e))
|
|
199
|
+
t[r] = ie(i);
|
|
200
|
+
return t;
|
|
201
|
+
}
|
|
202
|
+
function $e(e, t) {
|
|
203
|
+
const r = {};
|
|
204
|
+
for (const i of t)
|
|
205
|
+
N(e, i) && (r[i] = e[i]);
|
|
206
|
+
return r;
|
|
207
|
+
}
|
|
208
|
+
function Re(e, t = {}) {
|
|
209
|
+
const r = String(t?.type ?? C).toLowerCase().trim(), i = ie(t);
|
|
210
|
+
return r === "array" || r.endsWith("[]") ? Array.isArray(e) ? e : e && typeof e == "object" ? Object.values(e) : x(i) : r === "boolean" || r === "bool" ? e == null ? !!i : !!e : ["number", "int", "integer", "float", "decimal"].includes(r) ? e ?? i : ["object", "json", "map"].includes(r) ? e ?? x(i) : e ?? i;
|
|
211
|
+
}
|
|
212
|
+
function qe(e, t) {
|
|
213
|
+
const r = {}, i = e && typeof e == "object" ? e : {};
|
|
214
|
+
for (const [n, a] of Object.entries(t))
|
|
215
|
+
r[n] = Re(i[n], a);
|
|
216
|
+
return r;
|
|
217
|
+
}
|
|
218
|
+
function Fe(e, t) {
|
|
219
|
+
const r = Array.isArray(e) ? e.filter((n) => n && typeof n == "object") : Object.entries(e ?? {}).filter(([, n]) => n && typeof n == "object").map(([n, a]) => ({ name: n, ...a })), i = {};
|
|
220
|
+
for (const n of r) {
|
|
221
|
+
const a = String(n.name ?? "").trim();
|
|
222
|
+
if (!a) continue;
|
|
223
|
+
const p = n?.formGrouping && typeof n.formGrouping == "object" ? n.formGrouping : null, m = typeof n?.post == "boolean" ? n.post : void 0, s = typeof n?.edit == "boolean" ? n.edit : void 0, l = n?.group !== void 0 ? n.group : p?.group, M = n?.index !== void 0 ? n.index : p?.index, {
|
|
224
|
+
name: A,
|
|
225
|
+
type: O,
|
|
226
|
+
default: u,
|
|
227
|
+
editable: d,
|
|
228
|
+
writable: b,
|
|
229
|
+
required: P,
|
|
230
|
+
show: $,
|
|
231
|
+
enum: w,
|
|
232
|
+
post: c,
|
|
233
|
+
edit: j,
|
|
234
|
+
formGrouping: f,
|
|
235
|
+
group: y,
|
|
236
|
+
index: h,
|
|
237
|
+
...o
|
|
238
|
+
} = n, E = re(O, w), g = E.type ?? C;
|
|
239
|
+
i[a] = {
|
|
240
|
+
...o,
|
|
241
|
+
type: g,
|
|
242
|
+
...E.enum ? { enum: E.enum } : {},
|
|
243
|
+
...E.enumTypeName ? { enumTypeName: E.enumTypeName } : {},
|
|
244
|
+
...l !== void 0 ? { group: l } : {},
|
|
245
|
+
...M !== void 0 ? { index: M } : {},
|
|
246
|
+
default: N(n, "default") ? x(u) : ne(g),
|
|
247
|
+
editable: typeof s == "boolean" ? s : typeof d == "boolean" ? d : !!t,
|
|
248
|
+
writable: typeof m == "boolean" ? m : typeof b == "boolean" ? b : !0,
|
|
249
|
+
required: !!P,
|
|
250
|
+
show: typeof $ == "boolean" ? $ : !0
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
return i;
|
|
254
|
+
}
|
|
255
|
+
function T(e, t, r, i) {
|
|
256
|
+
const n = [...new Set(i)], a = $e(r, n), p = n.filter((O) => a[O]?.editable), m = n.filter((O) => a[O]?.writable), s = n.filter((O) => a[O]?.required), l = p.filter((O) => a[O]?.required), M = m.filter((O) => a[O]?.required);
|
|
257
|
+
class A {
|
|
258
|
+
#e = Se(a);
|
|
259
|
+
#t = /* @__PURE__ */ new Set();
|
|
260
|
+
constructor(u = {}) {
|
|
261
|
+
const d = J(u, n);
|
|
262
|
+
Object.assign(this.#e, d);
|
|
263
|
+
for (const b of Object.keys(d)) this.#t.add(b);
|
|
264
|
+
}
|
|
265
|
+
toJSON() {
|
|
266
|
+
return { ...this.#e };
|
|
267
|
+
}
|
|
268
|
+
toAddPayload(u = {}) {
|
|
269
|
+
return u.validateRequired && this.validateRequired("add"), J(this.#e, m);
|
|
270
|
+
}
|
|
271
|
+
toEditPayload(u = {}) {
|
|
272
|
+
return u.validateRequired && this.validateRequired("edit"), we(
|
|
273
|
+
this.#e,
|
|
274
|
+
p.filter((d) => this.#t.has(d))
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
toOption() {
|
|
278
|
+
return {
|
|
279
|
+
value: this.#e.id ?? this.#e.value ?? "",
|
|
280
|
+
label: this.#e.label ?? this.#e.name ?? this.#e.earTag ?? this.#e.id ?? ""
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
static from(u = {}) {
|
|
284
|
+
return new A(u);
|
|
285
|
+
}
|
|
286
|
+
static fromAPI(u = {}) {
|
|
287
|
+
return new A(qe(u, a));
|
|
288
|
+
}
|
|
289
|
+
static getFields() {
|
|
290
|
+
return [...n];
|
|
291
|
+
}
|
|
292
|
+
static getEditableFields() {
|
|
293
|
+
return [...p];
|
|
294
|
+
}
|
|
295
|
+
static getWritableFields() {
|
|
296
|
+
return [...m];
|
|
297
|
+
}
|
|
298
|
+
static getRequiredFields() {
|
|
299
|
+
return [...s];
|
|
300
|
+
}
|
|
301
|
+
getMissingRequiredFields(u = "all") {
|
|
302
|
+
return u === "add" ? I(this.#e, M) : u === "edit" ? I(this.#e, l) : I(this.#e, s);
|
|
303
|
+
}
|
|
304
|
+
hasMissingRequiredFields(u = "all") {
|
|
305
|
+
return this.getMissingRequiredFields(u).length > 0;
|
|
306
|
+
}
|
|
307
|
+
validateRequired(u = "all") {
|
|
308
|
+
const d = this.getMissingRequiredFields(u);
|
|
309
|
+
if (d.length > 0) {
|
|
310
|
+
const b = new Error(`Missing required fields: ${d.join(", ")}`);
|
|
311
|
+
throw b.code = "MODEL_REQUIRED_FIELDS_MISSING", b.mode = u, b.missingFields = d, b;
|
|
312
|
+
}
|
|
313
|
+
return !0;
|
|
314
|
+
}
|
|
315
|
+
static createFieldGetter(u) {
|
|
316
|
+
return function() {
|
|
317
|
+
return this.#e[u];
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
for (const O of n)
|
|
322
|
+
Object.defineProperty(A.prototype, O, {
|
|
323
|
+
get: A.createFieldGetter(O),
|
|
324
|
+
enumerable: !1,
|
|
325
|
+
configurable: !1
|
|
326
|
+
});
|
|
327
|
+
return Object.defineProperties(A, {
|
|
328
|
+
modelName: { value: e, enumerable: !0 },
|
|
329
|
+
variant: { value: t, enumerable: !0 },
|
|
330
|
+
fields: { value: Object.freeze([...n]), enumerable: !0 },
|
|
331
|
+
editableFields: { value: Object.freeze([...p]), enumerable: !0 },
|
|
332
|
+
writableFields: { value: Object.freeze([...m]), enumerable: !0 },
|
|
333
|
+
requiredFields: { value: Object.freeze([...s]), enumerable: !0 }
|
|
334
|
+
}), A;
|
|
335
|
+
}
|
|
336
|
+
function oe(e = {}) {
|
|
337
|
+
if (!e || typeof e != "object")
|
|
338
|
+
throw new TypeError("createEntityModels expects a config object.");
|
|
339
|
+
const t = L(e.name), r = e.editable ?? !0, i = Fe(e.fields ?? e.elements, r), n = Object.keys(i), a = n.filter((l) => i[l].editable), p = n.filter((l) => i[l].writable), m = n.filter((l) => i[l].show), s = Object.freeze({
|
|
340
|
+
name: t,
|
|
341
|
+
editable: !!r,
|
|
342
|
+
fields: Object.freeze({ ...i })
|
|
343
|
+
});
|
|
344
|
+
return {
|
|
345
|
+
[`${t}Model`]: T(t, "absolute", i, n),
|
|
346
|
+
[`${t}EditableModel`]: T(t, "editable", i, a),
|
|
347
|
+
[`${t}ShowableModel`]: T(t, "showable", i, m),
|
|
348
|
+
[`${t}WritableModel`]: T(t, "writable", i, p),
|
|
349
|
+
[`${t}ModelProperties`]: s
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
class Ue {
|
|
353
|
+
static build(t) {
|
|
354
|
+
return oe(t);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function ze(e, t) {
|
|
358
|
+
return Object.prototype.hasOwnProperty.call(e, t);
|
|
359
|
+
}
|
|
360
|
+
function z(e) {
|
|
361
|
+
return Array.isArray(e) ? [...e] : e && typeof e == "object" ? { ...e } : e;
|
|
362
|
+
}
|
|
363
|
+
function _(e) {
|
|
364
|
+
return Array.isArray(e) ? e : [];
|
|
365
|
+
}
|
|
366
|
+
function Ne(e, t = 9999) {
|
|
367
|
+
if (typeof e == "string" && e.trim()) return { name: e.trim(), index: t };
|
|
368
|
+
if (e && typeof e == "object") {
|
|
369
|
+
const r = String(e.name ?? "").trim(), i = Number.isFinite(e.index) ? e.index : t;
|
|
370
|
+
if (r) return { name: r, index: i };
|
|
371
|
+
}
|
|
372
|
+
return { name: "ungrouped", index: t };
|
|
373
|
+
}
|
|
374
|
+
function V(e, t) {
|
|
375
|
+
const r = (e.index ?? 9999) - (t.index ?? 9999);
|
|
376
|
+
return r !== 0 ? r : String(e.name).localeCompare(String(t.name));
|
|
377
|
+
}
|
|
378
|
+
function Te(e = {}, t = null) {
|
|
379
|
+
const r = /* @__PURE__ */ new Map(), i = {}, n = {}, a = {};
|
|
380
|
+
for (const [m, s] of Object.entries(e)) {
|
|
381
|
+
const l = Ne(s?.group, 9999), M = Number.isFinite(s?.index) ? s.index : 9999, A = `${l.index}::${l.name}`;
|
|
382
|
+
r.has(A) || r.set(A, { name: l.name, index: l.index, fields: [] }), r.get(A).fields.push({
|
|
383
|
+
name: m,
|
|
384
|
+
index: M,
|
|
385
|
+
type: s?.type,
|
|
386
|
+
default: z(s?.default),
|
|
387
|
+
hasExplicitDefault: !!s?.hasExplicitDefault,
|
|
388
|
+
required: !!s?.required,
|
|
389
|
+
editable: !!s?.editable,
|
|
390
|
+
writable: !!s?.writable,
|
|
391
|
+
show: !!s?.show,
|
|
392
|
+
metadata: s
|
|
393
|
+
}), i[m] = { group: l.name, groupIndex: l.index, index: M }, n[m] = z(s?.default), s?.hasExplicitDefault && (a[m] = z(s?.default));
|
|
394
|
+
}
|
|
395
|
+
const p = Array.from(r.values()).map((m) => ({ ...m, fields: _(m.fields).sort(V) })).sort(V);
|
|
396
|
+
return Object.freeze({
|
|
397
|
+
picture: t,
|
|
398
|
+
groups: p,
|
|
399
|
+
fieldIndex: Object.freeze({ ...i }),
|
|
400
|
+
defaults: Object.freeze({ ...n }),
|
|
401
|
+
explicitDefaults: Object.freeze({ ...a })
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
function De(e = {}, t = []) {
|
|
405
|
+
const r = {};
|
|
406
|
+
for (const i of t)
|
|
407
|
+
ze(e, i) && (r[i] = e[i]);
|
|
408
|
+
return Object.freeze(r);
|
|
409
|
+
}
|
|
410
|
+
function Y(e, t = {}) {
|
|
411
|
+
return t instanceof e ? t : e.from(t);
|
|
412
|
+
}
|
|
413
|
+
function k(e, t, r) {
|
|
414
|
+
const i = _(t?.getFields?.()), n = _(t?.getRequiredFields?.()), a = {}, p = {};
|
|
415
|
+
for (const s of i) {
|
|
416
|
+
const l = r?.[s] ?? {};
|
|
417
|
+
a[s] = z(l.default), l?.hasExplicitDefault && (p[s] = z(l.default));
|
|
418
|
+
}
|
|
419
|
+
const m = {
|
|
420
|
+
kind: e,
|
|
421
|
+
model: t,
|
|
422
|
+
fields: Object.freeze([...i]),
|
|
423
|
+
requiredFields: Object.freeze([...n]),
|
|
424
|
+
defaults: Object.freeze({ ...a }),
|
|
425
|
+
explicitDefaults: Object.freeze({ ...p }),
|
|
426
|
+
properties: De(r, i),
|
|
427
|
+
create: (s = {}) => t.from(s),
|
|
428
|
+
createEmpty: () => t.from({}),
|
|
429
|
+
fromAPI: (s = {}) => t.fromAPI(s)
|
|
430
|
+
};
|
|
431
|
+
return e === "write" && (m.toPayload = (s = {}, l = {}) => Y(t, s).toAddPayload(l)), e === "edit" && (m.toPayload = (s = {}, l = {}) => Y(t, s).toEditPayload(l)), Object.freeze(m);
|
|
432
|
+
}
|
|
433
|
+
function Z(e, t, r) {
|
|
434
|
+
if (!t) throw new Error(`Missing CRUD client for ${e}.`);
|
|
435
|
+
if (!r) throw new Error(`Missing CRUD basePath for ${e}.`);
|
|
436
|
+
}
|
|
437
|
+
function xe(e = {}, t = "resources") {
|
|
438
|
+
const r = String(e?.updateMethod ?? "PUT").toUpperCase();
|
|
439
|
+
return {
|
|
440
|
+
client: e?.client,
|
|
441
|
+
basePath: e?.basePath,
|
|
442
|
+
resource: e?.resource ?? t,
|
|
443
|
+
makeKeys: e?.makeKeys,
|
|
444
|
+
asOptions: !!e?.asOptions,
|
|
445
|
+
listAdapter: e?.listAdapter,
|
|
446
|
+
detailAdapter: e?.detailAdapter,
|
|
447
|
+
updateMethod: r === "PATCH" ? "PATCH" : "PUT"
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
function X(e, t, r, i) {
|
|
451
|
+
return {
|
|
452
|
+
list: { method: "GET", path: `${e}/`, responseMapper: (n) => i(n) },
|
|
453
|
+
create: { method: "POST", path: `${e}/`, responseMapper: (n) => r(n) },
|
|
454
|
+
detail: { method: "GET", path: ({ id: n }) => `${e}/${n}/`, responseMapper: (n) => r(n) },
|
|
455
|
+
update: { method: t, path: ({ id: n }) => `${e}/${n}/`, responseMapper: (n) => r(n) },
|
|
456
|
+
remove: { method: "DELETE", path: ({ id: n }) => `${e}/${n}/` },
|
|
457
|
+
archive: { method: "POST", path: ({ id: n }) => `${e}/${n}/archive/`, responseMapper: (n) => r(n) },
|
|
458
|
+
unarchive: { method: "POST", path: ({ id: n }) => `${e}/${n}/unarchive/`, responseMapper: (n) => r(n) }
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
function Qe(e = {}) {
|
|
462
|
+
if (!e || typeof e != "object")
|
|
463
|
+
throw new TypeError("createEntityResource expects a config object.");
|
|
464
|
+
const t = L(e.name), r = L(e.plural ?? `${e.name}s`), i = oe(e), n = i[`${t}Model`], a = i[`${t}ShowableModel`], p = i[`${t}WritableModel`], m = i[`${t}EditableModel`], l = i[`${t}ModelProperties`]?.fields ?? {}, M = k("read", a, l), A = k("write", p, l), O = k("edit", m, l), u = Object.freeze({ read: M, write: A, edit: O }), d = Te(l, e.picture ?? null);
|
|
465
|
+
class b extends n {
|
|
466
|
+
static from(c = {}) {
|
|
467
|
+
return new b(c);
|
|
468
|
+
}
|
|
469
|
+
static fromAPI(c = {}) {
|
|
470
|
+
const j = n.fromAPI(c);
|
|
471
|
+
return new b(j.toJSON());
|
|
472
|
+
}
|
|
473
|
+
static get interfaces() {
|
|
474
|
+
return u;
|
|
475
|
+
}
|
|
476
|
+
static get formSchema() {
|
|
477
|
+
return d;
|
|
478
|
+
}
|
|
479
|
+
toWritePayload(c = {}) {
|
|
480
|
+
return A.toPayload(this.toJSON(), c);
|
|
481
|
+
}
|
|
482
|
+
toEditOnlyPayload(c = {}) {
|
|
483
|
+
return O.toPayload(this.toJSON(), c);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
const P = xe(e.crud, `${e.name}s`);
|
|
487
|
+
class $ {
|
|
488
|
+
static get entity() {
|
|
489
|
+
return b;
|
|
490
|
+
}
|
|
491
|
+
static get interfaces() {
|
|
492
|
+
return u;
|
|
493
|
+
}
|
|
494
|
+
static get formSchema() {
|
|
495
|
+
return d;
|
|
496
|
+
}
|
|
497
|
+
static makeHooks(c = {}) {
|
|
498
|
+
const j = c.client ?? P.client, f = c.basePath ?? P.basePath;
|
|
499
|
+
return Z("makeHooks", j, f), ge({
|
|
500
|
+
client: j,
|
|
501
|
+
basePath: f,
|
|
502
|
+
resource: c.resource ?? P.resource,
|
|
503
|
+
mapOne: c.mapOne ?? b.fromAPI,
|
|
504
|
+
mapMany: c.mapMany ?? ((y) => Array.isArray(y) ? y.map(b.fromAPI) : []),
|
|
505
|
+
updateMethod: c.updateMethod ?? P.updateMethod,
|
|
506
|
+
makeKeys: c.makeKeys ?? P.makeKeys,
|
|
507
|
+
asOptions: c.asOptions ?? P.asOptions,
|
|
508
|
+
listAdapter: c.listAdapter ?? P.listAdapter,
|
|
509
|
+
detailAdapter: c.detailAdapter ?? P.detailAdapter
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
static makeLocalCrud({ data: c = [], isLoading: j = !1, error: f = null, refetch: y = null } = {}) {
|
|
513
|
+
const h = Array.isArray(c) ? c : [];
|
|
514
|
+
return {
|
|
515
|
+
useList: () => ({
|
|
516
|
+
data: h,
|
|
517
|
+
isLoading: !!j,
|
|
518
|
+
error: f ?? null,
|
|
519
|
+
refetch: typeof y == "function" ? y : null
|
|
520
|
+
})
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
static endpoints(c = {}) {
|
|
524
|
+
const j = c.basePath ?? P.basePath;
|
|
525
|
+
if (!j) throw new Error("Missing CRUD basePath for endpoints.");
|
|
526
|
+
const f = c.mapOne ?? b.fromAPI, y = c.mapMany ?? ((h) => Array.isArray(h) ? h.map(b.fromAPI) : []);
|
|
527
|
+
return X(j, c.updateMethod ?? P.updateMethod, f, y);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
for (const w of ["list", "create", "detail", "update", "remove", "archive", "unarchive"])
|
|
531
|
+
$[w] = async (...c) => {
|
|
532
|
+
const f = ["detail", "update", "remove", "archive", "unarchive"].includes(w), y = f ? c[0] : null, h = w === "create" ? c[0] : w === "update" ? c[1] : f ? c[1]?.req : c[0]?.req, o = w === "create" ? c[1] ?? {} : w === "update" ? c[2] ?? {} : f ? c[1] ?? {} : c[0] ?? {}, E = o.client ?? P.client, g = o.basePath ?? P.basePath;
|
|
533
|
+
Z(w, E, g);
|
|
534
|
+
const S = X(
|
|
535
|
+
g,
|
|
536
|
+
P.updateMethod,
|
|
537
|
+
b.fromAPI,
|
|
538
|
+
(q) => Array.isArray(q) ? q.map(b.fromAPI) : []
|
|
539
|
+
);
|
|
540
|
+
return E.call(S[w], {
|
|
541
|
+
pathParams: f ? { id: y } : o.pathParams,
|
|
542
|
+
data: h,
|
|
543
|
+
config: o.config
|
|
544
|
+
});
|
|
545
|
+
};
|
|
546
|
+
return {
|
|
547
|
+
...i,
|
|
548
|
+
read: M,
|
|
549
|
+
write: A,
|
|
550
|
+
edit: O,
|
|
551
|
+
interfaces: u,
|
|
552
|
+
formSchema: d,
|
|
553
|
+
[t]: b,
|
|
554
|
+
[r]: $
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
const Ie = (e) => String(e).replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`), ke = (e) => String(e).replace(/_([a-z])/g, (t, r) => r.toUpperCase()), G = (e) => Array.isArray(e) ? e.map(G) : e && typeof e == "object" ? Object.fromEntries(
|
|
558
|
+
Object.entries(e).map(([t, r]) => [ke(t), G(r)])
|
|
559
|
+
) : e, B = (e) => Array.isArray(e) ? e.map(B) : e && typeof e == "object" ? Object.fromEntries(
|
|
560
|
+
Object.entries(e).map(([t, r]) => [Ie(t), B(r)])
|
|
561
|
+
) : e;
|
|
562
|
+
class ve {
|
|
563
|
+
constructor(t, r = {}) {
|
|
564
|
+
this.ax = be.create({ baseURL: t, ...r }), this.queueKey = t ?? "default", me(this);
|
|
565
|
+
}
|
|
566
|
+
async call(t, { pathParams: r, data: i, config: n } = {}) {
|
|
567
|
+
const { method: a, path: p, requestMapper: m, responseMapper: s, offlineQueue: l } = t, M = typeof p == "function" ? p(r || {}) : p, A = m ? m(i) : i?.toJSON ? i.toJSON() : i, O = A !== void 0 ? B(A) : A, u = {
|
|
568
|
+
method: a,
|
|
569
|
+
url: M,
|
|
570
|
+
...a === "GET" ? { params: O } : { data: O },
|
|
571
|
+
...l === !1 ? { offlineQueue: !1 } : {},
|
|
572
|
+
...n || {}
|
|
573
|
+
};
|
|
574
|
+
if (ye(u) && typeof navigator < "u" && navigator.onLine === !1)
|
|
575
|
+
return v(this, u, "offline");
|
|
576
|
+
try {
|
|
577
|
+
const d = await this.ax.request(u), b = G(d.data);
|
|
578
|
+
return s ? s(b) : b;
|
|
579
|
+
} catch (d) {
|
|
580
|
+
if (await he(d, u))
|
|
581
|
+
return v(this, u, "network-error");
|
|
582
|
+
throw d;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
function D(e = "/") {
|
|
587
|
+
const t = String(e ?? "").trim();
|
|
588
|
+
return !t || t === "/" ? "/" : t.replace(/\/+$/, "") || "/";
|
|
589
|
+
}
|
|
590
|
+
function Le(e) {
|
|
591
|
+
const t = D(e), r = [], i = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/:([A-Za-z0-9_]+)/g, (n, a) => (r.push(a), "([^/]+)"));
|
|
592
|
+
return {
|
|
593
|
+
paramNames: r,
|
|
594
|
+
regex: new RegExp(`^${i}$`)
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function _e(e) {
|
|
598
|
+
return [...new Set(e.filter(Boolean))];
|
|
599
|
+
}
|
|
600
|
+
function ee(e, t = {}) {
|
|
601
|
+
return e ? e.replace(/:([A-Za-z0-9_]+)/g, (r, i) => {
|
|
602
|
+
const n = t?.[i];
|
|
603
|
+
return n == null ? `:${i}` : encodeURIComponent(String(n));
|
|
604
|
+
}) : "/";
|
|
605
|
+
}
|
|
606
|
+
function We({
|
|
607
|
+
routes: e = {},
|
|
608
|
+
defaultLanguage: t,
|
|
609
|
+
supportedLanguages: r,
|
|
610
|
+
mobileNavRouteKeys: i = []
|
|
611
|
+
} = {}) {
|
|
612
|
+
const n = Object.keys(e), a = t ?? n[0] ?? "", p = r?.length ? r : n, m = Object.keys(e[a] ?? {}), s = new Set(i), l = /* @__PURE__ */ new Map();
|
|
613
|
+
function M(f) {
|
|
614
|
+
return l.has(f) || l.set(f, Le(f)), l.get(f);
|
|
615
|
+
}
|
|
616
|
+
function A(f = a) {
|
|
617
|
+
const y = String(f ?? "").trim().toLowerCase();
|
|
618
|
+
if (!y)
|
|
619
|
+
return a;
|
|
620
|
+
if (e[y])
|
|
621
|
+
return y;
|
|
622
|
+
const [h] = y.split("-");
|
|
623
|
+
return e[h] ? h : a;
|
|
624
|
+
}
|
|
625
|
+
function O(f) {
|
|
626
|
+
return e[A(f)] ?? e[a];
|
|
627
|
+
}
|
|
628
|
+
function u(f, y) {
|
|
629
|
+
return O(f)?.[y] ?? e[a]?.[y] ?? null;
|
|
630
|
+
}
|
|
631
|
+
function d(f, y, h) {
|
|
632
|
+
return ee(u(f, y), h);
|
|
633
|
+
}
|
|
634
|
+
function b(f) {
|
|
635
|
+
return _e(p.map((y) => e[y]?.[f]));
|
|
636
|
+
}
|
|
637
|
+
function P(f, y) {
|
|
638
|
+
return p.map((h) => ({
|
|
639
|
+
language: h,
|
|
640
|
+
path: u(h, f),
|
|
641
|
+
redirect: u(h, y)
|
|
642
|
+
})).filter((h, o, E) => !h.path || !h.redirect ? !1 : E.findIndex((g) => g.path === h.path && g.redirect === h.redirect) === o);
|
|
643
|
+
}
|
|
644
|
+
function $(f) {
|
|
645
|
+
const y = D(f), h = [];
|
|
646
|
+
for (const E of p)
|
|
647
|
+
for (const g of m) {
|
|
648
|
+
const S = e[E]?.[g];
|
|
649
|
+
if (!S)
|
|
650
|
+
continue;
|
|
651
|
+
const { paramNames: q, regex: ae } = M(S), U = y.match(ae);
|
|
652
|
+
if (!U)
|
|
653
|
+
continue;
|
|
654
|
+
const se = q.reduce((Q, ue, le) => (Q[ue] = decodeURIComponent(U[le + 1] ?? ""), Q), {});
|
|
655
|
+
h.push({ language: E, routeKey: g, pattern: S, params: se });
|
|
656
|
+
}
|
|
657
|
+
if (h.length === 0)
|
|
658
|
+
return null;
|
|
659
|
+
const [o] = h;
|
|
660
|
+
return {
|
|
661
|
+
...o,
|
|
662
|
+
lang: o.language,
|
|
663
|
+
ambiguous: h.some((E) => E.language !== o.language)
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
function w(f, y) {
|
|
667
|
+
const h = $(f);
|
|
668
|
+
return h ? d(y, h.routeKey, h.params) : null;
|
|
669
|
+
}
|
|
670
|
+
function c(f) {
|
|
671
|
+
const y = $(f);
|
|
672
|
+
return y ? s.has(y.routeKey) : !1;
|
|
673
|
+
}
|
|
674
|
+
function j(f, y) {
|
|
675
|
+
if (!y)
|
|
676
|
+
return !1;
|
|
677
|
+
const h = D(f);
|
|
678
|
+
return b(y).some((o) => {
|
|
679
|
+
const g = D(o).replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/:([A-Za-z0-9_]+)/g, "[^/]+");
|
|
680
|
+
return new RegExp(`^${g}(?:/.*)?$`).test(h);
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
return {
|
|
684
|
+
routes: e,
|
|
685
|
+
supportedLanguages: p,
|
|
686
|
+
defaultLanguage: a,
|
|
687
|
+
normalizeLanguage: A,
|
|
688
|
+
getLocaleRoutes: O,
|
|
689
|
+
getRoutePattern: u,
|
|
690
|
+
buildRoutePath: ee,
|
|
691
|
+
getRoutePath: d,
|
|
692
|
+
getRoutePaths: b,
|
|
693
|
+
getRouteRedirects: P,
|
|
694
|
+
matchLocalizedRoute: $,
|
|
695
|
+
translateRoutePath: w,
|
|
696
|
+
shouldRenderMobileNav: c,
|
|
697
|
+
isRouteKeyActive: j
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
export {
|
|
701
|
+
ve as A,
|
|
702
|
+
Ce as E,
|
|
703
|
+
K as F,
|
|
704
|
+
Ue as a,
|
|
705
|
+
R as b,
|
|
706
|
+
ee as c,
|
|
707
|
+
oe as d,
|
|
708
|
+
Qe as e,
|
|
709
|
+
Ee as f,
|
|
710
|
+
We as g,
|
|
711
|
+
B as h,
|
|
712
|
+
Me as i,
|
|
713
|
+
F as j,
|
|
714
|
+
G as k,
|
|
715
|
+
W as l,
|
|
716
|
+
ge as m,
|
|
717
|
+
L as n,
|
|
718
|
+
Ie as o,
|
|
719
|
+
re as r,
|
|
720
|
+
ke as t
|
|
721
|
+
};
|