@rolder/kit 3.0.0-alpha-4 → 3.0.0-alpha-5

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.
Files changed (47) hide show
  1. package/dist/app/AppDefaults.d.ts +3 -0
  2. package/dist/app/AppDefaults.js +27 -0
  3. package/dist/app/DefaultApp.d.ts +6 -0
  4. package/dist/app/DefaultApp.js +43 -0
  5. package/dist/app/cookieColorSchemeManager.d.ts +6 -0
  6. package/dist/app/cookieColorSchemeManager.js +46 -0
  7. package/dist/app/defaultRequestMiddlewares.d.ts +4 -0
  8. package/dist/app/defaultRequestMiddlewares.js +24 -0
  9. package/dist/app/defaultTheme.d.ts +141 -0
  10. package/dist/app/defaultTheme.js +24 -0
  11. package/dist/app/index.d.ts +3 -0
  12. package/dist/app/index.js +3 -0
  13. package/dist/hooks/index.d.ts +2 -0
  14. package/dist/hooks/index.js +2 -0
  15. package/dist/hooks/useMutation.d.ts +4 -0
  16. package/dist/hooks/useMutation.js +8 -0
  17. package/dist/hooks/useMutationWithInvalidate.d.ts +4 -0
  18. package/dist/hooks/useMutationWithInvalidate.js +16 -0
  19. package/dist/index.d.ts +3 -0
  20. package/dist/index.js +3 -0
  21. package/dist/surreal/connection.d.ts +9 -0
  22. package/dist/surreal/connection.js +49 -0
  23. package/dist/surreal/deafaultCrud.d.ts +2 -0
  24. package/dist/surreal/deafaultCrud.js +18 -0
  25. package/dist/surreal/deserialize.d.ts +17 -0
  26. package/dist/surreal/deserialize.js +46 -0
  27. package/dist/surreal/encryption.d.ts +8 -0
  28. package/dist/surreal/encryption.js +28 -0
  29. package/dist/surreal/index.d.ts +4 -0
  30. package/dist/surreal/index.js +5 -0
  31. package/dist/ui/error/DefaultError.d.ts +2 -0
  32. package/dist/ui/error/DefaultError.js +62 -0
  33. package/dist/ui/error/DefaultNotFound.d.ts +1 -0
  34. package/dist/ui/error/DefaultNotFound.js +37 -0
  35. package/dist/ui/error/defaultErrorNotification.d.ts +1 -0
  36. package/dist/ui/error/defaultErrorNotification.js +8 -0
  37. package/dist/ui/error/index.d.ts +3 -0
  38. package/dist/ui/error/index.js +3 -0
  39. package/dist/ui/index.d.ts +1 -1
  40. package/dist/ui/index.js +1 -1
  41. package/package.json +7 -3
  42. package/dist/ui/hoverActionIcon/HoverActionIcon.d.ts +0 -6
  43. package/dist/ui/hoverActionIcon/HoverActionIcon.js +0 -14
  44. package/dist/ui/hoverActionIcon/index.d.ts +0 -1
  45. package/dist/ui/hoverActionIcon/index.js +0 -1
  46. package/dist/ui/hoverActionIcon/styles.module.js +0 -5
  47. package/dist/ui/hoverActionIcon/styles_module.css +0 -10
