@hywax/cms 0.0.3 → 0.0.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.
Files changed (41) hide show
  1. package/.nuxt/cms/http-codes.ts +8 -0
  2. package/dist/module.d.mts +22 -13
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +110 -34
  5. package/dist/runtime/plugins/api.js +1 -4
  6. package/dist/runtime/server/errors/InternalHttpError.d.ts +4 -0
  7. package/dist/runtime/server/errors/InternalHttpError.js +6 -0
  8. package/dist/runtime/server/errors/TimeoutError.d.ts +2 -0
  9. package/dist/runtime/server/errors/TimeoutError.js +2 -0
  10. package/dist/runtime/server/errors/index.d.ts +2 -0
  11. package/dist/runtime/server/errors/index.js +2 -0
  12. package/dist/runtime/server/types/errors.d.ts +8 -0
  13. package/dist/runtime/server/types/errors.js +0 -0
  14. package/dist/runtime/server/types/index.d.ts +1 -0
  15. package/dist/runtime/server/types/index.js +1 -0
  16. package/dist/runtime/server/utils/errors.d.ts +8 -0
  17. package/dist/runtime/server/utils/errors.js +57 -0
  18. package/dist/runtime/server/utils/httpHandler.d.ts +10 -0
  19. package/dist/runtime/server/utils/httpHandler.js +15 -0
  20. package/dist/runtime/server/utils/pagination.d.ts +11 -0
  21. package/dist/runtime/server/utils/pagination.js +12 -0
  22. package/dist/runtime/server/utils/timeout.d.ts +7 -0
  23. package/dist/runtime/server/utils/timeout.js +9 -0
  24. package/dist/runtime/server/utils/validation.d.ts +3 -0
  25. package/dist/runtime/server/utils/validation.js +26 -0
  26. package/dist/runtime/types/index.d.ts +1 -0
  27. package/dist/runtime/types/index.js +1 -0
  28. package/dist/runtime/types/query.d.ts +20 -0
  29. package/dist/runtime/types/query.js +0 -0
  30. package/dist/runtime/types/utils.d.ts +4 -1
  31. package/dist/runtime/utils/avatar.d.ts +1 -0
  32. package/dist/runtime/utils/avatar.js +9 -0
  33. package/dist/runtime/utils/dictionaries.d.ts +4 -0
  34. package/dist/runtime/utils/dictionaries.js +6 -0
  35. package/dist/runtime/utils/image.js +1 -1
  36. package/dist/runtime/utils/index.d.ts +3 -0
  37. package/dist/runtime/utils/index.js +3 -0
  38. package/dist/runtime/utils/slugify.d.ts +1 -0
  39. package/dist/runtime/utils/slugify.js +12 -0
  40. package/dist/types.d.mts +6 -2
  41. package/package.json +8 -3
@@ -0,0 +1,8 @@
1
+ export const HTTP_CODE_BAD_REQUEST = '400: Неверный запрос'
2
+ export const HTTP_CODE_UNAUTHORIZED = '401: Не авторизован'
3
+ export const HTTP_CODE_FORBIDDEN = '403: Доступ запрещен'
4
+ export const HTTP_CODE_NOT_FOUND = '404: Не найдено'
5
+ export const HTTP_CODE_REQUEST_TIMEOUT = '408: Время ожидания запроса истекло'
6
+ export const HTTP_CODE_INTERNAL_SERVER_ERROR = '500: Внутренняя ошибка сервера'
7
+ export const HTTP_CODE_BAD_GATEWAY = '502: Ошибка шлюза'
8
+ export const HTTP_CODE_SERVICE_UNAVAILABLE = '503: Сервис недоступен'
package/dist/module.d.mts CHANGED
@@ -1,17 +1,7 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
  export * from '../dist/runtime/types/index.js';
3
3
 
