@plitzi/sdk-shared 0.39.3 → 0.39.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/clients/index.d.ts +59 -0
- package/dist/clients/index.mjs +38 -0
- package/dist/conditions/types.d.ts +1 -1
- package/dist/csrf/csrf.d.ts +36 -0
- package/dist/csrf/csrf.mjs +62 -0
- package/dist/csrf/index.d.ts +2 -0
- package/dist/csrf/index.mjs +1 -0
- package/dist/helpers/deepEqual/deepEqual.mjs +3 -2
- package/dist/helpers/lodash/cloneDeep.d.ts +3 -3
- package/dist/helpers/lodash/cloneDeep.mjs +24 -27
- package/dist/helpers/lodash/has.d.ts +2 -1
- package/dist/helpers/lodash/has.mjs +8 -8
- package/dist/helpers/lodash/index.d.ts +1 -1
- package/dist/helpers/lodash/omit.mjs +2 -2
- package/dist/helpers/twigWrapper/filters/arrays.mjs +43 -42
- package/dist/helpers/twigWrapper/filters/filters.mjs +3 -3
- package/dist/helpers/twigWrapper/filters/index.mjs +4 -4
- package/dist/helpers/twigWrapper/filters/misc.mjs +14 -13
- package/dist/helpers/twigWrapper/filters/objects.mjs +50 -49
- package/dist/helpers/twigWrapper/filters/strings.mjs +41 -40
- package/dist/helpers/twigWrapper/filters/types.d.ts +4 -0
- package/dist/helpers/twigWrapper/filters/types.mjs +2 -2
- package/dist/navigation/index.d.ts +1 -1
- package/dist/navigation/index.mjs +3 -3
- package/dist/navigation/routes.d.ts +2 -0
- package/dist/navigation/routes.mjs +2 -1
- package/dist/navigation/sitemap.d.ts +8 -0
- package/dist/navigation/sitemap.mjs +7 -4
- package/dist/react/index.d.ts +1 -1
- package/dist/refusals/index.d.ts +112 -0
- package/dist/refusals/index.mjs +94 -0
- package/dist/schema/aiCrawlers.d.ts +25 -0
- package/dist/schema/aiCrawlers.mjs +34 -0
- package/dist/schema/documentParts.d.ts +45 -0
- package/dist/schema/documentParts.mjs +73 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.mjs +21 -18
- package/dist/schema/pageAccess.mjs +1 -1
- package/dist/schema/plitziMark.d.ts +9 -0
- package/dist/schema/plitziMark.mjs +3 -0
- package/dist/schema/schemaSettings.d.ts +1 -1
- package/dist/schema/schemaSettings.mjs +1 -1
- package/dist/schema/serverElements.d.ts +5 -0
- package/dist/store/runtimeStatePersist.mjs +2 -2
- package/dist/store/storeHooks.d.ts +33 -33
- package/dist/style/runtimeStyle.d.ts +5 -2
- package/dist/style/runtimeStyle.mjs +1 -1
- package/dist/types/ActionTypes.d.ts +2 -0
- package/dist/types/AuthTypes.d.ts +5 -0
- package/dist/types/SchemaTypes.d.ts +31 -4
- package/dist/types/StoreTypes.d.ts +5 -0
- package/eslint.config.mjs +123 -100
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @plitzi/sdk-shared
|
|
2
2
|
|
|
3
|
+
## 0.39.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 35415a1: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
|
|
8
|
+
`@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
|
|
9
|
+
|
|
3
10
|
## 0.39.3
|
|
4
11
|
|
|
5
12
|
No changes in this release.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A client of the platform and its version — the CLI and the builder say theirs on every request, and the platform
|
|
3
|
+
* judges it against the oldest it takes. Older than that is refused with the step that upgrades it; older than the
|
|
4
|
+
* platform but not too old is answered, and told what is current, which the client says once. Released together, every
|
|
5
|
+
* `@plitzi/*` package has the platform's version, so a client's version is compared with the platform's own.
|
|
6
|
+
*/
|
|
7
|
+
/** What a client sends: `<surface>/<version>` — `cli/0.39.3`. */
|
|
8
|
+
export declare const CLIENT_HEADER = "x-plitzi-client";
|
|
9
|
+
/** What the platform answers a client older than itself with: its own version. */
|
|
10
|
+
export declare const CURRENT_HEADER = "x-plitzi-current";
|
|
11
|
+
export declare const CLIENT_SURFACES: readonly ["cli", "builder"];
|
|
12
|
+
export type ClientSurface = (typeof CLIENT_SURFACES)[number];
|
|
13
|
+
/** The step that brings each surface up to the platform. */
|
|
14
|
+
export declare const CLIENT_UPGRADE: Record<ClientSurface, string>;
|
|
15
|
+
export declare const clientHeaderValue: (surface: ClientSurface, version: string) => string;
|
|
16
|
+
/** The client a request names, or nothing when it names none this platform knows — a browser, a script, a page. */
|
|
17
|
+
export declare const clientOf: (header: string | undefined) => {
|
|
18
|
+
surface: ClientSurface;
|
|
19
|
+
version: string;
|
|
20
|
+
} | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* The oldest client a platform of `current` takes when its deployment names none: the minor before its own, from its
|
|
23
|
+
* first patch. A client one minor behind still works; two behind is refused.
|
|
24
|
+
*/
|
|
25
|
+
export declare const oldestByDefault: (current: string) => string;
|
|
26
|
+
export type ClientVerdict =
|
|
27
|
+
/** No client of the platform's, or one as new as it: answered as any request is. */
|
|
28
|
+
{
|
|
29
|
+
kind: 'current';
|
|
30
|
+
}
|
|
31
|
+
/** Older than the platform, not older than it takes: answered, and told what is current. */
|
|
32
|
+
| {
|
|
33
|
+
kind: 'behind';
|
|
34
|
+
surface: ClientSurface;
|
|
35
|
+
version: string;
|
|
36
|
+
current: string;
|
|
37
|
+
}
|
|
38
|
+
/** Older than the oldest the platform takes: refused, with the step that upgrades it. */
|
|
39
|
+
| {
|
|
40
|
+
kind: 'refused';
|
|
41
|
+
surface: ClientSurface;
|
|
42
|
+
version: string;
|
|
43
|
+
oldest: string;
|
|
44
|
+
current: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* A client judged against the platform: `current` is the platform's version, `oldest` the oldest of each surface it
|
|
48
|
+
* takes. A patch behind is current — patches change no contract.
|
|
49
|
+
*/
|
|
50
|
+
export declare const judgeClient: (header: string | undefined, platform: {
|
|
51
|
+
current: string;
|
|
52
|
+
oldest: Record<ClientSurface, string>;
|
|
53
|
+
}) => ClientVerdict;
|
|
54
|
+
/** What a refused client is told: what it is, what the platform takes, and the step. */
|
|
55
|
+
export declare const outdatedText: (verdict: Extract<ClientVerdict, {
|
|
56
|
+
kind: "refused";
|
|
57
|
+
}>) => string;
|
|
58
|
+
/** What a client behind is told, once. */
|
|
59
|
+
export declare const behindText: (surface: ClientSurface, version: string, current: string) => string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/clients/index.ts
|
|
2
|
+
var e = "x-plitzi-client", t = "x-plitzi-current", n = ["cli", "builder"], r = {
|
|
3
|
+
cli: "in a project, plitzi upgrade packages (the CLI is one of them); elsewhere, npx @plitzi/cli@latest",
|
|
4
|
+
builder: "reload the builder: it loads the platform’s own"
|
|
5
|
+
}, i = (e) => {
|
|
6
|
+
let t = /^(\d+)\.(\d+)\.(\d+)/.exec(e.trim());
|
|
7
|
+
return t ? [
|
|
8
|
+
Number(t[1]),
|
|
9
|
+
Number(t[2]),
|
|
10
|
+
Number(t[3])
|
|
11
|
+
] : void 0;
|
|
12
|
+
}, a = (e, t) => e[0] - t[0] || e[1] - t[1] || e[2] - t[2], o = (e) => n.some((t) => t === e), s = (e, t) => `${e}/${t}`, c = (e) => {
|
|
13
|
+
let [t = "", n = ""] = (e ?? "").split("/");
|
|
14
|
+
return o(t) && i(n) ? {
|
|
15
|
+
surface: t,
|
|
16
|
+
version: n
|
|
17
|
+
} : void 0;
|
|
18
|
+
}, l = (e) => {
|
|
19
|
+
let t = i(e);
|
|
20
|
+
if (!t) return e;
|
|
21
|
+
let [n, r] = t;
|
|
22
|
+
return r > 0 ? `${String(n)}.${String(r - 1)}.0` : `${String(n)}.0.0`;
|
|
23
|
+
}, u = (e, t) => {
|
|
24
|
+
let n = c(e), r = n && i(n.version), o = i(t.current);
|
|
25
|
+
if (!n || !r || !o) return { kind: "current" };
|
|
26
|
+
let s = i(t.oldest[n.surface]);
|
|
27
|
+
return s && a(r, s) < 0 ? {
|
|
28
|
+
kind: "refused",
|
|
29
|
+
...n,
|
|
30
|
+
oldest: t.oldest[n.surface],
|
|
31
|
+
current: t.current
|
|
32
|
+
} : r[0] < o[0] || r[0] === o[0] && r[1] < o[1] ? {
|
|
33
|
+
kind: "behind",
|
|
34
|
+
...n,
|
|
35
|
+
current: t.current
|
|
36
|
+
} : { kind: "current" };
|
|
37
|
+
}, d = (e) => `This ${e.surface === "cli" ? "CLI" : "builder"} is ${e.version}, and the platform (${e.current}) takes ${e.oldest} and later: ${r[e.surface]}.`, f = (e, t, n) => `Plitzi ${n} is out, and this ${e === "cli" ? "CLI" : "builder"} is ${t}: ${r[e]}.`;
|
|
38
|
+
export { e as CLIENT_HEADER, n as CLIENT_SURFACES, r as CLIENT_UPGRADE, t as CURRENT_HEADER, f as behindText, s as clientHeaderValue, c as clientOf, u as judgeClient, l as oldestByDefault, d as outdatedText };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A condition as Plitzi stores it — a flag's rules, an interaction's `when`, a binding's condition: the schema's own
|
|
3
|
-
* format, so sdk-shared defines it (
|
|
3
|
+
* format, so sdk-shared defines it (docs/en/server-packages.md, D13). plitzi-ui's QueryBuilder edits the same shape with prop types of its
|
|
4
4
|
* own, and a type test in the builder, where the two meet, holds them assignable both ways.
|
|
5
5
|
*/
|
|
6
6
|
export type RuleValue = Date | string | number | boolean | undefined | null | object;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CSRF token, from the page's side: echoed on every write a page sends with the visitor's session cookie to an API
|
|
3
|
+
* that asks for one (the kernel's `createCsrf`), and renewed when it has run out.
|
|
4
|
+
*
|
|
5
|
+
* The page is told which APIs ask for it, the cookie it is kept in and where a new one is handed out, by the page
|
|
6
|
+
* server (`<meta name="plitzi-csrf">`, from the deployment's `rsc.visitorCredentials`). A meta tag rather than state:
|
|
7
|
+
* every copy of this module reads the same one — the SDK's, the builder's bundle, a plugin's. Sent to those APIs alone:
|
|
8
|
+
* the token is bound to the session, and a request to anywhere else never carries it.
|
|
9
|
+
*/
|
|
10
|
+
/** The header the token is echoed in. */
|
|
11
|
+
export declare const CSRF_HEADER_NAME = "x-csrf-token";
|
|
12
|
+
/** The field a `<form>` may carry it in instead. */
|
|
13
|
+
export declare const CSRF_FIELD_NAME = "_csrf";
|
|
14
|
+
/** The suffix of its cookie's name, after the session cookie's: `plitzi_auth` → `plitzi_auth_csrf`. */
|
|
15
|
+
export declare const CSRF_COOKIE_SUFFIX = "_csrf";
|
|
16
|
+
/** The meta tag the page server writes what the page needs to know in. */
|
|
17
|
+
export declare const CSRF_HINT_META = "plitzi-csrf";
|
|
18
|
+
/** What a refusal for the token says, in the kernel's words: a reason a new token answers. */
|
|
19
|
+
export declare const CSRF_RENEWABLE: readonly ["missing", "malformed", "expired", "mismatch"];
|
|
20
|
+
/** What the page is told: the APIs that ask for the token, each with the cookie it keeps it in, and where a new one is
|
|
21
|
+
* handed out on each. */
|
|
22
|
+
export type CsrfHint = {
|
|
23
|
+
apis: {
|
|
24
|
+
origin: string;
|
|
25
|
+
cookie: string;
|
|
26
|
+
}[];
|
|
27
|
+
path: string;
|
|
28
|
+
};
|
|
29
|
+
/** The hint the page carries, or none: a page no API asks a token of, or one drawn without a server. */
|
|
30
|
+
export declare const readCsrfHint: (doc?: Pick<Document, "querySelector">) => CsrfHint | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* `fetch`, echoing the CSRF token on a write sent with the session cookie to an API that asks for one — and, refused
|
|
33
|
+
* for the token (it ran out, the session changed), asking for a new one and sending the write once more. Any other
|
|
34
|
+
* request is sent as it is.
|
|
35
|
+
*/
|
|
36
|
+
export declare const csrfFetch: (input: string | URL, init?: RequestInit, fetchImpl?: typeof fetch) => Promise<Response>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/csrf/csrf.ts
|
|
2
|
+
var e = "x-csrf-token", t = "_csrf", n = "_csrf", r = "plitzi-csrf", i = [
|
|
3
|
+
"missing",
|
|
4
|
+
"malformed",
|
|
5
|
+
"expired",
|
|
6
|
+
"mismatch"
|
|
7
|
+
], a = /* @__PURE__ */ new Set([
|
|
8
|
+
"POST",
|
|
9
|
+
"PUT",
|
|
10
|
+
"PATCH",
|
|
11
|
+
"DELETE"
|
|
12
|
+
]), o = (e) => typeof e == "object" && !!e && typeof e.origin == "string" && typeof e.cookie == "string", s = (e) => {
|
|
13
|
+
if (typeof e != "object" || !e) return !1;
|
|
14
|
+
let { apis: t, path: n } = e;
|
|
15
|
+
return Array.isArray(t) && t.every(o) && typeof n == "string";
|
|
16
|
+
}, c = (e) => {
|
|
17
|
+
let t = (e ?? (typeof document > "u" ? void 0 : document))?.querySelector(`meta[name="${r}"]`)?.getAttribute("content");
|
|
18
|
+
if (t) try {
|
|
19
|
+
let e = JSON.parse(t);
|
|
20
|
+
return s(e) ? e : void 0;
|
|
21
|
+
} catch {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
}, l = (e, t) => {
|
|
25
|
+
for (let n of e.split(";")) {
|
|
26
|
+
let e = n.indexOf("=");
|
|
27
|
+
if (e !== -1 && n.slice(0, e).trim() === t) return decodeURIComponent(n.slice(e + 1).trim());
|
|
28
|
+
}
|
|
29
|
+
}, u = (e, t) => {
|
|
30
|
+
try {
|
|
31
|
+
return new URL(e, t).origin;
|
|
32
|
+
} catch {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}, d = (e, t, n) => {
|
|
36
|
+
if (!e || n.credentials !== "include" || !a.has((n.method ?? "GET").toUpperCase())) return;
|
|
37
|
+
let r = u(t, typeof location > "u" ? void 0 : location.href);
|
|
38
|
+
return e.apis.find((e) => e.origin === r);
|
|
39
|
+
}, f = /* @__PURE__ */ new Map(), p = async (e, t, n) => {
|
|
40
|
+
let r = await e(`${n}${t.path}`, { credentials: "include" });
|
|
41
|
+
if (!r.ok) return;
|
|
42
|
+
let i = await r.json();
|
|
43
|
+
if (typeof i.token == "string") return f.set(n, i.token), i.token;
|
|
44
|
+
}, m = (e) => l(typeof document > "u" ? "" : document.cookie, e.cookie) ?? f.get(e.origin), h = (t, n) => {
|
|
45
|
+
let r = new Headers(t.headers);
|
|
46
|
+
return r.set(e, n), {
|
|
47
|
+
...t,
|
|
48
|
+
headers: r
|
|
49
|
+
};
|
|
50
|
+
}, g = async (e) => {
|
|
51
|
+
if (e.status !== 403) return !1;
|
|
52
|
+
let t = await e.clone().json().catch(() => void 0);
|
|
53
|
+
return i.includes(t?.reason);
|
|
54
|
+
}, _ = async (e, t = {}, n = globalThis.fetch) => {
|
|
55
|
+
let r = c(), i = d(r, e, t);
|
|
56
|
+
if (!r || !i) return n(e, t);
|
|
57
|
+
let a = m(i) ?? await p(n, r, i.origin), o = await n(e, a ? h(t, a) : t);
|
|
58
|
+
if (!await g(o)) return o;
|
|
59
|
+
let s = await p(n, r, i.origin);
|
|
60
|
+
return s ? n(e, h(t, s)) : o;
|
|
61
|
+
};
|
|
62
|
+
export { n as CSRF_COOKIE_SUFFIX, t as CSRF_FIELD_NAME, e as CSRF_HEADER_NAME, r as CSRF_HINT_META, i as CSRF_RENEWABLE, _ as csrfFetch, c as readCsrfHint };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CSRF_COOKIE_SUFFIX, CSRF_FIELD_NAME, CSRF_HEADER_NAME, CSRF_HINT_META, CSRF_RENEWABLE, csrfFetch, readCsrfHint } from "./csrf.mjs";
|
|
@@ -22,8 +22,9 @@ var e = (e, t) => Object.getOwnPropertyDescriptor(e, t)?.enumerable, t = (n, r,
|
|
|
22
22
|
return !0;
|
|
23
23
|
}
|
|
24
24
|
if (ArrayBuffer.isView(n) && ArrayBuffer.isView(r)) {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
let e = n, t = r;
|
|
26
|
+
if (s = e.length, s != t.length) return !1;
|
|
27
|
+
for (c = s; c-- !== 0;) if (e[c] !== t[c]) return !1;
|
|
27
28
|
return !0;
|
|
28
29
|
}
|
|
29
30
|
if (n.constructor === RegExp) return n.source === r.source && n.global === r.global && n.ignoreCase === r.ignoreCase && n.multiline === r.multiline && n.unicode === r.unicode && n.lastIndex === r.lastIndex && n.sticky === r.sticky;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Path } from './shared';
|
|
2
|
-
export declare
|
|
3
|
-
export declare const cloneObject: <T>(obj: T) => T;
|
|
2
|
+
export declare const cloneDeep: <T>(value: T) => T;
|
|
3
|
+
export declare const cloneObject: <T extends object>(obj: T) => T;
|
|
4
4
|
/**
|
|
5
5
|
* Clones only the necessary path (structural sharing).
|
|
6
6
|
* Useful for immutable operations like omit without cloning the entire object.
|
|
7
7
|
*/
|
|
8
|
-
export declare function cloneAtPath<T extends
|
|
8
|
+
export declare function cloneAtPath<T extends object>(obj: T, path: Path): T;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toPath as e } from "./shared.mjs";
|
|
2
2
|
// src/helpers/lodash/cloneDeep.ts
|
|
3
|
-
|
|
3
|
+
var t = (e, n) => {
|
|
4
4
|
if (typeof e != "object" || !e) return e;
|
|
5
5
|
if (n.has(e)) return n.get(e);
|
|
6
6
|
if (e instanceof Date) return new Date(e.getTime());
|
|
@@ -13,41 +13,38 @@ function t(e, n = /* @__PURE__ */ new WeakMap()) {
|
|
|
13
13
|
let r = /* @__PURE__ */ new Set();
|
|
14
14
|
return n.set(e, r), e.forEach((e) => r.add(t(e, n))), r;
|
|
15
15
|
}
|
|
16
|
-
if (ArrayBuffer.isView(e)) {
|
|
17
|
-
if (e instanceof DataView) {
|
|
18
|
-
let r = new DataView(t(e.buffer, n), e.byteOffset, e.byteLength);
|
|
19
|
-
return n.set(e, r), r;
|
|
20
|
-
}
|
|
21
|
-
let r = e.constructor, i = new r(e.buffer.slice(0), e.byteOffset, e.length);
|
|
22
|
-
return n.set(e, i), i;
|
|
23
|
-
}
|
|
24
16
|
if (e instanceof ArrayBuffer) {
|
|
25
17
|
let t = e.slice(0);
|
|
26
18
|
return n.set(e, t), t;
|
|
27
19
|
}
|
|
20
|
+
if (e instanceof DataView) {
|
|
21
|
+
let r = t(e.buffer, n), i = r instanceof ArrayBuffer ? new DataView(r, e.byteOffset, e.byteLength) : e;
|
|
22
|
+
return n.set(e, i), i;
|
|
23
|
+
}
|
|
24
|
+
if (ArrayBuffer.isView(e)) {
|
|
25
|
+
let t = Reflect.get(e, "slice"), r = typeof t == "function" ? Reflect.apply(t, e, []) : e;
|
|
26
|
+
return n.set(e, r), r;
|
|
27
|
+
}
|
|
28
28
|
if (Array.isArray(e)) {
|
|
29
29
|
let r = [];
|
|
30
30
|
return n.set(e, r), e.forEach((e, i) => r[i] = t(e, n)), r;
|
|
31
31
|
}
|
|
32
|
-
let r = Object.getPrototypeOf(e)
|
|
33
|
-
n.set(e,
|
|
34
|
-
for (let
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
let t = i[e], r = o?.[t];
|
|
44
|
-
if (!r || typeof r != "object") {
|
|
45
|
-
s[t] = r;
|
|
32
|
+
let r = Object.create(Reflect.getPrototypeOf(e));
|
|
33
|
+
n.set(e, r);
|
|
34
|
+
for (let i of Object.keys(e)) Reflect.set(r, i, t(Reflect.get(e, i), n));
|
|
35
|
+
return r;
|
|
36
|
+
}, n = (e) => t(e, /* @__PURE__ */ new WeakMap()), r = (e) => Object.assign(Object.create(Reflect.getPrototypeOf(e)), e), i = (e) => Array.isArray(e) ? [...e] : r(e);
|
|
37
|
+
function a(t, n) {
|
|
38
|
+
let r = i(t), a = t, o = r;
|
|
39
|
+
for (let t of e(n)) {
|
|
40
|
+
let e = typeof a == "object" && a ? Reflect.get(a, t) : void 0;
|
|
41
|
+
if (!e || typeof e != "object") {
|
|
42
|
+
Reflect.set(o, t, e);
|
|
46
43
|
break;
|
|
47
44
|
}
|
|
48
|
-
let
|
|
49
|
-
|
|
45
|
+
let n = i(e);
|
|
46
|
+
Reflect.set(o, t, n), a = e, o = n;
|
|
50
47
|
}
|
|
51
|
-
return
|
|
48
|
+
return r;
|
|
52
49
|
}
|
|
53
|
-
export {
|
|
50
|
+
export { a as cloneAtPath, n as cloneDeep, r as cloneObject };
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { Path } from './shared';
|
|
2
|
-
|
|
2
|
+
/** Whether every key of the path is there, own or inherited — a value that holds no keys holds none of them. */
|
|
3
|
+
export declare function has(obj: object | null | undefined, path: Path): boolean;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { toPath as e } from "./shared.mjs";
|
|
2
2
|
// src/helpers/lodash/has.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let
|
|
6
|
-
for (let
|
|
7
|
-
if (i
|
|
8
|
-
i = i
|
|
3
|
+
var t = (e) => typeof e == "object" && !!e || typeof e == "function";
|
|
4
|
+
function n(n, r) {
|
|
5
|
+
let i = n;
|
|
6
|
+
for (let n of e(r)) {
|
|
7
|
+
if (!t(i) || !(n in i)) return !1;
|
|
8
|
+
i = Reflect.get(i, n);
|
|
9
9
|
}
|
|
10
|
-
return
|
|
10
|
+
return t(n);
|
|
11
11
|
}
|
|
12
|
-
export {
|
|
12
|
+
export { n as has };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The lodash-like utilities sdk-shared reads paths and keys with — a copy of plitzi-ui's own, which keeps its for its 29
|
|
3
|
-
* files (
|
|
3
|
+
* files (docs/en/server-packages.md, D13): generic, with no Plitzi rule in them, so two copies are not two sources of truth for any rule,
|
|
4
4
|
* and a server reaches neither React nor a UI library to read a path.
|
|
5
5
|
*/
|
|
6
6
|
export * from './get';
|
|
@@ -13,7 +13,7 @@ function i(i, a) {
|
|
|
13
13
|
let l = i;
|
|
14
14
|
if (s.length) {
|
|
15
15
|
let e;
|
|
16
|
-
for (let n of s) Object.prototype.hasOwnProperty.call(l, n) && (e ??= t(l),
|
|
16
|
+
for (let n of s) Object.prototype.hasOwnProperty.call(l, n) && (e ??= t(l), Reflect.deleteProperty(e, n));
|
|
17
17
|
e && (l = e);
|
|
18
18
|
}
|
|
19
19
|
for (let t of c) {
|
|
@@ -26,7 +26,7 @@ function i(i, a) {
|
|
|
26
26
|
}
|
|
27
27
|
if (o && typeof o == "object") {
|
|
28
28
|
let e = i[i.length - 1];
|
|
29
|
-
Object.prototype.hasOwnProperty.call(o, e) &&
|
|
29
|
+
Object.prototype.hasOwnProperty.call(o, e) && Reflect.deleteProperty(o, e);
|
|
30
30
|
}
|
|
31
31
|
l = a;
|
|
32
32
|
}
|
|
@@ -1,65 +1,66 @@
|
|
|
1
|
-
import { ARROW_PARAMS as e } from "./types.mjs";
|
|
2
|
-
import { compareValues as
|
|
1
|
+
import { ARROW_PARAMS as e, isCallback as t, isList as n } from "./types.mjs";
|
|
2
|
+
import { compareValues as r, toStr as i } from "./values.mjs";
|
|
3
|
+
import { isRecord as a } from "../../isRecord.mjs";
|
|
3
4
|
// src/helpers/twigWrapper/filters/arrays.ts
|
|
4
|
-
var
|
|
5
|
-
sort: (
|
|
6
|
-
if (!
|
|
7
|
-
let
|
|
8
|
-
if (
|
|
9
|
-
let
|
|
10
|
-
return (
|
|
5
|
+
var o = {
|
|
6
|
+
sort: (i, a) => {
|
|
7
|
+
if (!n(i)) return i;
|
|
8
|
+
let o = [...i], s = a[0];
|
|
9
|
+
if (t(s)) {
|
|
10
|
+
let t = s;
|
|
11
|
+
return (t[e] ?? 1) >= 2 ? o.sort((e, n) => Number(t(e, n))) : o.sort((e, n) => r(t(e), t(n)));
|
|
11
12
|
}
|
|
12
|
-
return
|
|
13
|
+
return o.sort(r);
|
|
13
14
|
},
|
|
14
15
|
batch: (e, t) => {
|
|
15
|
-
if (!
|
|
16
|
-
let
|
|
17
|
-
if (
|
|
18
|
-
let
|
|
19
|
-
for (let t = 0; t < e.length; t +=
|
|
20
|
-
return
|
|
16
|
+
if (!n(e) || t.length === 0) return e;
|
|
17
|
+
let r = Number(t[0]);
|
|
18
|
+
if (r <= 0) return e;
|
|
19
|
+
let i = [];
|
|
20
|
+
for (let t = 0; t < e.length; t += r) i.push(e.slice(t, t + r));
|
|
21
|
+
return i;
|
|
21
22
|
},
|
|
22
|
-
map: (e,
|
|
23
|
-
if (!
|
|
24
|
-
let
|
|
25
|
-
return
|
|
23
|
+
map: (e, r) => {
|
|
24
|
+
if (!n(e) || r.length === 0) return e;
|
|
25
|
+
let i = r[0];
|
|
26
|
+
return t(i) ? e.map((e, t) => i(e, t)) : e;
|
|
26
27
|
},
|
|
27
|
-
reduce: (e,
|
|
28
|
-
if (!
|
|
29
|
-
let
|
|
30
|
-
if (
|
|
31
|
-
let
|
|
32
|
-
for (let t =
|
|
33
|
-
return
|
|
28
|
+
reduce: (e, r) => {
|
|
29
|
+
if (!n(e) || r.length === 0) return e;
|
|
30
|
+
let i = r[0];
|
|
31
|
+
if (!t(i)) return e;
|
|
32
|
+
let a = r[1], o = +(a === void 0), s = a === void 0 ? e[0] : a;
|
|
33
|
+
for (let t = o; t < e.length; t++) s = i(s, e[t], t);
|
|
34
|
+
return s;
|
|
34
35
|
},
|
|
35
36
|
merge: (e, t) => {
|
|
36
37
|
if (t.length === 0) return e;
|
|
37
|
-
let
|
|
38
|
-
return
|
|
38
|
+
let r = t[0];
|
|
39
|
+
return n(e) && n(r) ? [...e, ...r] : typeof e == "object" && e && typeof r == "object" && r && !n(r) ? {
|
|
39
40
|
...e,
|
|
40
|
-
...
|
|
41
|
+
...r
|
|
41
42
|
} : e;
|
|
42
43
|
},
|
|
43
|
-
keys: (e) =>
|
|
44
|
-
values: (e) =>
|
|
45
|
-
filter: (e,
|
|
46
|
-
if (!
|
|
47
|
-
if (
|
|
48
|
-
let
|
|
49
|
-
if (
|
|
50
|
-
let
|
|
44
|
+
keys: (e) => a(e) ? Object.keys(e) : e,
|
|
45
|
+
values: (e) => a(e) ? Object.values(e) : e,
|
|
46
|
+
filter: (e, r) => {
|
|
47
|
+
if (!n(e)) return e;
|
|
48
|
+
if (r.length === 0) return e.filter(Boolean);
|
|
49
|
+
let a = r[0];
|
|
50
|
+
if (t(a)) return e.filter((e, t) => a(e, t));
|
|
51
|
+
let o = i(a);
|
|
51
52
|
return e.filter((e) => {
|
|
52
53
|
if (typeof e == "object" && e) {
|
|
53
|
-
let t = e[
|
|
54
|
+
let t = e[o];
|
|
54
55
|
return t != null && t !== !1 && t !== "";
|
|
55
56
|
}
|
|
56
57
|
return !!e;
|
|
57
58
|
});
|
|
58
59
|
},
|
|
59
60
|
column: (e, t) => {
|
|
60
|
-
if (!
|
|
61
|
-
let r =
|
|
61
|
+
if (!n(e) || t.length === 0) return e;
|
|
62
|
+
let r = i(t[0]);
|
|
62
63
|
return e.map((e) => typeof e == "object" && e ? e[r] : void 0);
|
|
63
64
|
}
|
|
64
65
|
};
|
|
65
|
-
export {
|
|
66
|
+
export { o as arrayTransformFilters };
|
|
@@ -5,9 +5,9 @@ import { numberFilters as o } from "./numbers.mjs";
|
|
|
5
5
|
import { objectFilters as s, queryFilters as c } from "./objects.mjs";
|
|
6
6
|
import { defaultFilters as l, identityFilters as u, serialisationFilters as d, stringOperationFilters as f, stringQueryFilters as p, stringTransformFilters as m } from "./strings.mjs";
|
|
7
7
|
import { RAW_MARKER as h, isRawMarker as g, unwrapRaw as _, wrapRaw as v } from "./raw.mjs";
|
|
8
|
-
import { ARROW_PARAMS as y } from "./types.mjs";
|
|
8
|
+
import { ARROW_PARAMS as y, isCallback as b, isList as x } from "./types.mjs";
|
|
9
9
|
// src/helpers/twigWrapper/filters/filters.ts
|
|
10
|
-
var
|
|
10
|
+
var S = {
|
|
11
11
|
...u,
|
|
12
12
|
...d,
|
|
13
13
|
...l,
|
|
@@ -24,4 +24,4 @@ var b = {
|
|
|
24
24
|
...s,
|
|
25
25
|
...c
|
|
26
26
|
};
|
|
27
|
-
export { y as ARROW_PARAMS, h as RAW_MARKER,
|
|
27
|
+
export { y as ARROW_PARAMS, h as RAW_MARKER, S as filters, b as isCallback, x as isList, g as isRawMarker, _ as unwrapRaw, v as wrapRaw };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ARROW_PARAMS as e } from "./types.mjs";
|
|
2
|
-
import { RAW_MARKER as
|
|
3
|
-
import { filters as
|
|
4
|
-
export { e as ARROW_PARAMS,
|
|
1
|
+
import { ARROW_PARAMS as e, isCallback as t, isList as n } from "./types.mjs";
|
|
2
|
+
import { RAW_MARKER as r, isRawMarker as i, unwrapRaw as a, wrapRaw as o } from "./raw.mjs";
|
|
3
|
+
import { filters as s } from "./filters.mjs";
|
|
4
|
+
export { e as ARROW_PARAMS, r as RAW_MARKER, s as filters, t as isCallback, n as isList, i as isRawMarker, a as unwrapRaw, o as wrapRaw };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { base64ToUtf8 as e, md5Hex as t, utf8ToBase64 as n } from "./hashing.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { isList as r } from "./types.mjs";
|
|
3
|
+
import { toStr as i } from "./values.mjs";
|
|
3
4
|
// src/helpers/twigWrapper/filters/misc.ts
|
|
4
|
-
var
|
|
5
|
-
url_encode: (e) => typeof e == "string" ? encodeURIComponent(e) : typeof e == "object" && e && !
|
|
5
|
+
var a = {
|
|
6
|
+
url_encode: (e) => typeof e == "string" ? encodeURIComponent(e) : typeof e == "object" && e && !r(e) ? new URLSearchParams(Object.fromEntries(Object.entries(e).map(([e, t]) => [e, i(t)]))).toString() : e,
|
|
6
7
|
nl2br: (e) => typeof e == "string" ? e.replace(/\n/g, "<br>") : e,
|
|
7
8
|
striptags: (e, t) => {
|
|
8
9
|
if (typeof e != "string") return e;
|
|
9
|
-
let n = t.length > 0 ?
|
|
10
|
+
let n = t.length > 0 ? i(t[0]).trim() : "";
|
|
10
11
|
if (n) {
|
|
11
12
|
let t = n.split(/(?:\s*>\s*<\s*|<\s*|>\s*)/).filter(Boolean).map((e) => e.replace(/[/>]/g, "").trim());
|
|
12
13
|
if (t.length > 0) {
|
|
@@ -19,33 +20,33 @@ var i = {
|
|
|
19
20
|
abs: (e) => typeof e == "number" ? Math.abs(e) : e,
|
|
20
21
|
round: (e, t) => {
|
|
21
22
|
if (typeof e != "number") return e;
|
|
22
|
-
let n = Number(t[0]) || 0,
|
|
23
|
-
return
|
|
23
|
+
let n = Number(t[0]) || 0, r = t[1] == null ? "common" : i(t[1]), a = 10 ** n;
|
|
24
|
+
return r === "ceil" ? Math.ceil(e * a) / a : r === "floor" ? Math.floor(e * a) / a : Math.round(e * a) / a;
|
|
24
25
|
},
|
|
25
26
|
format: (e, t) => {
|
|
26
27
|
if (typeof e != "string") return e;
|
|
27
28
|
let n = 0;
|
|
28
|
-
return e.replace(/%((?:[-+ 0]|'.)*)(\d*)(?:\.(\d+))?([sdf%])/g, (e,
|
|
29
|
+
return e.replace(/%((?:[-+ 0]|'.)*)(\d*)(?:\.(\d+))?([sdf%])/g, (e, r, a, o, s) => {
|
|
29
30
|
if (s === "%") return "%";
|
|
30
31
|
let c = t[n];
|
|
31
32
|
if (n++, c === void 0) return e;
|
|
32
|
-
let l =
|
|
33
|
+
let l = r.includes("+"), u;
|
|
33
34
|
if (s === "d") {
|
|
34
35
|
let e = Math.trunc(Number(c));
|
|
35
36
|
u = `${l && e >= 0 ? "+" : ""}${e}`;
|
|
36
37
|
} else if (s === "f") {
|
|
37
38
|
let e = Number(c);
|
|
38
39
|
u = `${l && e >= 0 ? "+" : ""}${o === void 0 ? String(e) : e.toFixed(Number(o))}`;
|
|
39
|
-
} else u =
|
|
40
|
+
} else u = i(c), u = o === void 0 ? u : u.slice(0, Number(o));
|
|
40
41
|
let d = Number(a || 0);
|
|
41
42
|
if (u.length >= d) return u;
|
|
42
|
-
let f = /'(.)/.exec(
|
|
43
|
-
return
|
|
43
|
+
let f = /'(.)/.exec(r), p = f ? f[1] : r.includes("0") ? "0" : " ";
|
|
44
|
+
return r.includes("-") ? u.padEnd(d, p === "0" ? " " : p) : p === "0" && s !== "s" && /^[+-]/.test(u) ? u[0] + u.slice(1).padStart(d - 1, "0") : u.padStart(d, p);
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
|
-
},
|
|
47
|
+
}, o = { spaceless: (e) => typeof e == "string" ? e.replace(/>\s+</g, "><").trim() : e }, s = { random: (e) => r(e) ? e.length > 0 ? e[Math.floor(Math.random() * e.length)] : void 0 : typeof e == "string" ? e.length > 0 ? e[Math.floor(Math.random() * e.length)] : "" : typeof e == "number" ? Math.floor(Math.random() * e) : e }, c = {
|
|
47
48
|
base64_encode: (e) => typeof e == "string" ? n(e) : e,
|
|
48
49
|
base64_decode: (t) => typeof t == "string" ? e(t) : t,
|
|
49
50
|
md5: (e) => typeof e == "string" ? t(e) : e
|
|
50
51
|
};
|
|
51
|
-
export {
|
|
52
|
+
export { c as encodingFilters, a as miscFilters, s as randomFilters, o as whitespaceFilters };
|