@@ -0,0 +1,3 @@
1
+ export declare const AppDefaults: ({ saveColorScheme, }: {
2
+ saveColorScheme: boolean;
3
+ }) => null;
@@ -0,0 +1,27 @@
1
+ import { useComputedColorScheme } from "@mantine/core";
2
+ import { useEffect } from "react";
3
+ import { setCookies } from "../functions/index.js";
4
+ const AppDefaults = ({ saveColorScheme })=>{
5
+ const colorScheme = useComputedColorScheme();
6
+ useEffect(()=>{
7
+ const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
8
+ const cookies = [
9
+ {
10
+ name: 'tz',
11
+ value: tz,
12
+ expires: 365
13
+ }
14
+ ];
15
+ if (saveColorScheme) cookies.push({
16
+ name: 'colorScheme',
17
+ value: colorScheme,
18
+ expires: 365
19
+ });
20
+ setCookies(cookies);
21
+ }, [
22
+ colorScheme,
23
+ saveColorScheme
24
+ ]);
25
+ return null;
26
+ };
27
+ export { AppDefaults };
@@ -0,0 +1,6 @@
1
+ import { type MantineProviderProps } from '@mantine/core';
2
+ interface Props extends MantineProviderProps {
3
+ saveColorScheme?: boolean;
4
+ }
5
+ export declare const DefaultApp: ({ children, saveColorScheme, defaultColorScheme, ...props }: Props) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,43 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { ColorSchemeScript, MantineProvider } from "@mantine/core";
3
+ import { HeadContent, Scripts } from "@tanstack/react-router";
4
+ import { getCookie } from "../functions/index.js";
5
+ import { AppDefaults } from "./AppDefaults.js";
6
+ import { cookieColorSchemeManager } from "./cookieColorSchemeManager.js";
7
+ import { defaultTheme } from "./defaultTheme.js";
8
+ const colorSchemeManager = cookieColorSchemeManager();
9
+ const DefaultApp = ({ children, saveColorScheme = true, defaultColorScheme = 'auto', ...props })=>{
10
+ const colorScheme = saveColorScheme ? getCookie('colorScheme', defaultColorScheme) : defaultColorScheme;
11
+ return /*#__PURE__*/ jsxs("html", {
12
+ lang: "ru",
13
+ suppressHydrationWarning: true,
14
+ children: [
15
+ /*#__PURE__*/ jsxs("head", {
16
+ children: [
17
+ /*#__PURE__*/ jsx(HeadContent, {}),
18
+ /*#__PURE__*/ jsx(ColorSchemeScript, {
19
+ defaultColorScheme: colorScheme
20
+ })
21
+ ]
22
+ }),
23
+ /*#__PURE__*/ jsxs("body", {
24
+ children: [
25
+ /*#__PURE__*/ jsxs(MantineProvider, {
26
+ defaultColorScheme: colorScheme,
27
+ theme: defaultTheme,
28
+ colorSchemeManager: colorSchemeManager,
29
+ ...props,
30
+ children: [
31
+ /*#__PURE__*/ jsx(AppDefaults, {
32
+ saveColorScheme: saveColorScheme
33
+ }),
34
+ children
35
+ ]
36
+ }),
37
+ /*#__PURE__*/ jsx(Scripts, {})
38
+ ]
39
+ })
40
+ ]
41
+ });
42
+ };
43
+ export { DefaultApp };
@@ -0,0 +1,6 @@
1
+ import { type MantineColorSchemeManager } from '@mantine/core';
2
+ export interface CookieColorSchemeManager {
3
+ /** Название куки, `colorScheme` по умолчанию */
4
+ key?: string;
5
+ }
6
+ export declare const cookieColorSchemeManager: ({ key, }?: CookieColorSchemeManager) => MantineColorSchemeManager;
@@ -0,0 +1,46 @@
1
+ import { isMantineColorScheme } from "@mantine/core";
2
+ import { atom } from "nanostores";
3
+ import { setCookie } from "../functions/index.js";
4
+ const $colorScheme = atom();
5
+ let unsubscribeSystemTheme;
6
+ const cookieColorSchemeManager = ({ key = 'colorScheme' } = {})=>({
7
+ get: (defaultValue)=>{
8
+ try {
9
+ return $colorScheme.get() || defaultValue;
10
+ } catch {
11
+ return defaultValue;
12
+ }
13
+ },
14
+ set: (value)=>{
15
+ try {
16
+ setCookie(key, value);
17
+ $colorScheme.set(value);
18
+ } catch (error) {
19
+ console.warn('[cookieColorSchemeManager] Ошибка при сохранении цветовой схемы в куки.', error);
20
+ }
21
+ },
22
+ subscribe: (onUpdate)=>{
23
+ $colorScheme.listen((newValue)=>{
24
+ if (isMantineColorScheme(newValue)) {
25
+ setCookie(key, newValue);
26
+ onUpdate(newValue);
27
+ }
28
+ });
29
+ const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
30
+ const handleSystemThemeChange = ()=>onUpdate('auto');
31
+ mediaQuery.addEventListener('change', handleSystemThemeChange);
32
+ unsubscribeSystemTheme = ()=>mediaQuery.removeEventListener('change', handleSystemThemeChange);
33
+ },
34
+ unsubscribe: ()=>{
35
+ $colorScheme.off();
36
+ if (unsubscribeSystemTheme) {
37
+ unsubscribeSystemTheme();
38
+ unsubscribeSystemTheme = void 0;
39
+ }
40
+ },
41
+ clear: ()=>{
42
+ setCookie(key);
43
+ $colorScheme.set(void 0);
44
+ }
45
+ });
46
+ export { cookieColorSchemeManager };
@@ -0,0 +1,4 @@
1
+ export declare const defaultRequestMiddlewares: import("@tanstack/start-client-core").RequestMiddlewareAfterServer<{}, undefined, {
2
+ locale: string;
3
+ timeZone: string;
4
+ }>[];
@@ -0,0 +1,24 @@
1
+ import { createMiddleware } from "@tanstack/react-start";
2
+ import { getCookie, getRequestHeader, setCookie } from "@tanstack/react-start/server";
3
+ const defaultRequestMiddlewares_locale = createMiddleware().server(async ({ next })=>{
4
+ const header = getRequestHeader('accept-language');
5
+ const headerLocale = header?.split(',')[0] || 'ru-RU';
6
+ const cookieLocale = getCookie('locale');
7
+ const cookieTz = getCookie('tz');
8
+ const locale = cookieLocale || headerLocale;
9
+ const timeZone = cookieTz || 'UTC';
10
+ setCookie('locale', locale, {
11
+ path: '/',
12
+ maxAge: 31536000
13
+ });
14
+ return next({
15
+ context: {
16
+ locale,
17
+ timeZone
18
+ }
19
+ });
20
+ });
21
+ const defaultRequestMiddlewares = [
22
+ defaultRequestMiddlewares_locale
23
+ ];
24
+ export { defaultRequestMiddlewares };
@@ -0,0 +1,141 @@
1
+ export declare const defaultTheme: {
2
+ focusRing?: "auto" | "always" | "never" | undefined;
3
+ scale?: number | undefined;
4
+ fontSmoothing?: boolean | undefined;
5
+ white?: string | undefined;
6
+ black?: string | undefined;
7
+ colors?: {
8
+ [x: string & {}]: import("@mantine/core").MantineColorsTuple | undefined;
9
+ dark?: import("@mantine/core").MantineColorsTuple | undefined;
10
+ blue?: import("@mantine/core").MantineColorsTuple | undefined;
11
+ cyan?: import("@mantine/core").MantineColorsTuple | undefined;
12
+ gray?: import("@mantine/core").MantineColorsTuple | undefined;
13
+ green?: import("@mantine/core").MantineColorsTuple | undefined;
14
+ indigo?: import("@mantine/core").MantineColorsTuple | undefined;
15
+ lime?: import("@mantine/core").MantineColorsTuple | undefined;
16
+ orange?: import("@mantine/core").MantineColorsTuple | undefined;
17
+ pink?: import("@mantine/core").MantineColorsTuple | undefined;
18
+ red?: import("@mantine/core").MantineColorsTuple | undefined;
19
+ teal?: import("@mantine/core").MantineColorsTuple | undefined;
20
+ violet?: import("@mantine/core").MantineColorsTuple | undefined;
21
+ yellow?: import("@mantine/core").MantineColorsTuple | undefined;
22
+ grape?: import("@mantine/core").MantineColorsTuple | undefined;
23
+ } | undefined;
24
+ primaryShade?: import("@mantine/core").MantineColorShade | {
25
+ light?: import("@mantine/core").MantineColorShade | undefined;
26
+ dark?: import("@mantine/core").MantineColorShade | undefined;
27
+ } | undefined;
28
+ primaryColor?: string | undefined;
29
+ variantColorResolver?: import("@mantine/core").VariantColorsResolver | undefined;
30
+ autoContrast?: boolean | undefined;
31
+ luminanceThreshold?: number | undefined;
32
+ fontFamily?: string | undefined;
33
+ fontFamilyMonospace?: string | undefined;
34
+ headings?: {
35
+ fontFamily?: string | undefined;
36
+ fontWeight?: string | undefined;
37
+ textWrap?: "balance" | "nowrap" | "wrap" | "stable" | "pretty" | undefined;
38
+ sizes?: {
39
+ h1?: {
40
+ fontSize?: string | undefined;
41
+ fontWeight?: string | undefined;
42
+ lineHeight?: string | undefined;
43
+ } | undefined;
44
+ h2?: {
45
+ fontSize?: string | undefined;
46
+ fontWeight?: string | undefined;
47
+ lineHeight?: string | undefined;
48
+ } | undefined;
49
+ h3?: {
50
+ fontSize?: string | undefined;
51
+ fontWeight?: string | undefined;
52
+ lineHeight?: string | undefined;
53
+ } | undefined;
54
+ h4?: {
55
+ fontSize?: string | undefined;
56
+ fontWeight?: string | undefined;
57
+ lineHeight?: string | undefined;
58
+ } | undefined;
59
+ h5?: {
60
+ fontSize?: string | undefined;
61
+ fontWeight?: string | undefined;
62
+ lineHeight?: string | undefined;
63
+ } | undefined;
64
+ h6?: {
65
+ fontSize?: string | undefined;
66
+ fontWeight?: string | undefined;
67
+ lineHeight?: string | undefined;
68
+ } | undefined;
69
+ } | undefined;
70
+ } | undefined;
71
+ radius?: {
72
+ [x: string & {}]: string | undefined;
73
+ xs?: string | undefined;
74
+ sm?: string | undefined;
75
+ md?: string | undefined;
76
+ lg?: string | undefined;
77
+ xl?: string | undefined;
78
+ } | undefined;
79
+ defaultRadius?: import("@mantine/core").MantineRadius | undefined;
80
+ spacing?: {
81
+ [x: number]: string | undefined;
82
+ [x: string & {}]: string | undefined;
83
+ xs?: string | undefined;
84
+ sm?: string | undefined;
85
+ md?: string | undefined;
86
+ lg?: string | undefined;
87
+ xl?: string | undefined;
88
+ } | undefined;
89
+ fontSizes?: {
90
+ [x: string & {}]: string | undefined;
91
+ xs?: string | undefined;
92
+ sm?: string | undefined;
93
+ md?: string | undefined;
94
+ lg?: string | undefined;
95
+ xl?: string | undefined;
96
+ } | undefined;
97
+ lineHeights?: {
98
+ [x: string & {}]: string | undefined;
99
+ xs?: string | undefined;
100
+ sm?: string | undefined;
101
+ md?: string | undefined;
102
+ lg?: string | undefined;
103
+ xl?: string | undefined;
104
+ } | undefined;
105
+ breakpoints?: {
106
+ [x: string & {}]: string | undefined;
107
+ xs?: string | undefined;
108
+ sm?: string | undefined;
109
+ md?: string | undefined;
110
+ lg?: string | undefined;
111
+ xl?: string | undefined;
112
+ } | undefined;
113
+ shadows?: {
114
+ [x: string & {}]: string | undefined;
115
+ xs?: string | undefined;
116
+ sm?: string | undefined;
117
+ md?: string | undefined;
118
+ lg?: string | undefined;
119
+ xl?: string | undefined;
120
+ } | undefined;
121
+ respectReducedMotion?: boolean | undefined;
122
+ cursorType?: "default" | "pointer" | undefined;
123
+ defaultGradient?: {
124
+ from?: string | undefined;
125
+ to?: string | undefined;
126
+ deg?: number | undefined;
127
+ } | undefined;
128
+ activeClassName?: string | undefined;
129
+ focusClassName?: string | undefined;
130
+ components?: {
131
+ [x: string]: {
132
+ classNames?: any;
133
+ styles?: any;
134
+ vars?: any;
135
+ defaultProps?: any;
136
+ } | undefined;
137
+ } | undefined;
138
+ other?: {
139
+ [x: string]: any;
140
+ } | undefined;
141
+ };
@@ -0,0 +1,24 @@
1
+ import { Modal, createTheme } from "@mantine/core";
2
+ const defaultTheme = createTheme({
3
+ components: {
4
+ Modal: Modal.extend({
5
+ defaultProps: {
6
+ centered: true,
7
+ padding: 'lg'
8
+ }
9
+ }),
10
+ ModalTitle: Modal.Title.extend({
11
+ defaultProps: {
12
+ pr: 24
13
+ }
14
+ }),
15
+ ModalCloseButton: Modal.CloseButton.extend({
16
+ defaultProps: {
17
+ pos: 'absolute',
18
+ top: 4,
19
+ right: 4
20
+ }
21
+ })
22
+ }
23
+ });
24
+ export { defaultTheme };
@@ -0,0 +1,3 @@
1
+ export * from './DefaultApp';
2
+ export * from './defaultRequestMiddlewares';
3
+ export * from './defaultTheme';
@@ -0,0 +1,3 @@
1
+ export * from "./DefaultApp.js";
2
+ export * from "./defaultRequestMiddlewares.js";
3
+ export * from "./defaultTheme.js";
@@ -0,0 +1,2 @@
1
+ export * from './useMutation';
2
+ export * from './useMutationWithInvalidate';
@@ -0,0 +1,2 @@
1
+ export * from "./useMutation.js";
2
+ export * from "./useMutationWithInvalidate.js";
@@ -0,0 +1,4 @@
1
+ import { type UseMutationOptions } from '@tanstack/react-query';
2
+ export declare const useMutation: <T, K = void>(fn: ({ data }: {
3
+ data: T;
4
+ }) => Promise<K>, options?: Omit<UseMutationOptions<K, Error, T>, "mutationFn">) => import("@tanstack/react-query").UseMutationResult<K, Error, T, unknown>;
@@ -0,0 +1,8 @@
1
+ import { useMutation } from "@tanstack/react-query";
2
+ const useMutation_useMutation = (fn, options)=>useMutation({
3
+ mutationFn: (data)=>fn({
4
+ data
5
+ }),
6
+ ...options
7
+ });
8
+ export { useMutation_useMutation as useMutation };
@@ -0,0 +1,4 @@
1
+ import { type UseMutationOptions } from '@tanstack/react-query';
2
+ export declare const useMutationWithInvalidate: <T, K = void>(fn: ({ data }: {
3
+ data: T;
4
+ }) => Promise<K>, queryKey: string[], options?: Omit<UseMutationOptions<K, Error, T>, "mutationFn" | "onSettled">) => import("@tanstack/react-query").UseMutationResult<K, Error, T, unknown>;
@@ -0,0 +1,16 @@
1
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
2
+ const useMutationWithInvalidate = (fn, queryKey, options)=>{
3
+ const queryClient = useQueryClient();
4
+ return useMutation({
5
+ mutationFn: (data)=>fn({
6
+ data
7
+ }),
8
+ onSettled: async (_, error)=>{
9
+ if (!error && queryKey.length) await queryClient.invalidateQueries({
10
+ queryKey
11
+ });
12
+ },
13
+ ...options
14
+ });
15
+ };
16
+ export { useMutationWithInvalidate };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
+ export * from './app';
1
2
  export * from './functions';