4
- declare module '@nuxt/schema' {
5
- interface ConfigSchema {
6
- public?: {
7
- cms: {
8
- fluxorUrl: string;
9
- };
10
- };
11
- }
12
- }
13
-
14
- interface ModuleOptions {
4
+ interface CMSOptions {
15
5
  /**
16
6
  * Name of the module
17
7
  * @defaultValue 'cms'
@@ -27,8 +17,27 @@ interface ModuleOptions {
27
17
  * @defaultValue 'https://fluxor.uplora.ru'
28
18
  */
29
19
  fluxorUrl?: string;
20
+ /**
21
+ * Prefix for the environment variables
22
+ * @defaultValue 'APP_'
23
+ */
24
+ envPrefix?: string;
25
+ /**
26
+ * HTTP codes
27
+ * @defaultValue {}
28
+ */
29
+ httpCodes?: Record<string, string>;
30
30
  }
31
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
31
+
32
+ declare module '@nuxt/schema' {
33
+ interface ConfigSchema {
34
+ public?: {
35
+ fluxorUrl: string;
36
+ version: string;
37
+ };
38
+ }
39
+ }
40
+
41
+ declare const _default: _nuxt_schema.NuxtModule<CMSOptions, CMSOptions, false>;
32
42
 
33
43
  export { _default as default };
34
- export type { ModuleOptions };
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hywax/cms",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "configKey": "cms",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
package/dist/module.mjs CHANGED
@@ -1,10 +1,75 @@
1
- import { addTypeTemplate, addTemplate, defineNuxtModule, hasNuxtModule, installModule, createResolver, addComponentsDir, addImportsDir, addPlugin } from '@nuxt/kit';
1
+ import { createResolver, addComponentsDir, addImportsDir, addPlugin, addImports, addServerImports, addServerImportsDir, addTypeTemplate, addTemplate, addServerTemplate, defineNuxtModule, hasNuxtModule, installModule } from '@nuxt/kit';
2
2
  import { defu } from 'defu';
3
- import 'node:url';
4
- import { kebabCase } from 'scule';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { dirname } from 'pathe';
5
+ import { snakeCase, kebabCase } from 'scule';
5
6
 
6
7
  const name = "@hywax/cms";
7
- const version = "0.0.3";
8
+ const version = "0.0.4";
9
+
10
+ function createContext(options, nuxt) {
11
+ const { resolve } = createResolver(import.meta.url);
12
+ const distDir = dirname(fileURLToPath(import.meta.url));
13
+ const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
14
+ return {
15
+ options,
16
+ resolve,
17
+ distDir,
18
+ runtimeDir,
19
+ nuxt
20
+ };
21
+ }
22
+
23
+ function getDefaultCMSConfig() {
24
+ return {};
25
+ }
26
+ const defaultModuleOptions = {
27
+ name: "cms",
28
+ prefix: "C",
29
+ fluxorUrl: "https://fluxor.uplora.ru",
30
+ envPrefix: "APP_",
31
+ httpCodes: {
32
+ badRequest: "400: \u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0437\u0430\u043F\u0440\u043E\u0441",
33
+ unauthorized: "401: \u041D\u0435 \u0430\u0432\u0442\u043E\u0440\u0438\u0437\u043E\u0432\u0430\u043D",
34
+ forbidden: "403: \u0414\u043E\u0441\u0442\u0443\u043F \u0437\u0430\u043F\u0440\u0435\u0449\u0435\u043D",
35
+ notFound: "404: \u041D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E",
36
+ requestTimeout: "408: \u0412\u0440\u0435\u043C\u044F \u043E\u0436\u0438\u0434\u0430\u043D\u0438\u044F \u0437\u0430\u043F\u0440\u043E\u0441\u0430 \u0438\u0441\u0442\u0435\u043A\u043B\u043E",
37
+ internalServerError: "500: \u0412\u043D\u0443\u0442\u0440\u0435\u043D\u043D\u044F\u044F \u043E\u0448\u0438\u0431\u043A\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430",
38
+ badGateway: "502: \u041E\u0448\u0438\u0431\u043A\u0430 \u0448\u043B\u044E\u0437\u0430",
39
+ serviceUnavailable: "503: \u0421\u0435\u0440\u0432\u0438\u0441 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D"
40
+ }
41
+ };
42
+
43
+ function transformHttpCodes(httpCodes) {
44
+ return Object.entries(httpCodes).map(([code, value]) => ({
45
+ code: `HTTP_CODE_${snakeCase(code).toUpperCase()}`,
46
+ value
47
+ }));
48
+ }
49
+
50
+ function prepareAutoImports({ resolve, options, nuxt }) {
51
+ const httpCodesPath = resolve(nuxt.options.buildDir, "cms/http-codes.ts");
52
+ const httpCodesImports = transformHttpCodes(options.httpCodes).map(({ code }) => ({ name: code, from: httpCodesPath }));
53
+ addComponentsDir({
54
+ path: resolve("./runtime/components"),
55
+ pathPrefix: false,
56
+ prefix: options?.prefix,
57
+ ignore: ["prose/**"]
58
+ });
59
+ addComponentsDir({
60
+ path: resolve("./runtime/components/prose"),
61
+ prefix: "Prose",
62
+ pathPrefix: false,
63
+ global: true
64
+ });
65
+ addImportsDir(resolve("./runtime/composables"));
66
+ addPlugin(resolve("./runtime/plugins/api.ts"));
67
+ addImports(httpCodesImports);
68
+ addServerImports(httpCodesImports);
69
+ addServerImportsDir(resolve("./runtime/server/utils"));
70
+ nuxt.options.nitro.alias ||= {};
71
+ nuxt.options.nitro.alias["#cms/http-codes"] = httpCodesPath;
72
+ }
8
73
 
9
74
  const buttonClear = {
10
75
  slots: {
@@ -38,7 +103,7 @@ const themeProse = {
38
103
  uploraImage: uploraImage
39
104
  };
40
105
 
41
- function getTemplates(options) {
106
+ function getAppTemplates({ options }) {
42
107
  const templates = [];
43
108
  function writeThemeTemplate(theme2, path) {
44
109
  for (const component in theme2) {
@@ -97,8 +162,11 @@ function getTemplates(options) {
97
162
  filename: "types/cms.d.ts",
98
163
  getContents: () => `import * as cms from '#build/cms'
99
164
  import type { TVConfig } from '@nuxt/ui'
165
+ import type { RouteLocationRaw } from 'vue-router'
166
+
167
+ type AppConfigCMS = {
100
168
 
101
- type AppConfigCMS = TVConfig<typeof cms>
169
+ } & TVConfig<typeof cms>
102
170
 
103
171
  declare module '@nuxt/schema' {
104
172
  interface AppConfigInput {
@@ -112,17 +180,39 @@ declare module '@nuxt/schema' {
112
180
  export {}
113
181
  `
114
182
  });
183
+ templates.push({
184
+ filename: "cms/http-codes.ts",
185
+ write: true,
186
+ getContents: () => {
187
+ const httpCodes = transformHttpCodes(options.httpCodes);
188
+ const content = httpCodes.map(({ code, value }) => `export const ${code} = '${value}'`).join("\n");
189
+ return `${content}
190
+ `;
191
+ }
192
+ });
193
+ return templates;
194
+ }
195
+ function getServerTemplates(_context) {
196
+ const templates = [];
115
197
  return templates;
116
198
  }
117
- function addTemplates(options) {
118
- const templates = getTemplates(options);
119
- for (const template of templates) {
199
+ function prepareTemplates(context) {
200
+ const appTemplates = getAppTemplates(context);
201
+ const serverTemplates = getServerTemplates();
202
+ for (const template of appTemplates) {
120
203
  if (template.filename.endsWith(".d.ts")) {
121
204
  addTypeTemplate(template);
122
205
  } else {
123
206
  addTemplate(template);
124
207
  }
125
208
  }
209
+ for (const template of serverTemplates) {
210
+ if (template.filename.endsWith(".d.ts")) {
211
+ addTypeTemplate(template, { nitro: true, nuxt: false });
212
+ } else {
213
+ addServerTemplate(template);
214
+ }
215
+ }
126
216
  }
127
217
 
128
218
  const icons = {};
@@ -133,15 +223,15 @@ const module = defineNuxtModule({
133
223
  version,
134
224
  configKey: "cms"
135
225
  },
136
- defaults: {
137
- name: "cms",
138
- prefix: "C",
139
- fluxorUrl: "https://fluxor.uplora.ru"
140
- },
226
+ defaults: defaultModuleOptions,
141
227
  async setup(options, nuxt) {
142
- nuxt.options.runtimeConfig.public.cms = defu(nuxt.options.runtimeConfig.public.cms || {}, {
143
- fluxorUrl: options.fluxorUrl
228
+ const context = createContext(options, nuxt);
229
+ nuxt.options.runtimeConfig.public = defu(nuxt.options.runtimeConfig.public || {}, {
230
+ fluxorUrl: options.fluxorUrl,
231
+ version: ""
144
232
  });
233
+ nuxt.options.runtimeConfig.nitro ||= {};
234
+ nuxt.options.runtimeConfig.nitro.envPrefix = options.envPrefix;
145
235
  nuxt.options.appConfig.ui = defu(nuxt.options.appConfig.ui || {}, {
146
236
  icons
147
237
  });
@@ -174,24 +264,10 @@ const module = defineNuxtModule({
174
264
  if (!hasNuxtModule("nuxt-auth-utils")) {
175
265
  await installModule("nuxt-auth-utils");
176
266
  }
177
- const { resolve } = createResolver(import.meta.url);
178
- nuxt.options.alias["#cms"] = resolve("./runtime");
179
- nuxt.options.appConfig.cms = defu(nuxt.options.appConfig.cms || {}, {});
180
- addComponentsDir({
181
- path: resolve("./runtime/components"),
182
- pathPrefix: false,
183
- prefix: options?.prefix || "C",
184
- ignore: ["prose/**"]
185
- });
186
- addComponentsDir({
187
- path: resolve("./runtime/components/prose"),
188
- prefix: "Prose",
189
- pathPrefix: false,
190
- global: true
191
- });
192
- addImportsDir(resolve("./runtime/composables"));
193
- addTemplates(options);
194
- addPlugin(resolve("./runtime/plugins/api.ts"));
267
+ nuxt.options.alias["#cms"] = context.resolve("./runtime");
268
+ nuxt.options.appConfig.cms = defu(nuxt.options.appConfig.cms || {}, getDefaultCMSConfig());
269
+ prepareAutoImports(context);
270
+ prepareTemplates(context);
195
271
  }
196
272
  });
197
273
 
@@ -1,4 +1,4 @@
1
- import { defineNuxtPlugin, navigateTo, useAppConfig, useToast } from "#imports";
1
+ import { defineNuxtPlugin, useAppConfig, useToast } from "#imports";
2
2
  export default defineNuxtPlugin({
3
3
  name: "cms-api",
4
4
  async setup() {
@@ -12,9 +12,6 @@ export default defineNuxtPlugin({
12
12
  color: "error",
13
13
  icon: appConfig.ui.icons.close
14
14
  });
15
- if (response.status === 401) {
16
- await navigateTo({ name: "index" });
17
- }
18
15
  }
19
16
  });
20
17
  return {
@@ -0,0 +1,4 @@
1
+ export declare class InternalHttpError extends Error {
2
+ httpCodeString: string;
3
+ constructor(httpCodeString: string);
4
+ }
@@ -0,0 +1,6 @@
1
+ export class InternalHttpError extends Error {
2
+ constructor(httpCodeString) {
3
+ super("Internal Error");
4
+ this.httpCodeString = httpCodeString;
5
+ }
6
+ }
@@ -0,0 +1,2 @@
1
+ export declare class TimeoutError extends Error {
2
+ }
@@ -0,0 +1,2 @@
1
+ export class TimeoutError extends Error {
2
+ }
@@ -0,0 +1,2 @@
1
+ export * from './InternalHttpError';
2
+ export * from './TimeoutError';
@@ -0,0 +1,2 @@
1
+ export * from "./InternalHttpError.js";
2
+ export * from "./TimeoutError.js";
@@ -0,0 +1,8 @@
1
+ export type ErrorMapCodes = Record<string, string>;
2
+ export interface CustomError {
3
+ statusCode: number;
4
+ message: string;
5
+ data?: {
6
+ [key: string]: unknown;
7
+ };
8
+ }
File without changes
@@ -0,0 +1 @@
1
+ export * from './errors';
@@ -0,0 +1 @@
1
+ export * from "./errors.js";
@@ -0,0 +1,8 @@
1
+ import type { CustomError, ErrorMapCodes } from '../types';
2
+ import { H3Error } from 'h3';
3
+ import { InternalHttpError } from '../errors';
4
+ export declare function parseErrorString(errorString: string): CustomError;
5
+ export declare function errorServerResolver(error: unknown, errorMap?: ErrorMapCodes): H3Error<{
6
+ [key: string]: unknown;
7
+ }>;
8
+ export declare function createServerError(errorString: string): InternalHttpError;
@@ -0,0 +1,57 @@
1
+ import { HTTP_CODE_BAD_REQUEST, HTTP_CODE_INTERNAL_SERVER_ERROR, HTTP_CODE_REQUEST_TIMEOUT, HTTP_CODE_UNAUTHORIZED } from "#cms/http-codes";
2
+ import { consola } from "consola";
3
+ import { defu } from "defu";
4
+ import { createError, H3Error } from "h3";
5
+ import { z } from "zod";
6
+ import { InternalHttpError, TimeoutError } from "../errors/index.js";
7
+ const defaultHttpCodes = {
8
+ DEFAULT: HTTP_CODE_INTERNAL_SERVER_ERROR,
9
+ ZOD: HTTP_CODE_BAD_REQUEST,
10
+ DB: HTTP_CODE_INTERNAL_SERVER_ERROR,
11
+ ERROR_UNAUTHORIZED: HTTP_CODE_UNAUTHORIZED,
12
+ TIMEOUT: HTTP_CODE_REQUEST_TIMEOUT
13
+ };
14
+ function extractHttpCodeString(error, errorMap = {}) {
15
+ errorMap = defu(errorMap, defaultHttpCodes);
16
+ if (error instanceof InternalHttpError) {
17
+ return error.httpCodeString;
18
+ } else if (error instanceof z.ZodError) {
19
+ return errorMap.ZOD;
20
+ } else if (error instanceof TimeoutError) {
21
+ return errorMap.TIMEOUT;
22
+ } else if (error instanceof H3Error && error.cause instanceof InternalHttpError) {
23
+ return error.cause.httpCodeString;
24
+ } else if (error instanceof Error) {
25
+ if ("query" in error && "params" in error && Array.isArray(error.params)) {
26
+ const errorMaybeCode2 = `DB_${error.cause?.code}`;
27
+ return errorMap[errorMaybeCode2] ?? errorMap.DB;
28
+ }
29
+ const normalizedMessage = error.message.trim().replaceAll(" ", "_").toUpperCase();
30
+ const errorMaybeCode = `ERROR_${normalizedMessage}`;
31
+ return errorMap[errorMaybeCode] ?? errorMap.DEFAULT;
32
+ }
33
+ return errorMap.DEFAULT;
34
+ }
35
+ export function parseErrorString(errorString) {
36
+ const [code, message] = errorString.split(":");
37
+ if (!code || !message) {
38
+ throw new Error("Invalid error string");
39
+ }
40
+ return {
41
+ statusCode: Number.parseInt(code, 10),
42
+ message: message.trim()
43
+ };
44
+ }
45
+ export function errorServerResolver(error, errorMap) {
46
+ const httpCodeString = extractHttpCodeString(error, errorMap);
47
+ const parsedHttpCode = parseErrorString(httpCodeString);
48
+ consola.error({
49
+ code: parsedHttpCode.statusCode,
50
+ message: parsedHttpCode.message,
51
+ error
52
+ });
53
+ return createError(parsedHttpCode);
54
+ }
55
+ export function createServerError(errorString) {
56
+ return new InternalHttpError(errorString);
57
+ }
@@ -0,0 +1,10 @@
1
+ import type { EventHandler, EventHandlerRequest, EventHandlerResponse } from 'h3';
2
+ import type { ErrorMapCodes } from '../types';
3
+ export interface EventHandlerOptions {
4
+ errorMap?: ErrorMapCodes;
5
+ }
6
+ /**
7
+ * Функция для определения обработчика HTTP-запросов.
8
+ * Обрабатывает, H3-обработчик и ловит, обрабатывает ошибки.
9
+ */
10
+ export declare function defineHttpHandler<Request extends EventHandlerRequest, Response extends EventHandlerResponse>(handler: EventHandler<Request, Response | Promise<Response>>, options?: EventHandlerOptions): EventHandler<Request, Promise<Response>>;
@@ -0,0 +1,15 @@
1
+ import { eventHandler } from "h3";
2
+ import { errorServerResolver } from "./errors.js";
3
+ export function defineHttpHandler(handler, options) {
4
+ return eventHandler(async (event) => {
5
+ try {
6
+ return await handler(event);
7
+ } catch (e) {
8
+ let error = e;
9
+ if (error.cause?.data instanceof Error) {
10
+ error = error.cause?.data;
11
+ }
12
+ throw errorServerResolver(error, options?.errorMap);
13
+ }
14
+ });
15
+ }
@@ -0,0 +1,11 @@
1
+ import type { KeysMatching, Pagination } from '../../types';
2
+ export declare function extractPaginationData<T extends {
3
+ total: number;
4
+ }>(data: T[]): {
5
+ items: Omit<T, 'total'>[];
6
+ pagination: Pagination;
7
+ };
8
+ export declare function extractPaginationData<T extends object, K extends KeysMatching<T, number>>(data: T[], key: K): {
9
+ items: Omit<T, K>[];
10
+ pagination: Pagination;
11
+ };
@@ -0,0 +1,12 @@
1
+ export function extractPaginationData(data, key) {
2
+ if (!data.length) {
3
+ return { items: [], pagination: { total: 0 } };
4
+ }
5
+ const totalKey = key ?? "total";
6
+ const total = Number(data[0]?.[totalKey]) || 0;
7
+ const items = data.map(({ [totalKey]: _, ...item }) => item);
8
+ return {
9
+ items,
10
+ pagination: { total }
11
+ };
12
+ }
@@ -0,0 +1,7 @@
1
+ import { TimeoutError } from '../errors/TimeoutError';
2
+ interface TryWithTimeoutOptions {
3
+ timeout?: number;
4
+ timeoutMessage?: string;
5
+ }
6
+ export declare function tryWithTimeout<T>(promise: Promise<T>, options: TryWithTimeoutOptions): Promise<T | TimeoutError>;
7
+ export {};
@@ -0,0 +1,9 @@
1
+ import { TimeoutError } from "../errors/TimeoutError.js";
2
+ export function tryWithTimeout(promise, options) {
3
+ return Promise.race([
4
+ promise,
5
+ new Promise(
6
+ (_, reject) => setTimeout(() => reject(new TimeoutError(options?.timeoutMessage)), options?.timeout ?? 1e3)
7
+ )
8
+ ]);
9
+ }
@@ -0,0 +1,3 @@
1
+ import type { PaginationQuery, PaginationQueryRaw, SortQuery, SortQueryRaw } from '../../types';
2
+ export declare function getValidatedSort<T extends string[]>(query: SortQueryRaw, availableColumns: readonly [...T]): SortQuery<T[number]>;
3
+ export declare function getValidatedPagination(query: PaginationQueryRaw): PaginationQuery;
@@ -0,0 +1,26 @@
1
+ import { HTTP_CODE_BAD_REQUEST } from "#cms/http-codes";
2
+ import { InternalHttpError } from "../errors/InternalHttpError.js";
3
+ export function getValidatedSort(query, availableColumns) {
4
+ if (!query.sortColumn || !availableColumns.includes(query.sortColumn)) {
5
+ throw new InternalHttpError(HTTP_CODE_BAD_REQUEST);
6
+ }
7
+ const sortType = query.sortType === "asc" ? "asc" : "desc";
8
+ const sortColumn = query.sortColumn;
9
+ return {
10
+ sortType,
11
+ sortColumn
12
+ };
13
+ }
14
+ export function getValidatedPagination(query) {
15
+ const perPage = Number(query.perPage);
16
+ if (!Number.isInteger(perPage) || perPage < 1 || perPage > 100) {
17
+ throw new InternalHttpError(HTTP_CODE_BAD_REQUEST);
18
+ }
19
+ const page = Number(query.page) || 1;
20
+ const pageOffset = (page - 1) * perPage;
21
+ return {
22
+ page,
23
+ perPage,
24
+ pageOffset
25
+ };
26
+ }
@@ -1,5 +1,6 @@
1
1
  export * from '../components/ButtonClear.vue';
2
2
  export * from '../components/UploraImage.vue';
3
3
  export * from './image';
4
+ export * from './query';
4
5
  export * from './seo';
5
6
  export * from './utils';
@@ -1,5 +1,6 @@
1
1
  export * from "../components/ButtonClear.vue";
2
2
  export * from "../components/UploraImage.vue";
3
3
  export * from "./image.js";
4
+ export * from "./query.js";
4
5
  export * from "./seo.js";
5
6
  export * from "./utils.js";
@@ -0,0 +1,20 @@
1
+ export interface SortQueryRaw {
2
+ sortColumn?: string;
3
+ sortType?: string;
4
+ }
5
+ export interface SortQuery<K = string> {
6
+ sortColumn: K;
7
+ sortType: 'asc' | 'desc';
8
+ }
9
+ export interface Pagination {
10
+ total: number;
11
+ }
12
+ export interface PaginationQueryRaw {
13
+ page?: string;
14
+ perPage?: string;
15
+ }
16
+ export interface PaginationQuery {
17
+ page: number;
18
+ perPage: number;
19
+ pageOffset: number;
20
+ }
File without changes
@@ -1,3 +1,6 @@
1
1
  import type { AcceptableValue as _AcceptableValue } from 'reka-ui';
2
- export type AcceptableValue = Exclude<_AcceptableValue, Record<string, any>>;
3
2
  export * from './tv';
3
+ export type AcceptableValue = Exclude<_AcceptableValue, Record<string, any>>;
4
+ export type KeysMatching<T, V> = {
5
+ [K in keyof T]: T[K] extends V ? K : never;
6
+ }[keyof T];
@@ -0,0 +1 @@
1
+ export declare function createAvatarByName(name?: string): string;
@@ -0,0 +1,9 @@
1
+ import { initials } from "@dicebear/collection";
2
+ import { createAvatar } from "@dicebear/core";
3
+ export function createAvatarByName(name = "Anonymous") {
4
+ const avatar = createAvatar(initials, {
5
+ seed: name,
6
+ backgroundType: ["gradientLinear"]
7
+ });
8
+ return avatar.toDataUri();
9
+ }
@@ -0,0 +1,4 @@
1
+ export declare function labelsToDictionary<T extends Record<any, string>>(labels: T): Array<{
2
+ value: T[keyof T];
3
+ label: string;
4
+ }>;
@@ -0,0 +1,6 @@
1
+ export function labelsToDictionary(labels) {
2
+ return Object.entries(labels).map(([value, label]) => ({
3
+ value,
4
+ label
5
+ }));
6
+ }
@@ -3,7 +3,7 @@ import { imagesExtensionsToMimeTypes } from "@uplora/formats";
3
3
  import { serialize } from "@uplora/serializer";
4
4
  export function createUploraImageResolver() {
5
5
  const runtimeConfig = useRuntimeConfig();
6
- const { fluxorUrl } = runtimeConfig.public.cms;
6
+ const { fluxorUrl } = runtimeConfig.public;
7
7
  return (id, filters) => {
8
8
  const serializeFilters = filters ? serialize(filters) : "";
9
9
  return `${fluxorUrl}/${id}${serializeFilters ? `/${serializeFilters}` : ""}`;
@@ -1 +1,4 @@
1
+ export * from './avatar';
2
+ export * from './dictionaries';
1
3
  export * from './image';
4
+ export * from './slugify';
@@ -1 +1,4 @@
1
+ export * from "./avatar.js";
2
+ export * from "./dictionaries.js";
1
3
  export * from "./image.js";
4
+ export * from "./slugify.js";
@@ -0,0 +1 @@
1
+ export declare function slugify(text?: string): string;
@@ -0,0 +1,12 @@
1
+ import baseSlugify from "slugify";
2
+ export function slugify(text) {
3
+ if (!text) {
4
+ return "";
5
+ }
6
+ return baseSlugify(text, {
7
+ lower: true,
8
+ strict: true,
9
+ locale: "ru",
10
+ trim: true
11
+ });
12
+ }
package/dist/types.d.mts CHANGED
@@ -1,5 +1,9 @@
1
- export { default } from './module.mjs'
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module.mjs'
2
4
 
3
- export { type ModuleOptions } from './module.mjs'
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module.mjs'
4
8
 
5
9
  export * from '../dist/runtime/types/index.js'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hywax/cms",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "description": "Hywax CMS. ⚠️ This package is intended for internal use only.",
6
6
  "repository": {
7
7
  "type": "git",
@@ -55,6 +55,8 @@
55
55
  "dist"
56
56
  ],
57
57
  "dependencies": {
58
+ "@dicebear/collection": "^9.2.2",
59
+ "@dicebear/core": "^9.2.2",
58
60
  "@iconify-json/lucide": "1.2.50",
59
61
  "@nuxt/kit": "^3.17.5",
60
62
  "@nuxt/ui-pro": "^3.1.3",
@@ -65,7 +67,10 @@
65
67
  "@vueuse/nuxt": "^13.4.0",
66
68
  "defu": "^6.1.4",
67
69
  "nuxt-auth-utils": "^0.5.20",
70
+ "pathe": "^2.0.3",
68
71
  "prosekit": "^0.13.6",
72
+ "scule": "^1.3.0",
73
+ "slugify": "^1.6.6",
69
74
  "zod": "^3.25.67"
70
75
  },
71
76
  "devDependencies": {
@@ -102,13 +107,13 @@
102
107
  "scripts": {
103
108
  "release": "pnpm run build && changelogen --release --push && pnpm publish --access public",
104
109
  "build": "nuxt-module-build build",
105
- "build:dev": "nuxi build playground",
110
+ "build:playground": "nuxi build playground",
106
111
  "dev": "npm run dev:prepare && nuxi dev playground",
107
112
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
108
113
  "lint": "eslint .",
109
114
  "lint:fix": "eslint --fix .",
110
115
  "test": "vitest run",
111
116
  "test:watch": "vitest watch",
112
- "typecheck": "vue-tsc --noEmit"
117
+ "typecheck": "vue-tsc --noEmit && nuxt typecheck playground"
113
118
  }
114
119
  }