@mono-lit/utility 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.
package/README.md CHANGED
@@ -1,157 +1,157 @@
1
- # Mono Utils
2
-
3
- A comprehensive utility library for Vue.js applications built around DevExtreme UI components, providing powerful data management, validation, and export capabilities.
4
-
5
- ## Features
6
-
7
- - 🔧 **OData Integration** - Sophisticated OData client with batch operations, caching, and error handling
8
- - 🎛️ **DevExtreme Helpers** - Utilities for data grids, lookups, and form components
9
- - ✅ **Schema Validation** - Yup-based validation system with nested object support
10
- - 📊 **Excel Export** - Advanced Excel export capabilities with custom formatting and formulas
11
- - 🔔 **Notification System** - Notivue-based notification management
12
- - 🚨 **Error Handling** - Comprehensive HTTP and OData error handling
13
- - 🔄 **Data Manipulation** - Powerful utilities for data transformation and operations
14
-
15
- ## Installation
16
-
17
- **From npmjs (public):**
18
-
19
- ```bash
20
- pnpm add @mono-lit/utility
21
- ```
22
-
23
- **From the Netlify registry:** add this to your project's `.npmrc`, then run the same `pnpm add`:
24
-
25
- ```ini
26
- @mono-lit:registry=https://mono-libs.netlify.app/npm/
27
- //mono-libs.netlify.app/npm/:_authToken=<REGISTRY_DOWNLOAD_TOKEN>
28
- ```
29
-
30
- See the [repository README](https://github.com/mono-lit/core#install-in-your-project) for details.
31
-
32
- ## Dependencies
33
-
34
- ### Core Dependencies
35
-
36
- These are the essential dependencies required for core functionality:
37
-
38
- ```bash
39
- npm install notivue yup exceljs file-saver-es @odata2ts/http-client-fetch json-server change-case chokidar
40
- ```
41
-
42
- **Note:** The additional dependencies (`json-server`, `change-case`, `chokidar`) are recommended for development and should be installed as devDependencies:
43
-
44
- ```bash
45
- npm install --save-dev json-server change-case chokidar
46
- ```
47
-
48
- ### Optional DevExtreme Dependencies
49
-
50
- **For DevExtreme UI Components:**
51
- If you're using DevExtreme components, you'll also need:
52
-
53
- ```bash
54
- npm install devextreme devextreme-vue
55
- ```
56
-
57
- **Note:** The core data fetching, validation, and Excel export utilities work independently of any UI framework. You can use this library with Vue, React, Angular, or vanilla JavaScript.
58
-
59
- ## Quick Start
60
-
61
- ### Basic Setup
62
-
63
- ```vue
64
- <script setup>
65
- import { useUtils } from '@mono-lit/utility/runtime'
66
-
67
- const utils = useUtils()
68
-
69
- // Destructure the utilities you need
70
- const {
71
- notif,
72
- validateAllSchema,
73
- validateSchema,
74
- replacerData,
75
- exportExcel,
76
- useFetchOData,
77
- createFetcher,
78
- advanceExportExcel
79
- } = utils
80
- </script>
81
- ```
82
-
83
- ### Usage Without DevExtreme
84
-
85
- For users working with other UI frameworks (React, Angular, or vanilla JavaScript), you can still use the core data fetching, validation, and export utilities:
86
-
87
- ```javascript
88
- import { useUtils } from '@mono-lit/utility/runtime'
89
-
90
- const { useFetchOData, notif, advanceExportExcel } = useUtils()
91
-
92
- // Fetch data
93
- const { data, error } = await useFetchOData({
94
- url: '/Users',
95
- baseUrl: 'https://your-api.com/odata',
96
- type: 'data'
97
- })
98
-
99
- if (error) {
100
- notif({
101
- message: error.message,
102
- type: 'error'
103
- })
104
- }
105
-
106
- // Export to Excel
107
- await advanceExportExcel({
108
- title: 'User Report',
109
- items: data,
110
- config: {
111
- columns: [
112
- { key: 'Id', title: 'ID', width: 10 },
113
- { key: 'Name', title: 'Name', width: 30 },
114
- { key: 'Email', title: 'Email', width: 40 }
115
- ]
116
- }
117
- })
118
- ```
119
-
120
- ## Documentation
121
-
122
- - **[Data Fetching](./docs/data-fetching.md)** - OData integration, HTTP client, data manipulation
123
- - **[Excel Export](./docs/excel-export.md)** - Advanced Excel export with formatting and formulas
124
- - **[Validation](./docs/validation.md)** - Schema validation with Yup
125
- - **[Notifications](./docs/notifications.md)** - Notivue-based notification system
126
- - **[DevExtreme Integration](./docs/devextreme-integration.md)** - DevExtreme UI helpers and components
127
-
128
- ## API Reference
129
-
130
- ### useUtils Return Object
131
-
132
- The main `useUtils()` function returns an object with the following utilities:
133
-
134
- #### Core Utilities
135
- - `notif` - Notification system
136
- - `validateAllSchema` - Validate entire form with Yup
137
- - `validateSchema` - Validate single field with Yup
138
- - `validateAllSchemaCheck` - Check if any validation errors exist
139
- - `clearSchemaValidation` - Clear all validation errors
140
-
141
- #### Data Utilities
142
- - `replacerData` - Add/update/remove items from arrays or DataSources
143
- - `filterOrIn` - Create OData filter expressions
144
-
145
- #### UI Components
146
- - `exportExcel` - Basic Excel export
147
- - `advanceExportExcel` - Advanced Excel export with formulas
148
-
149
- #### OData & HTTP
150
- - `useFetchOData` - Main OData fetching utility
151
- - `createFetcher` - Create reusable fetchers
152
- - `useNormalFetch` - Simple HTTP fetch utility
153
- - `createUniqueFetcher` - Fetch unique records
154
-
155
- ## License
156
-
1
+ # Mono Utils
2
+
3
+ A comprehensive utility library for Vue.js applications built around DevExtreme UI components, providing powerful data management, validation, and export capabilities.
4
+
5
+ ## Features
6
+
7
+ - 🔧 **OData Integration** - Sophisticated OData client with batch operations, caching, and error handling
8
+ - 🎛️ **DevExtreme Helpers** - Utilities for data grids, lookups, and form components
9
+ - ✅ **Schema Validation** - Yup or Valibot (any Standard Schema) validation with nested object support
10
+ - 📊 **Excel Export** - Advanced Excel export capabilities with custom formatting and formulas
11
+ - 🔔 **Notification System** - Notivue-based notification management
12
+ - 🚨 **Error Handling** - Comprehensive HTTP and OData error handling
13
+ - 🔄 **Data Manipulation** - Powerful utilities for data transformation and operations
14
+
15
+ ## Installation
16
+
17
+ **From npmjs (public):**
18
+
19
+ ```bash
20
+ pnpm add @mono-lit/utility
21
+ ```
22
+
23
+ **From the Netlify registry:** add this to your project's `.npmrc`, then run the same `pnpm add`:
24
+
25
+ ```ini
26
+ @mono-lit:registry=https://mono-libs.netlify.app/npm/
27
+ //mono-libs.netlify.app/npm/:_authToken=<REGISTRY_DOWNLOAD_TOKEN>
28
+ ```
29
+
30
+ See the [repository README](https://github.com/mono-lit/core#install-in-your-project) for details.
31
+
32
+ ## Dependencies
33
+
34
+ ### Core Dependencies
35
+
36
+ These are the essential dependencies required for core functionality:
37
+
38
+ ```bash
39
+ npm install notivue valibot exceljs file-saver-es @odata2ts/http-client-fetch json-server change-case chokidar
40
+ ```
41
+
42
+ **Note:** The additional dependencies (`json-server`, `change-case`, `chokidar`) are recommended for development and should be installed as devDependencies:
43
+
44
+ ```bash
45
+ npm install --save-dev json-server change-case chokidar
46
+ ```
47
+
48
+ ### Optional DevExtreme Dependencies
49
+
50
+ **For DevExtreme UI Components:**
51
+ If you're using DevExtreme components, you'll also need:
52
+
53
+ ```bash
54
+ npm install devextreme devextreme-vue
55
+ ```
56
+
57
+ **Note:** The core data fetching, validation, and Excel export utilities work independently of any UI framework. You can use this library with Vue, React, Angular, or vanilla JavaScript.
58
+
59
+ ## Quick Start
60
+
61
+ ### Basic Setup
62
+
63
+ ```vue
64
+ <script setup>
65
+ import { useUtils } from '@mono-lit/utility/runtime'
66
+
67
+ const utils = useUtils()
68
+
69
+ // Destructure the utilities you need
70
+ const {
71
+ notif,
72
+ validateAllSchema,
73
+ validateSchema,
74
+ replacerData,
75
+ exportExcel,
76
+ useFetchOData,
77
+ createFetcher,
78
+ advanceExportExcel
79
+ } = utils
80
+ </script>
81
+ ```
82
+
83
+ ### Usage Without DevExtreme
84
+
85
+ For users working with other UI frameworks (React, Angular, or vanilla JavaScript), you can still use the core data fetching, validation, and export utilities:
86
+
87
+ ```javascript
88
+ import { useUtils } from '@mono-lit/utility/runtime'
89
+
90
+ const { useFetchOData, notif, advanceExportExcel } = useUtils()
91
+
92
+ // Fetch data
93
+ const { data, error } = await useFetchOData({
94
+ url: '/Users',
95
+ baseUrl: 'https://your-api.com/odata',
96
+ type: 'data'
97
+ })
98
+
99
+ if (error) {
100
+ notif({
101
+ message: error.message,
102
+ type: 'error'
103
+ })
104
+ }
105
+
106
+ // Export to Excel
107
+ await advanceExportExcel({
108
+ title: 'User Report',
109
+ items: data,
110
+ config: {
111
+ columns: [
112
+ { key: 'Id', title: 'ID', width: 10 },
113
+ { key: 'Name', title: 'Name', width: 30 },
114
+ { key: 'Email', title: 'Email', width: 40 }
115
+ ]
116
+ }
117
+ })
118
+ ```
119
+
120
+ ## Documentation
121
+
122
+ - **[Data Fetching](./docs/data-fetching.md)** - OData integration, HTTP client, data manipulation
123
+ - **[Excel Export](./docs/excel-export.md)** - Advanced Excel export with formatting and formulas
124
+ - **[Validation](./docs/validation.md)** - Schema validation with Yup or Valibot
125
+ - **[Notifications](./docs/notifications.md)** - Notivue-based notification system
126
+ - **[DevExtreme Integration](./docs/devextreme-integration.md)** - DevExtreme UI helpers and components
127
+
128
+ ## API Reference
129
+
130
+ ### useUtils Return Object
131
+
132
+ The main `useUtils()` function returns an object with the following utilities:
133
+
134
+ #### Core Utilities
135
+ - `notif` - Notification system
136
+ - `validateAllSchema` - Validate entire form (Yup or Valibot)
137
+ - `validateSchema` - Validate single field (Yup or Valibot)
138
+ - `validateAllSchemaCheck` - Check if any validation errors exist
139
+ - `clearSchemaValidation` - Clear all validation errors
140
+
141
+ #### Data Utilities
142
+ - `replacerData` - Add/update/remove items from arrays or DataSources
143
+ - `filterOrIn` - Create OData filter expressions
144
+
145
+ #### UI Components
146
+ - `exportExcel` - Basic Excel export
147
+ - `advanceExportExcel` - Advanced Excel export with formulas
148
+
149
+ #### OData & HTTP
150
+ - `useFetchOData` - Main OData fetching utility
151
+ - `createFetcher` - Create reusable fetchers
152
+ - `useNormalFetch` - Simple HTTP fetch utility
153
+ - `createUniqueFetcher` - Fetch unique records
154
+
155
+ ## License
156
+
157
157
  This project is licensed under the MIT License.
@@ -1,5 +1,5 @@
1
1
  import { a as monoMockDb, n as MonoMockRequest, o as resetMonoMockDb, r as MonoMockResponse, t as MonoMockDb } from "./index-BAy6tbOG.js";
2
- import { B as NormalFetchOptions, H as OdataFetchTypes, U as TanstackFetchOptions, Y as UseOdataStaticOpts, _ as getPrefetchBridge, a as TryCatchDatasourceParams, d as promiseWrapper, g as MonoPrefetchRequest, h as MonoPrefetchBridge, i as OdataFetchUniqueTypes, n as FetchOverrides, o as createFetcher, r as LoadChunkStoreArgs } from "./index-DYlzhHq7.js";
2
+ import { G as OdataFetchTypes, K as TanstackFetchOptions, Q as UseOdataStaticOpts, U as NormalFetchOptions, _ as getPrefetchBridge, a as TryCatchDatasourceParams, d as promiseWrapper, g as MonoPrefetchRequest, h as MonoPrefetchBridge, i as OdataFetchUniqueTypes, n as FetchOverrides, o as createFetcher, r as LoadChunkStoreArgs } from "./index-CLXtqgEx.js";
3
3
  import DataSource from "devextreme/data/data_source";
4
4
  import CustomStore from "devextreme/data/custom_store";
5
5
  import ODataStore from "devextreme/data/odata/store";
package/dist/fetching.js CHANGED
@@ -1,4 +1,4 @@
1
- import { D as monoState, O as monoStatePatch, T as monoConfig, a as createUniqueFetcher, c as tryCatchDatasource, d as PREFETCH_SUPPORT, f as getPrefetchBridge, h as createStaticDatasource, i as createFetcher, l as useFetchOData, o as loadChuckStore, p as setPrefetchBridge, s as promiseWrapper, u as useNormalFetch } from "./runtime-vs7U9Ed4.js";
1
+ import { D as monoState, O as monoStatePatch, T as monoConfig, a as createUniqueFetcher, c as tryCatchDatasource, d as PREFETCH_SUPPORT, f as getPrefetchBridge, h as createStaticDatasource, i as createFetcher, l as useFetchOData, o as loadChuckStore, p as setPrefetchBridge, s as promiseWrapper, u as useNormalFetch } from "./runtime-TXXmV6Q6.js";
2
2
  import { t as monoCookie, u as decodeJwt } from "./universal-DIVEzCvN.js";
3
3
  import { i as matchMockRoute } from "./generate-CJ7MtcDd.js";
4
4
  import { c as executeQuery, f as parseQuery, l as parseExpand, n as monoMockDb, r as resetMonoMockDb } from "./mock-db-4tTWrF-P.js";
@@ -6,7 +6,7 @@ import CustomStore, { CustomStoreOptions } from "devextreme/data/custom_store";
6
6
  import { FetchRequestConfig } from "@odata2ts/http-client-fetch";
7
7
  import ODataStore, { ODataStoreOptions } from "devextreme/data/odata/store";
8
8
  import { DxColumn, DxDataGrid, DxDataGridTypes } from "devextreme-vue/data-grid";
9
- import { ObjectSchema } from "yup";
9
+ import * as yup from "yup";
10
10
  import { QBooleanPath, QDateTimeOffsetPath, QEntityCollectionPath, QEntityPath, QNumberPath, QStringPath } from "@odata2ts/odata-query-objects";
11
11
  import { LoadOptions } from "devextreme/data";
12
12
  //#region src/core/composables/use-static-datasource.d.ts
@@ -109,11 +109,11 @@ declare const useHelper: () => {
109
109
  };
110
110
  }) => void;