3
+ export * from './hooks';
4
+ export * from './surreal';
2
5
  export * from './ui';
package/dist/index.js CHANGED
@@ -1,2 +1,5 @@
1
+ export * from "./app/index.js";
1
2
  export * from "./functions/index.js";
3
+ export * from "./hooks/index.js";
4
+ export * from "./surreal/index.js";
2
5
  export * from "./ui/index.js";
@@ -0,0 +1,9 @@
1
+ import { type CodecOptions, Surreal } from 'surrealdb';
2
+ export declare const getDB: (params?: {
3
+ url?: string;
4
+ namespace?: string;
5
+ database?: string;
6
+ username?: string;
7
+ password?: string;
8
+ codecOptions?: CodecOptions;
9
+ } | undefined) => Promise<Surreal>;
@@ -0,0 +1,49 @@
1
+ import { createServerOnlyFn } from "@tanstack/react-start";
2
+ import { getCookie } from "@tanstack/react-start/server";
3
+ import { DateTime, Surreal } from "surrealdb";
4
+ let db = null;
5
+ const getDB = createServerOnlyFn(async (params = {})=>{
6
+ if (db?.isConnected) return db;
7
+ const locale = getCookie('locale') || 'ru-RU';
8
+ const timeZone = getCookie('tz') || 'UTC';
9
+ const instance = new Surreal({
10
+ codecOptions: params.codecOptions || {
11
+ valueDecodeVisitor (value) {
12
+ if (value instanceof DateTime) return new Date(value.toDate()).toLocaleDateString(locale, {
13
+ hour: 'numeric',
14
+ minute: 'numeric',
15
+ timeZone
16
+ });
17
+ return value;
18
+ }
19
+ }
20
+ });
21
+ try {
22
+ const url = params.url || process.env.SURREALDB_URL;
23
+ if (!url) throw new Error('Missing required SurrealDB URL');
24
+ const namespace = params.namespace || process.env.SURREALDB_NAMESPACE;
25
+ if (!namespace) throw new Error('Missing required SurrealDB namespace');
26
+ const database = params.database || process.env.SURREALDB_DATABASE;
27
+ if (!database) throw new Error('Missing required SurrealDB database');
28
+ const username = params.username || process.env.SURREALDB_USERNAME;
29
+ const password = params.password || process.env.SURREALDB_PASSWORD;
30
+ if (username && password) await instance.connect(url, {
31
+ authentication: {
32
+ username,
33
+ password
34
+ }
35
+ });
36
+ else await instance.connect(url);
37
+ await instance.use({
38
+ namespace,
39
+ database
40
+ });
41
+ db = instance;
42
+ return instance;
43
+ } catch (error) {
44
+ console.error('Failed to connect to SurrealDB:', error);
45
+ db = null;
46
+ throw error;
47
+ }
48
+ });
49
+ export { getDB };
@@ -0,0 +1,2 @@
1
+ export declare const surrealDeleteFn: import("@tanstack/start-client-core").RequiredFetcher<undefined, (data: string) => string, Promise<void>>;
2
+ export declare const surrealUnsubscribeFn: import("@tanstack/start-client-core").RequiredFetcher<undefined, (data: string) => string, Promise<void>>;
@@ -0,0 +1,18 @@
1
+ import { createServerFn } from "@tanstack/react-start";
2
+ import { getDB } from "./connection.js";
3
+ import { deserialize } from "./deserialize.js";
4
+ const surrealDeleteFn = createServerFn({
5
+ method: 'POST'
6
+ }).inputValidator((data)=>data).handler(async ({ data })=>{
7
+ const db = await getDB();
8
+ const id = deserialize(data);
9
+ await db.delete(id);
10
+ });
11
+ const surrealUnsubscribeFn = createServerFn({
12
+ method: 'POST'
13
+ }).inputValidator((data)=>data).handler(async ({ data })=>{
14
+ const db = await getDB();
15
+ const live = await db.liveOf(data);
16
+ await live.kill();
17
+ });
18
+ export { surrealDeleteFn, surrealUnsubscribeFn };
@@ -0,0 +1,17 @@
1
+ import { RecordId } from 'surrealdb';
2
+ /**
3
+ * Type that converts specified string paths to RecordId, others stay as their original types
4
+ */
5
+ type DeserializeResult<T, IdPaths extends string = never> = T extends string ? RecordId<string> : T extends (infer U)[] ? U extends object ? {
6
+ [K in keyof U]: K extends IdPaths ? RecordId<string> : U[K];
7
+ }[] : DeserializeResult<U, IdPaths>[] : T extends object ? T extends Date ? T : {
8
+ [K in keyof T]: K extends IdPaths ? RecordId<string> : T[K];
9
+ } : T;
10
+ /**
11
+ * Deserializes DTO back to SurrealDB Record recursively based on specified ID paths
12
+ */
13
+ export declare function deserialize<T, K extends keyof T & string>(dto: T[], idPaths: K[]): DeserializeResult<T, K>[];
14
+ export declare function deserialize<T, K extends keyof T & string>(dto: T, idPaths: K[]): DeserializeResult<T, K>;
15
+ export declare function deserialize<T>(dto: T[]): DeserializeResult<T>[];
16
+ export declare function deserialize<T>(dto: T): DeserializeResult<T>;
17
+ export {};
@@ -0,0 +1,46 @@
1
+ import { RecordId } from "surrealdb";
2
+ const extractTableName = (str)=>{
3
+ const match = str.match(/^([^:]+):/);
4
+ return match ? match[1] : null;
5
+ };
6
+ const isRecordIdFormat = (str)=>/^[^:]+:.+$/.test(str);
7
+ function deserialize(dto, idPaths) {
8
+ if (Array.isArray(dto)) return dto.map((item)=>convertStringsToRecordIds(item, idPaths || []));
9
+ return convertStringsToRecordIds(dto, idPaths || []);
10
+ }
11
+ const convertStringsToRecordIds = (obj, idPaths, currentPath = '')=>{
12
+ if (null == obj) return obj;
13
+ if (Array.isArray(obj)) {
14
+ if (idPaths.includes(currentPath)) return obj.map((item)=>{
15
+ if ('string' == typeof item && isRecordIdFormat(item)) {
16
+ const tableName = extractTableName(item);
17
+ if (tableName) return new RecordId(tableName, item.split(':')[1]);
18
+ }
19
+ return item;
20
+ });
21
+ return obj.map((item, index)=>convertStringsToRecordIds(item, idPaths, `${currentPath}[${index}]`));
22
+ }
23
+ if ('object' == typeof obj && !(obj instanceof Date)) {
24
+ const result = {};
25
+ for (const [key, value] of Object.entries(obj)){
26
+ const fieldPath = currentPath ? `${currentPath}.${key}` : key;
27
+ if ('string' == typeof value) {
28
+ const shouldConvert = idPaths.includes(fieldPath) && isRecordIdFormat(value);
29
+ if (shouldConvert) {
30
+ const tableName = extractTableName(value);
31
+ if (tableName) result[key] = new RecordId(tableName, value.split(':')[1]);
32
+ else result[key] = value;
33
+ } else result[key] = value;
34
+ } else result[key] = convertStringsToRecordIds(value, idPaths, fieldPath);
35
+ }
36
+ return result;
37
+ }
38
+ if ('string' == typeof obj) {
39
+ if (0 === idPaths.length && isRecordIdFormat(obj)) {
40
+ const tableName = extractTableName(obj);
41
+ if (tableName) return new RecordId(tableName, obj.split(':')[1]);
42
+ }
43
+ }
44
+ return obj;
45
+ };
46
+ export { deserialize };
@@ -0,0 +1,8 @@
1
+ declare class Encryption {
2
+ private key;
3
+ constructor(secretHash: string);
4
+ encrypt(text: string): string;
5
+ decrypt(encryptedText: string): string;
6
+ }
7
+ export declare const encryptionFn: (secretHash: string) => Encryption;
8
+ export {};
@@ -0,0 +1,28 @@
1
+ import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
2
+ import { createServerOnlyFn } from "@tanstack/react-start";
3
+ class Encryption {
4
+ key;
5
+ constructor(secretHash){
6
+ this.key = Buffer.from(secretHash, 'hex');
7
+ }
8
+ encrypt(text) {
9
+ const algorithm = 'aes-256-cbc';
10
+ const iv = randomBytes(16);
11
+ const cipher = createCipheriv(algorithm, this.key, iv);
12
+ let encrypted = cipher.update(text, 'utf8', 'hex');
13
+ encrypted += cipher.final('hex');
14
+ return `${iv.toString('hex')}:${encrypted}`;
15
+ }
16
+ decrypt(encryptedText) {
17
+ const algorithm = 'aes-256-cbc';
18
+ const parts = encryptedText.split(':');
19
+ const iv = Buffer.from(parts[0], 'hex');
20
+ const encrypted = parts[1];
21
+ const decipher = createDecipheriv(algorithm, this.key, iv);
22
+ let decrypted = decipher.update(encrypted, 'hex', 'utf8');
23
+ decrypted += decipher.final('utf8');
24
+ return decrypted;
25
+ }
26
+ }
27
+ const encryptionFn = createServerOnlyFn((secretHash)=>new Encryption(secretHash));
28
+ export { encryptionFn };
@@ -0,0 +1,4 @@
1
+ export { getDB } from './connection';
2
+ export * from './deafaultCrud';
3
+ export { deserialize } from './deserialize';
4
+ export { encryptionFn } from './encryption';
@@ -0,0 +1,5 @@
1
+ import { getDB } from "./connection.js";
2
+ import { deserialize } from "./deserialize.js";
3
+ import { encryptionFn } from "./encryption.js";
4
+ export * from "./deafaultCrud.js";
5
+ export { deserialize, encryptionFn, getDB };
@@ -0,0 +1,2 @@
1
+ import type { ErrorComponentProps } from '@tanstack/react-router';
2
+ export declare const DefaultError: ({ error }: ErrorComponentProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,62 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Button, Group, Stack, Title } from "@mantine/core";
3
+ import { rootRouteId, useMatch, useRouter } from "@tanstack/react-router";
4
+ import { RouterLink } from "../routerLink/index.js";
5
+ const DefaultError = ({ error })=>{
6
+ const router = useRouter();
7
+ const isRoot = useMatch({
8
+ strict: false,
9
+ select: (state)=>state.id === rootRouteId
10
+ });
11
+ return /*#__PURE__*/ jsxs(Stack, {
12
+ align: "center",
13
+ justify: "center",
14
+ gap: 0,
15
+ ta: "center",
16
+ h: "100vh",
17
+ children: [
18
+ /*#__PURE__*/ jsx(Title, {
19
+ textWrap: "balance",
20
+ size: 65,
21
+ children: "Произошла ошибка!"
22
+ }),
23
+ error.message && /*#__PURE__*/ jsx(Title, {
24
+ order: 3,
25
+ ml: 4,
26
+ textWrap: "balance",
27
+ c: "var(--mantine-color-error)",
28
+ children: error.message
29
+ }),
30
+ /*#__PURE__*/ jsxs(Group, {
31
+ children: [
32
+ /*#__PURE__*/ jsx(Button, {
33
+ mt: "xl",
34
+ size: "lg",
35
+ variant: "light",
36
+ onClick: ()=>{
37
+ router.invalidate();
38
+ },
39
+ children: "Попробовать еще раз"
40
+ }),
41
+ isRoot ? /*#__PURE__*/ jsx(RouterLink.Button, {
42
+ to: "/",
43
+ mt: "xl",
44
+ size: "lg",
45
+ radius: "md",
46
+ children: "На главную"
47
+ }) : /*#__PURE__*/ jsx(Button, {
48
+ mt: "xl",
49
+ radius: "md",
50
+ size: "lg",
51
+ onClick: (e)=>{
52
+ e.preventDefault();
53
+ router.history.back();
54
+ },
55
+ children: "Назад"
56
+ })
57
+ ]
58
+ })
59
+ ]
60
+ });
61
+ };
62
+ export { DefaultError };
@@ -0,0 +1 @@
1
+ export declare const DefaultNotFound: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,37 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Stack, Text, Title } from "@mantine/core";
3
+ import { RouterLink } from "../routerLink/index.js";
4
+ const DefaultNotFound = ()=>/*#__PURE__*/ jsxs(Stack, {
5
+ align: "center",
6
+ justify: "center",
7
+ gap: 0,
8
+ ta: "center",
9
+ h: "100vh",
10
+ children: [
11
+ /*#__PURE__*/ jsx(Text, {
12
+ c: "dimmed",
13
+ fw: "bold",
14
+ children: "404"
15
+ }),
16
+ /*#__PURE__*/ jsx(Title, {
17
+ textWrap: "balance",
18
+ size: 65,
19
+ children: "Страница не найдена"
20
+ }),
21
+ /*#__PURE__*/ jsx(Title, {
22
+ order: 3,
23
+ ml: 4,
24
+ textWrap: "balance",
25
+ c: "dimmed",
26
+ children: "Извините, но здесь нет страницы. Возможно она перемещена."
27
+ }),
28
+ /*#__PURE__*/ jsx(RouterLink.Button, {
29
+ to: "/",
30
+ mt: "xl",
31
+ size: "lg",
32
+ radius: "md",
33
+ children: "На главную"
34
+ })
35
+ ]
36
+ });
37
+ export { DefaultNotFound };
@@ -0,0 +1 @@
1
+ export declare const defaultErrorNotification: (error: Error) => string;
@@ -0,0 +1,8 @@
1
+ import { notifications } from "@mantine/notifications";
2
+ const defaultErrorNotification = (error)=>notifications.show({
3
+ title: 'Системная ошибка',
4
+ message: error.message,
5
+ color: 'red',
6
+ autoClose: false
7
+ });
8
+ export { defaultErrorNotification };
@@ -0,0 +1,3 @@
1
+ export * from './DefaultError';
2
+ export * from './DefaultNotFound';
3
+ export * from './defaultErrorNotification';
@@ -0,0 +1,3 @@
1
+ export * from "./DefaultError.js";
2
+ export * from "./DefaultNotFound.js";
3
+ export * from "./defaultErrorNotification.js";
@@ -1,7 +1,7 @@
1
1
  export * from './AnimatedChevron';
