@mono-lit/utility 0.0.0-stage → 0.0.2
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/LICENSE.md +54 -0
- package/README.md +157 -3
- package/dist/app-roots-CvJnmXcs.js +128 -0
- package/dist/app-roots-DK41xMWj.d.ts +90 -0
- package/dist/config-node-UzJrXg0Z.js +76 -0
- package/dist/config-node.d.ts +923 -0
- package/dist/config-node.js +7 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +3 -0
- package/dist/create-config-B8IhX4ht.d.ts +735 -0
- package/dist/create-config-DdL3Fh6T.js +357 -0
- package/dist/fetching.d.ts +244 -0
- package/dist/fetching.js +1015 -0
- package/dist/generate-CJ7MtcDd.js +291 -0
- package/dist/index-BAy6tbOG.d.ts +371 -0
- package/dist/index-DYlzhHq7.d.ts +514 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +941 -0
- package/dist/merge-file-CLc3wxY4.d.ts +99 -0
- package/dist/merge-file-CtyKTu5L.js +133 -0
- package/dist/mock-db-4tTWrF-P.js +1282 -0
- package/dist/mock-db.d.ts +2 -0
- package/dist/mock-db.js +4 -0
- package/dist/mono-alias-DNDm-jB_.js +508 -0
- package/dist/mono-clone.mjs +958 -0
- package/dist/mono-db.d.ts +1 -0
- package/dist/mono-db.js +158 -0
- package/dist/mono-env.mjs +231 -0
- package/dist/mono-git.mjs +798 -0
- package/dist/mono-link-YlOQ2PVS.js +488 -0
- package/dist/mono-prepare.d.ts +1 -0
- package/dist/mono-prepare.js +28 -0
- package/dist/mono-skills.d.ts +1 -0
- package/dist/mono-skills.js +837 -0
- package/dist/mono-tsconfig-D2qRL9_R.js +204 -0
- package/dist/mono.mjs +34 -0
- package/dist/nuxt-layers-DP1m7f1-.js +176 -0
- package/dist/nuxt-layers.d.ts +36 -0
- package/dist/nuxt-layers.js +3 -0
- package/dist/nuxt-runtime.d.ts +17 -0
- package/dist/nuxt-runtime.js +102 -0
- package/dist/nuxt.d.ts +390 -0
- package/dist/nuxt.js +737 -0
- package/dist/runtime-vs7U9Ed4.js +6054 -0
- package/dist/runtime.d.ts +2518 -0
- package/dist/runtime.js +4 -0
- package/dist/session-Bcig-rPi.js +1721 -0
- package/dist/types-B6FdB7LJ.d.ts +57 -0
- package/dist/universal-BR0O7Qwk.d.ts +59 -0
- package/dist/universal-DIVEzCvN.js +600 -0
- package/dist/virtual-mono-apps.d.ts +16 -0
- package/dist/vite.d.ts +943 -0
- package/dist/vite.js +1132 -0
- package/package.json +141 -3
package/LICENSE.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 YCEJ9999
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Third-party software
|
|
26
|
+
|
|
27
|
+
The MIT License above covers only the code written for this package. It does
|
|
28
|
+
**not** cover third-party packages these libraries depend on or work with. Each of
|
|
29
|
+
those keeps its own license.
|
|
30
|
+
|
|
31
|
+
### DevExtreme
|
|
32
|
+
|
|
33
|
+
**DevExtreme** is a product of **Developer Express Inc. ("DevExpress")** and is
|
|
34
|
+
licensed by DevExpress under its own terms, not by the copyright holder of this
|
|
35
|
+
package. `@mono-lit/utility` depends on `devextreme` and `devextreme-vue`, so installing
|
|
36
|
+
it downloads them, but:
|
|
37
|
+
|
|
38
|
+
- this package does **not** provide, sublicense, transfer or grant any DevExtreme
|
|
39
|
+
license;
|
|
40
|
+
- you are responsible for obtaining a valid DevExtreme license from DevExpress and
|
|
41
|
+
for complying with its End User License Agreement;
|
|
42
|
+
- DevExpress's license terms, not this file, govern your use of DevExtreme.
|
|
43
|
+
|
|
44
|
+
Official DevExpress licensing information:
|
|
45
|
+
|
|
46
|
+
- DevExtreme licensing: https://js.devexpress.com/Licensing/
|
|
47
|
+
- DevExtreme EULA: https://js.devexpress.com/EULAs/DevExtremeComplete/
|
|
48
|
+
|
|
49
|
+
For setting up your license key, see
|
|
50
|
+
[../devextreme/README.md](../devextreme/README.md).
|
|
51
|
+
|
|
52
|
+
"DevExpress" and "DevExtreme" are trademarks or registered trademarks of
|
|
53
|
+
Developer Express Inc. This project is not affiliated with or endorsed by
|
|
54
|
+
DevExpress.
|
package/README.md
CHANGED
|
@@ -1,3 +1,157 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
|
|
157
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
//#region src/composables/app-roots.ts
|
|
5
|
+
/**
|
|
6
|
+
* Where each federated app's source actually lives.
|
|
7
|
+
*
|
|
8
|
+
* Everything that consumes a remote — `monoAlias`, `monoMissingApps`,
|
|
9
|
+
* `monoEcosystem`, `mono prepare`, `mono sync`, `mono env`, the vite transform
|
|
10
|
+
* gates, the Nuxt module — used to answer that question by listing
|
|
11
|
+
* `.mono/apps/`. That is still the answer for a synced clone, but
|
|
12
|
+
* `MonoAppConfig.path` names a directory the app is read from DIRECTLY (a
|
|
13
|
+
* sibling folder in a mono-lith, a checkout beside this one), and a directory
|
|
14
|
+
* listing cannot see one. So the question is asked here, once, and every
|
|
15
|
+
* consumer takes the answer.
|
|
16
|
+
*
|
|
17
|
+
* Two properties this file has to preserve:
|
|
18
|
+
*
|
|
19
|
+
* - **`path` is authoritative in every command.** Dev, build, prepare, sync,
|
|
20
|
+
* env and the Nuxt module all read the same directory. There is no
|
|
21
|
+
* "build reads the clone instead" mode any more: a bundle built from a lith
|
|
22
|
+
* IS built from its siblings, and that is the point.
|
|
23
|
+
* - **Nothing here is a delete target.** `MONO_APPS_DIR` stays the single
|
|
24
|
+
* constant `mono sync` prunes inside (`bin/mono-git.mjs`). A resolved root is
|
|
25
|
+
* only ever READ. The very first `path` option was removed precisely because
|
|
26
|
+
* it fed the clone destination, and therefore the prune root, with a
|
|
27
|
+
* user-supplied directory.
|
|
28
|
+
*/
|
|
29
|
+
/** Apps already warned about, so a repeated config load stays quiet. */
|
|
30
|
+
const warnedPaths = /* @__PURE__ */ new Set();
|
|
31
|
+
/**
|
|
32
|
+
* Resolve every federated app to the directory it is read from.
|
|
33
|
+
*
|
|
34
|
+
* Config-declared `path` apps (when the directory exists) UNIONed with the
|
|
35
|
+
* `.mono/apps/` listing. A `path` root SHADOWS a clone of the same name — the
|
|
36
|
+
* stale clone is left on disk, simply not read — and a `path` that does not
|
|
37
|
+
* exist falls back to the clone when the entry has a `url` to sync from.
|
|
38
|
+
*/
|
|
39
|
+
function resolveAppRoots(opts) {
|
|
40
|
+
const { dirname, appsDir = "./.mono/apps", apps = [], listClones = true } = opts;
|
|
41
|
+
const onMissingPath = opts.onMissingPath ?? (opts.warnMissingPath === false ? "ignore" : "report");
|
|
42
|
+
const appsRoot = path.resolve(dirname, appsDir);
|
|
43
|
+
const roots = [];
|
|
44
|
+
const linked = /* @__PURE__ */ new Set();
|
|
45
|
+
for (const app of apps) {
|
|
46
|
+
const name = app?.name;
|
|
47
|
+
const declared = typeof app?.path === "string" ? app.path.trim() : "";
|
|
48
|
+
if (!name || !declared) continue;
|
|
49
|
+
const root = path.isAbsolute(declared) ? declared : path.resolve(dirname, declared);
|
|
50
|
+
if (!isDirectory(root)) {
|
|
51
|
+
if (onMissingPath === "ignore") continue;
|
|
52
|
+
if (hasUrl(app)) {
|
|
53
|
+
warnMissingAppPath(name, declared, root);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
throw new Error(missingPathMessage(name, declared, root));
|
|
57
|
+
}
|
|
58
|
+
linked.add(name);
|
|
59
|
+
roots.push({
|
|
60
|
+
name,
|
|
61
|
+
type: app.type,
|
|
62
|
+
root,
|
|
63
|
+
source: "path"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (!listClones) return roots;
|
|
67
|
+
const typeOf = /* @__PURE__ */ new Map();
|
|
68
|
+
for (const app of apps) if (app?.name) typeOf.set(app.name, app.type);
|
|
69
|
+
let entries;
|
|
70
|
+
try {
|
|
71
|
+
entries = fs.readdirSync(appsRoot, { withFileTypes: true });
|
|
72
|
+
} catch {
|
|
73
|
+
return roots;
|
|
74
|
+
}
|
|
75
|
+
for (const entry of entries) {
|
|
76
|
+
if (!entry.isDirectory()) continue;
|
|
77
|
+
if (linked.has(entry.name)) continue;
|
|
78
|
+
roots.push({
|
|
79
|
+
name: entry.name,
|
|
80
|
+
type: typeOf.get(entry.name),
|
|
81
|
+
root: path.join(appsRoot, entry.name),
|
|
82
|
+
source: "clone"
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return roots;
|
|
86
|
+
}
|
|
87
|
+
/** Just the absolute roots — for `server.fs.allow` and the transform gates. */
|
|
88
|
+
function appRootDirs(roots) {
|
|
89
|
+
return roots.map((r) => r.root);
|
|
90
|
+
}
|
|
91
|
+
/** The `path`-resolved subset. Used to tell the developer what is read in place. */
|
|
92
|
+
function pathAppRoots(roots) {
|
|
93
|
+
return roots.filter((r) => r.source === "path");
|
|
94
|
+
}
|
|
95
|
+
/** @deprecated renamed {@link pathAppRoots}. */
|
|
96
|
+
const linkedAppRoots = pathAppRoots;
|
|
97
|
+
/** `true` when an app entry can be synced from GitHub. */
|
|
98
|
+
function hasUrl(app) {
|
|
99
|
+
return typeof app?.url === "string" && app.url.trim().length > 0;
|
|
100
|
+
}
|
|
101
|
+
/** The error every entry point raises for a `path` with no directory and no `url`. */
|
|
102
|
+
function missingPathMessage(name, declared, resolved) {
|
|
103
|
+
return `[mono] ${name}: path '${declared}' does not exist and no url is declared, so there is nothing to fall back to.\n[mono] looked in ${resolved}`;
|
|
104
|
+
}
|
|
105
|
+
/** Recognise {@link missingPathMessage} from a caught error. */
|
|
106
|
+
function isMissingPathError(e) {
|
|
107
|
+
return e instanceof Error && e.message.includes("does not exist and no url is declared");
|
|
108
|
+
}
|
|
109
|
+
function isDirectory(dir) {
|
|
110
|
+
try {
|
|
111
|
+
return fs.statSync(dir).isDirectory();
|
|
112
|
+
} catch {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function warnMissingAppPath(name, declared, resolved) {
|
|
117
|
+
const key = `${name} ${resolved}`;
|
|
118
|
+
if (warnedPaths.has(key)) return;
|
|
119
|
+
warnedPaths.add(key);
|
|
120
|
+
console.warn(`[mono] ${name}: path '${declared}' does not exist — using the synced clone instead.\n[mono] looked in ${resolved}`);
|
|
121
|
+
}
|
|
122
|
+
/** Test seam: forget which missing paths have been reported. */
|
|
123
|
+
function resetAppPathWarnings() {
|
|
124
|
+
warnedPaths.clear();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
export { missingPathMessage as a, resolveAppRoots as c, linkedAppRoots as i, hasUrl as n, pathAppRoots as o, isMissingPathError as r, resetAppPathWarnings as s, appRootDirs as t };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { o as MonoAppType } from "./create-config-B8IhX4ht.js";
|
|
2
|
+
//#region src/composables/app-roots.d.ts
|
|
3
|
+
/** Where a resolved root came from. */
|
|
4
|
+
type MonoAppRootSource = 'path' | 'clone';
|
|
5
|
+
/** One federated app, resolved to the directory its source is read from. */
|
|
6
|
+
interface MonoAppRoot {
|
|
7
|
+
/** The app's `name` — what `@<name>` / `@<name>-root` key off. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Its declared `type`, when a config entry supplied one. */
|
|
10
|
+
type?: MonoAppType;
|
|
11
|
+
/** Absolute directory that IS the app root (contains `src/` or `app/`). */
|
|
12
|
+
root: string;
|
|
13
|
+
/**
|
|
14
|
+
* `'path'` — resolved from `apps[].path`, read in place, never written to.
|
|
15
|
+
* `'clone'` — the `.mono/apps/<name>` tree `mono sync` materialised.
|
|
16
|
+
*/
|
|
17
|
+
source: MonoAppRootSource;
|
|
18
|
+
/**
|
|
19
|
+
* Set when the entry was not declared by the root config but by one of its
|
|
20
|
+
* apps (see `resolveFederatedRoots`): the name of the app whose config
|
|
21
|
+
* declared it.
|
|
22
|
+
*/
|
|
23
|
+
via?: string;
|
|
24
|
+
}
|
|
25
|
+
/** The `apps[]` shape this needs. Loosened so the static text-parse fits too. */
|
|
26
|
+
interface MonoAppRootInput {
|
|
27
|
+
name?: string;
|
|
28
|
+
type?: MonoAppType;
|
|
29
|
+
url?: string;
|
|
30
|
+
path?: string;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* What to do with a declared `path` whose directory does not exist.
|
|
35
|
+
*
|
|
36
|
+
* - `'report'` — the entry also has a `url`: warn once and fall back to the
|
|
37
|
+
* clone (the developer who set `path` has the directory, everyone else gets
|
|
38
|
+
* `mono sync`'s copy). No `url`: THROW, there is nothing to fall back to.
|
|
39
|
+
* - `'ignore'` — skip silently. For a second pass over a config that another
|
|
40
|
+
* pass has already reported (prepare after alias, the transitive walk).
|
|
41
|
+
*/
|
|
42
|
+
type MonoMissingPathPolicy = 'report' | 'ignore';
|
|
43
|
+
interface ResolveAppRootsOptions {
|
|
44
|
+
/** Project root. `path` entries resolve against it. */
|
|
45
|
+
dirname: string;
|
|
46
|
+
/** Folder holding the clones. @default './.mono/apps' */
|
|
47
|
+
appsDir?: string;
|
|
48
|
+
/** `apps[]` from `mono.config.ts`. Entries with `path` resolve in place. */
|
|
49
|
+
apps?: MonoAppRootInput[];
|
|
50
|
+
/** @default 'report' */
|
|
51
|
+
onMissingPath?: MonoMissingPathPolicy;
|
|
52
|
+
/**
|
|
53
|
+
* Also list `<appsDir>` for clones. Pass `false` to resolve ONLY the declared
|
|
54
|
+
* `path` entries — what a transitive walk over a sibling's config wants.
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
listClones?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated `path` is authoritative in every command; this is ignored.
|
|
60
|
+
* Kept so older call sites keep type-checking.
|
|
61
|
+
*/
|
|
62
|
+
link?: boolean;
|
|
63
|
+
/** @deprecated use `onMissingPath: 'ignore'`. */
|
|
64
|
+
warnMissingPath?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Resolve every federated app to the directory it is read from.
|
|
68
|
+
*
|
|
69
|
+
* Config-declared `path` apps (when the directory exists) UNIONed with the
|
|
70
|
+
* `.mono/apps/` listing. A `path` root SHADOWS a clone of the same name — the
|
|
71
|
+
* stale clone is left on disk, simply not read — and a `path` that does not
|
|
72
|
+
* exist falls back to the clone when the entry has a `url` to sync from.
|
|
73
|
+
*/
|
|
74
|
+
declare function resolveAppRoots(opts: ResolveAppRootsOptions): MonoAppRoot[];
|
|
75
|
+
/** Just the absolute roots — for `server.fs.allow` and the transform gates. */
|
|
76
|
+
declare function appRootDirs(roots: MonoAppRoot[]): string[];
|
|
77
|
+
/** The `path`-resolved subset. Used to tell the developer what is read in place. */
|
|
78
|
+
declare function pathAppRoots(roots: MonoAppRoot[]): MonoAppRoot[];
|
|
79
|
+
/** @deprecated renamed {@link pathAppRoots}. */
|
|
80
|
+
declare const linkedAppRoots: typeof pathAppRoots;
|
|
81
|
+
/** `true` when an app entry can be synced from GitHub. */
|
|
82
|
+
declare function hasUrl(app: MonoAppRootInput | undefined): boolean;
|
|
83
|
+
/** The error every entry point raises for a `path` with no directory and no `url`. */
|
|
84
|
+
declare function missingPathMessage(name: string, declared: string, resolved: string): string;
|
|
85
|
+
/** Recognise {@link missingPathMessage} from a caught error. */
|
|
86
|
+
declare function isMissingPathError(e: unknown): boolean;
|
|
87
|
+
/** Test seam: forget which missing paths have been reported. */
|
|
88
|
+
declare function resetAppPathWarnings(): void;
|
|
89
|
+
//#endregion
|
|
90
|
+
export { ResolveAppRootsOptions as a, isMissingPathError as c, pathAppRoots as d, resetAppPathWarnings as f, MonoMissingPathPolicy as i, linkedAppRoots as l, MonoAppRootInput as n, appRootDirs as o, resolveAppRoots as p, MonoAppRootSource as r, hasUrl as s, MonoAppRoot as t, missingPathMessage as u };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { r as dedupeConfigArrays } from "./create-config-DdL3Fh6T.js";
|
|
2
|
+
import { loadConfig } from "c12";
|
|
3
|
+
|
|
4
|
+
//#region src/composables/config-node.ts
|
|
5
|
+
function getCwd() {
|
|
6
|
+
return typeof process !== "undefined" ? process.cwd() : void 0;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Collapse name-keyed arrays that may carry one duplicate per layer, so the
|
|
10
|
+
* loaded config behaves like a single config.
|
|
11
|
+
*
|
|
12
|
+
* Delegates to `dedupeConfigArrays` from `create-config` rather than owning a
|
|
13
|
+
* rule: this used to keep the FIRST occurrence while the runtime resolver keeps
|
|
14
|
+
* the LAST, which are opposite precedence rules for the same data. It is a no-op
|
|
15
|
+
* while `extend: false` (below) leaves c12 with only the root config's own
|
|
16
|
+
* arrays, but the two must never be able to disagree.
|
|
17
|
+
*/
|
|
18
|
+
function normalizeMergedConfig(config) {
|
|
19
|
+
return dedupeConfigArrays(config);
|
|
20
|
+
}
|
|
21
|
+
async function loadMonoConfig(options = {}) {
|
|
22
|
+
const result = await loadConfig({
|
|
23
|
+
name: "mono",
|
|
24
|
+
cwd: options.cwd ?? getCwd(),
|
|
25
|
+
extend: false,
|
|
26
|
+
defaults: {
|
|
27
|
+
apps: [],
|
|
28
|
+
name: "mono-app",
|
|
29
|
+
type: "vue",
|
|
30
|
+
menu: [],
|
|
31
|
+
cookie: [],
|
|
32
|
+
jwt: {}
|
|
33
|
+
},
|
|
34
|
+
...options
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
...result,
|
|
38
|
+
config: normalizeMergedConfig(result.config)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async function getMonoConfig(options = {}) {
|
|
42
|
+
try {
|
|
43
|
+
return (await loadMonoConfig(options)).config;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
throw describeConfigLoadError(error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** `Cannot find module '@some-app-root/mono.config'` — the shape jiti throws. */
|
|
49
|
+
const MISSING_ALIAS_RE = /Cannot find module ['"](@[^'"]+)['"]/;
|
|
50
|
+
/**
|
|
51
|
+
* Turn an unresolved mono alias into an error that says what to do.
|
|
52
|
+
*
|
|
53
|
+
* `mono.config.ts` reaches other apps through ordinary `import`s resolved by jiti
|
|
54
|
+
* against the alias map, and those aliases come from the `.mono/apps/` directory
|
|
55
|
+
* listing. An app that isn't synced therefore surfaces as a bare `Cannot find
|
|
56
|
+
* module '@x-root/mono.config'` — a specifier nobody typed by hand, thrown from
|
|
57
|
+
* inside c12, naming no file and no fix.
|
|
58
|
+
*
|
|
59
|
+
* Pattern-based on purpose: this module knows nothing about the alias map, and
|
|
60
|
+
* shouldn't. Covers the paths that never call `monoStubAliases` (the `mono db` CLI)
|
|
61
|
+
* and the specifiers a config-only stub can't satisfy (a host config importing a
|
|
62
|
+
* missing app's OData service).
|
|
63
|
+
*/
|
|
64
|
+
function describeConfigLoadError(error) {
|
|
65
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
66
|
+
const specifier = MISSING_ALIAS_RE.exec(message)?.[1];
|
|
67
|
+
if (!specifier) return error;
|
|
68
|
+
return new Error([
|
|
69
|
+
`[@mono-lit/utility] Failed to load mono.config: cannot resolve '${specifier}'.`,
|
|
70
|
+
"That looks like a federated mono app that isn't present in .mono/apps/.",
|
|
71
|
+
"Run `mono sync && mono prepare`. If the repo is private, set its envToken in .env."
|
|
72
|
+
].join("\n"), { cause: error });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { loadMonoConfig as n, getMonoConfig as t };
|