111
111
  filterOrIn: (field: string, values: any[], combine?: boolean) => any;
112
- validateAllSchema: <T extends object = any>({ schema, input, error }: ValidateSchema<T>, callback?: () => void) => Promise<boolean>;
113
- validateSchema: <T = any>({ schema, field, input, error }: ValidateSchema<T>, callback?: Function) => Promise<boolean>;
114
- validateAllSchemaCheck: (error: ValidateError<any>) => boolean;
112
+ validateAllSchema: <T extends object = any>({ schema, input, error }: ValidateSchema<T>, callback?: () => unknown) => Promise<boolean>;
113
+ validateSchema: <T = any>({ schema, field, input, error }: ValidateSchema<T>, callback?: () => unknown) => Promise<boolean>;
114
+ validateAllSchemaCheck: (error: ValidateError<any> | any) => boolean;
115
115
  clearSchemaValidation: ({ error }: {
116
- error: Ref<any>;
116
+ error: any;
117
117
  }) => void;
118
118
  notif: (options: NotifProps) => Promise<import("notivue").NotificationClearMethods | undefined>;
119
119
  dxFilterToString: ({ filter, encode }: {
@@ -321,10 +321,42 @@ interface GroupTemplate {
321
321
  }
322
322
  //#endregion
323
323
  //#region src/core/types/schema.d.ts
324
+ /**
325
+ * Minimal Standard Schema v1 shape (https://standardschema.dev) — what Valibot,
326
+ * Zod, ArkType, … expose as `schema["~standard"]`. Inlined so no schema library
327
+ * is a type dependency.
328
+ */
329
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
330
+ readonly "~standard": {
331
+ readonly version: 1;
332
+ readonly vendor: string;
333
+ readonly validate: (value: unknown) => StandardSchemaV1Result<Output> | Promise<StandardSchemaV1Result<Output>>;
334
+ readonly types?: {
335
+ readonly input: Input;
336
+ readonly output: Output;
337
+ } | undefined;
338
+ };
339
+ }
340
+ type StandardSchemaV1Result<Output> = {
341
+ readonly value: Output;
342
+ readonly issues?: undefined;
343
+ } | {
344
+ readonly issues: ReadonlyArray<{
345
+ readonly message: string;
346
+ readonly path?: ReadonlyArray<PropertyKey | {
347
+ readonly key: PropertyKey;
348
+ }> | undefined;
349
+ }>;
350
+ };
351
+ /** A yup schema or any Standard Schema (Valibot, Zod, …). */
352
+ type ValidationSchemaLike = yup.AnySchema | yup.AnyObjectSchema | StandardSchemaV1<any, any>;
324
353
  interface ValidateSchema<T = any> {
325
- schema: any;
326
- field?: keyof T;
354
+ /** yup schema or any Standard Schema (Valibot, Zod, …) */
355
+ schema: ValidationSchemaLike | any;
356
+ /** field to validate; dotted / indexed paths allowed (`"address.city"`, `"items[0].name"`) */
357
+ field?: keyof T | (string & {});
327
358
  input: T;
359
+ /** `{ valid, message }` slots mirroring `input` (object or Ref) */
328
360
  error: any;
329
361
  }
330
362
  type ValidateErrorItem = {
@@ -334,7 +366,7 @@ type ValidateErrorItem = {
334
366
  type ValidateError<T extends string = string> = Record<T, ValidateErrorItem>;
335
367
  type WithUndefined<T> = { [P in keyof T]: T[P] | undefined; };
336
368
  interface SchemaType<T> extends WithUndefined<T> {}
337
- interface Schema<T> extends ObjectSchema<SchemaType<T>> {}
369
+ interface Schema<T> extends yup.ObjectSchema<SchemaType<T>> {}
338
370
  type AnyObject = yup.AnyObject;
339
371
  /** Map a TS type T to the corresponding Yup schema type */
340
372
  type SchemaFor<T> = T extends string ? yup.StringSchema<string> : T extends number ? yup.NumberSchema<number> : T extends boolean ? yup.BooleanSchema<boolean> : T extends Date ? yup.DateSchema<Date> : T extends (infer U)[] ? yup.ArraySchema<SchemaFor<U>, AnyObject, U[]> : T extends Record<string, any> ? yup.ObjectSchema<{ [K in keyof T]-?: SchemaFor<T[K]>; }, AnyObject, T> : yup.Schema<T>;
@@ -511,4 +543,4 @@ type __VLS_Props = {
511
543
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
512
544
  declare const _default: typeof __VLS_export;
513
545
  //#endregion
514
- export { ValidateErrorItem as A, NormalFetchOptions as B, Format as C, SchemaType as D, SchemaObject as E, LoopTemplate as F, NotifProps as G, OdataFetchTypes as H, PathValue as I, MonoNotifButton as J, MonoNotifActionProps as K, FetchLoading as L, ValidateSchema as M, Col as N, ValidateError as O, GroupTemplate as P, FetchOData as R, FilterExpression as S, Schema as T, TanstackFetchOptions as U, NormalFetchResult as V, useHelper as W, createStaticDatasource as X, UseOdataStaticOpts as Y, getPrefetchBridge as _, TryCatchDatasourceParams as a, CustomSummary as b, extractErrorMessage as c, promiseWrapper as d, tryCatchDatasource as f, MonoPrefetchRequest as g, MonoPrefetchBridge as h, OdataFetchUniqueTypes as i, ValidateErrorSingle as j, ValidateErrorComplex as k, loadChuckStore as l, useNormalFetch as m, FetchOverrides as n, createFetcher as o, useFetchOData as p, MonoNotifActionTypes as q, LoadChunkStoreArgs as r, createUniqueFetcher as s, _default as t, parseDxError as u, setPrefetchBridge as v, HeaderFilter as w, DataGrid as x, OdataMapTypes as y, FetchParam as z };
546
+ export { createStaticDatasource as $, ValidateError as A, FetchLoading as B, Format as C, SchemaType as D, SchemaObject as E, ValidationSchemaLike as F, OdataFetchTypes as G, FetchParam as H, Col as I, NotifProps as J, TanstackFetchOptions as K, GroupTemplate as L, ValidateErrorItem as M, ValidateErrorSingle as N, StandardSchemaV1 as O, ValidateSchema as P, UseOdataStaticOpts as Q, LoopTemplate as R, FilterExpression as S, Schema as T, NormalFetchOptions as U, FetchOData as V, NormalFetchResult as W, MonoNotifActionTypes as X, MonoNotifActionProps as Y, MonoNotifButton as Z, getPrefetchBridge as _, TryCatchDatasourceParams as a, CustomSummary as b, extractErrorMessage as c, promiseWrapper as d, tryCatchDatasource as f, MonoPrefetchRequest as g, MonoPrefetchBridge as h, OdataFetchUniqueTypes as i, ValidateErrorComplex as j, StandardSchemaV1Result as k, loadChuckStore as l, useNormalFetch as m, FetchOverrides as n, createFetcher as o, useFetchOData as p, useHelper as q, LoadChunkStoreArgs as r, createUniqueFetcher as s, _default as t, parseDxError as u, setPrefetchBridge as v, HeaderFilter as w, DataGrid as x, OdataMapTypes as y, PathValue as z };