2
2
  export * from './editor';
3
+ export * from './error';
3
4
  export * from './form';
4
- export * from './hoverActionIcon';
5
5
  export * from './hoverPaper';
6
6
  export * from './JsonInput';
7
7
  export * from './routerLink';
package/dist/ui/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export * from "./AnimatedChevron.js";
2
2
  export * from "./editor/index.js";
3
+ export * from "./error/index.js";
3
4
  export * from "./form/index.js";
4
- export * from "./hoverActionIcon/index.js";
5
5
  export * from "./hoverPaper/index.js";
6
6
  export * from "./JsonInput.js";
7
7
  export * from "./routerLink/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolder/kit",
3
- "version": "3.0.0-alpha-4",
3
+ "version": "3.0.0-alpha-5",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -18,7 +18,7 @@
18
18
  "check": "biome check --write && tsc --noEmit"
19
19
  },
20
20
  "devDependencies": {
21
- "@biomejs/biome": "2.3.8",
21
+ "@biomejs/biome": "2.3.11",
22
22
  "@rsbuild/plugin-react": "^1.4.2",
23
23
  "@rslib/core": "^0.19.2",
24
24
  "@types/react": "^19.2.8",
@@ -46,11 +46,15 @@
46
46
  "@mantine/core": "^8.3.11",
47
47
  "@mantine/hooks": "^8.3.11",
48
48
  "@mantine/tiptap": "^8.3.11",
49
+ "@mantine/notifications": "^8.3.11",
49
50
  "@tanstack/react-router": "1.147.3",
50
51
  "@tanstack/react-form": "1.27.7",
51
52
  "@tanstack/react-start": "^1.149.1",
53
+ "@tanstack/react-query": "^5.90.16",
52
54
  "zod": "^4.3.5",
53
- "js-cookie": "^3.0.5"
55
+ "js-cookie": "^3.0.5",
56
+ "nanostores": "^1.1.0",
57
+ "surrealdb": "^2.0.0-alpha.16"
54
58
  },
55
59
  "trustedDependencies": [
56
60
  "core-js",
@@ -1,6 +0,0 @@
1
- import { type ActionIconProps, type ElementProps } from '@mantine/core';
2
- interface Props extends ActionIconProps, ElementProps<'button', keyof ActionIconProps> {
3
- hovered?: boolean;
4
- }
5
- export declare const HoverActionIcon: ({ hovered, classNames, ...props }: Props) => import("react/jsx-runtime").JSX.Element;
6
- export {};
@@ -1,14 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { ActionIcon } from "@mantine/core";
3
- import styles_module from "./styles.module.js";
4
- const HoverActionIcon = ({ hovered, classNames, ...props })=>/*#__PURE__*/ jsx(ActionIcon, {
5
- classNames: {
6
- root: styles_module.root,
7
- ...classNames
8
- },
9
- mod: {
10
- hovered
11
- },
12
- ...props
13
- });
14
- export { HoverActionIcon };
@@ -1 +0,0 @@
1
- export * from './HoverActionIcon';
@@ -1 +0,0 @@
1
- export * from "./HoverActionIcon.js";
@@ -1,5 +0,0 @@
1
- import "./styles_module.css";
2
- const styles_module = {
3
- root: "root-Ao1xe7"
4
- };
5
- export { styles_module as default };
@@ -1,10 +0,0 @@
1
- .root-Ao1xe7 {
2
- opacity: 0;
3
- transition: opacity .2s ease-in-out;
4
-
5
- &[data-hovered] {
6
- opacity: 1;
7
- transition: opacity .2s ease-in-out;
8
- }
9
- }
10
-