@mono-lit/utility 0.0.0-stage → 0.0.1
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 +156 -2
- package/dist/app-roots-BJsIxzjk.d.ts +91 -0
- package/dist/app-roots-CvJnmXcs.js +128 -0
- package/dist/config-node-UzJrXg0Z.js +76 -0
- package/dist/config-node.d.ts +977 -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-D3m6xTaQ.d.ts +733 -0
- package/dist/create-config-DdL3Fh6T.js +357 -0
- package/dist/fetching.d.ts +239 -0
- package/dist/fetching.js +867 -0
- package/dist/generate-CJ7MtcDd.js +291 -0
- package/dist/index-C2hZeNkq.d.ts +365 -0
- package/dist/index-ClrZbU7n.d.ts +518 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +939 -0
- package/dist/merge-file-C5nzi_MY.d.ts +122 -0
- package/dist/merge-file-CtyKTu5L.js +133 -0
- package/dist/mock-db-5mJTObSC.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 +151 -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 +27 -0
- package/dist/mono-skills.d.ts +1 -0
- package/dist/mono-skills.js +830 -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 +34 -0
- package/dist/nuxt-layers.js +3 -0
- package/dist/nuxt-runtime.d.ts +18 -0
- package/dist/nuxt-runtime.js +102 -0
- package/dist/nuxt.d.ts +386 -0
- package/dist/nuxt.js +590 -0
- package/dist/runtime-C_IWNrAG.js +5817 -0
- package/dist/runtime.d.ts +2583 -0
- package/dist/runtime.js +4 -0
- package/dist/session-Bk985AIM.js +1721 -0
- package/dist/types-B6FdB7LJ.d.ts +57 -0
- package/dist/universal-B2eD9xho.d.ts +97 -0
- package/dist/universal-BNTo_83u.js +599 -0
- package/dist/virtual-mono-apps.d.ts +16 -0
- package/dist/vite.d.ts +940 -0
- package/dist/vite.js +1132 -0
- package/package.json +141 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/mono-db.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { c as resolveMonoConfig } from "./create-config-DdL3Fh6T.js";
|
|
2
|
+
import { t as getMonoConfig } from "./config-node-UzJrXg0Z.js";
|
|
3
|
+
import { s as monoAlias } from "./mono-alias-DNDm-jB_.js";
|
|
4
|
+
import { n as generateSeed, s as parseMockSchema } from "./generate-CJ7MtcDd.js";
|
|
5
|
+
import { writeFileSync } from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { defineCommand, runMain } from "citty";
|
|
8
|
+
|
|
9
|
+
//#region pkg/cli/db/index.ts
|
|
10
|
+
/**
|
|
11
|
+
* The merged config, including `extends`.
|
|
12
|
+
*
|
|
13
|
+
* Two things are load-bearing here:
|
|
14
|
+
*
|
|
15
|
+
* 1. jiti (inside c12) knows nothing about the `@mono-host` / `@<app>` aliases, and
|
|
16
|
+
* every real mono.config.ts imports through them (`@mono-host/odata/...`, and
|
|
17
|
+
* `@mono-host-root/mono.config` for `extends`). So teach it the same alias map
|
|
18
|
+
* Vite and the Nuxt module use — otherwise the config fails to load outright.
|
|
19
|
+
* 2. `getMonoConfig` runs c12 with `extend: false` (mono's `extends` holds thunks,
|
|
20
|
+
* which c12 can't resolve), so it returns the config with `extends` still raw.
|
|
21
|
+
* `resolveMonoConfig` is what merges the layers — which is how several apps'
|
|
22
|
+
* schemas end up in one place.
|
|
23
|
+
*/
|
|
24
|
+
async function loadMergedConfig(cwd) {
|
|
25
|
+
const dirname = path.resolve(cwd ?? process.cwd());
|
|
26
|
+
return resolveMonoConfig(await getMonoConfig({
|
|
27
|
+
cwd: dirname,
|
|
28
|
+
jitiOptions: { alias: monoAlias({ dirname }) }
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
function requireMock(config) {
|
|
32
|
+
const mock = config?.mockIndexedDB;
|
|
33
|
+
if (!mock?.schema || !Object.keys(mock.schema).length) {
|
|
34
|
+
console.error("[mono db] no `mockIndexedDB.schema` in the merged mono config.\n Declare one in mono.config.ts, or in a synced app that this config extends.");
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
return mock;
|
|
38
|
+
}
|
|
39
|
+
runMain(defineCommand({
|
|
40
|
+
meta: {
|
|
41
|
+
name: "db",
|
|
42
|
+
description: "Mock IndexedDB backend: validate schemas and preview generated seed data. The store itself lives in the browser — use monoMockDb().reset()/.export() at runtime."
|
|
43
|
+
},
|
|
44
|
+
subCommands: {
|
|
45
|
+
validate: defineCommand({
|
|
46
|
+
meta: {
|
|
47
|
+
name: "validate",
|
|
48
|
+
description: "Parse every mock schema and report bad fields/relations."
|
|
49
|
+
},
|
|
50
|
+
args: { cwd: {
|
|
51
|
+
type: "string",
|
|
52
|
+
description: "App root (defaults to the current directory)."
|
|
53
|
+
} },
|
|
54
|
+
async run({ args }) {
|
|
55
|
+
const { schemas, errors } = parseMockSchema(requireMock(await loadMergedConfig(args.cwd)));
|
|
56
|
+
for (const schema of schemas) {
|
|
57
|
+
const entities = Object.values(schema.entities);
|
|
58
|
+
console.log(`\n ${schema.baseUrl} (${entities.length} entit${entities.length === 1 ? "y" : "ies"})`);
|
|
59
|
+
for (const entity of entities) {
|
|
60
|
+
const relations = entity.relations.map((f) => f.name);
|
|
61
|
+
console.log(` - ${entity.name} pk=${entity.primaryKey} columns=${entity.columns.length}` + (relations.length ? ` expand=[${relations.join(", ")}]` : "") + (entity.seed ? ` seed=${entity.seed.length} row(s)` : ""));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (errors.length) {
|
|
65
|
+
console.error(`\n ${errors.length} error(s):`);
|
|
66
|
+
for (const error of errors) console.error(` x ${error.baseUrl} -> ${error.entity}${error.field ? `.${error.field}` : ""}: ${error.message}`);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
console.log("\n schema OK\n");
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
preview: defineCommand({
|
|
73
|
+
meta: {
|
|
74
|
+
name: "preview",
|
|
75
|
+
description: "Print the rows the generator would produce."
|
|
76
|
+
},
|
|
77
|
+
args: {
|
|
78
|
+
cwd: {
|
|
79
|
+
type: "string",
|
|
80
|
+
description: "App root (defaults to the current directory)."
|
|
81
|
+
},
|
|
82
|
+
entity: {
|
|
83
|
+
type: "string",
|
|
84
|
+
description: "Only this entity."
|
|
85
|
+
},
|
|
86
|
+
count: {
|
|
87
|
+
type: "string",
|
|
88
|
+
description: "Rows per entity (overrides seedCount)."
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
async run({ args }) {
|
|
92
|
+
const mock = requireMock(await loadMergedConfig(args.cwd));
|
|
93
|
+
const { schemas, errors } = parseMockSchema(mock);
|
|
94
|
+
if (errors.length) {
|
|
95
|
+
console.error("[mono db] schema has errors — run `mono db validate` first.");
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
for (const schema of schemas) {
|
|
99
|
+
const seed = generateSeed(schema, {
|
|
100
|
+
count: args.count ? Number(args.count) : mock.seedCount,
|
|
101
|
+
random: mock.seedRandom
|
|
102
|
+
});
|
|
103
|
+
for (const [entityName, rows] of Object.entries(seed)) {
|
|
104
|
+
if (args.entity && args.entity !== entityName) continue;
|
|
105
|
+
console.log(`\n ${schema.baseUrl} / ${entityName} (${rows.length} rows)`);
|
|
106
|
+
console.log(JSON.stringify(rows, null, 2));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}),
|
|
111
|
+
export: defineCommand({
|
|
112
|
+
meta: {
|
|
113
|
+
name: "export",
|
|
114
|
+
description: "Write generated rows to a JSON file (to promote them into an explicit `seed`)."
|
|
115
|
+
},
|
|
116
|
+
args: {
|
|
117
|
+
cwd: {
|
|
118
|
+
type: "string",
|
|
119
|
+
description: "App root (defaults to the current directory)."
|
|
120
|
+
},
|
|
121
|
+
out: {
|
|
122
|
+
type: "string",
|
|
123
|
+
description: "Output file.",
|
|
124
|
+
default: "mock-seed.json"
|
|
125
|
+
},
|
|
126
|
+
count: {
|
|
127
|
+
type: "string",
|
|
128
|
+
description: "Rows per entity (overrides seedCount)."
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
async run({ args }) {
|
|
132
|
+
const mock = requireMock(await loadMergedConfig(args.cwd));
|
|
133
|
+
const { schemas, errors } = parseMockSchema(mock);
|
|
134
|
+
if (errors.length) {
|
|
135
|
+
console.error("[mono db] schema has errors — run `mono db validate` first.");
|
|
136
|
+
process.exit(1);
|
|
137
|
+
}
|
|
138
|
+
const out = {};
|
|
139
|
+
for (const schema of schemas) out[schema.baseUrl] = generateSeed(schema, {
|
|
140
|
+
count: args.count ? Number(args.count) : mock.seedCount,
|
|
141
|
+
random: mock.seedRandom
|
|
142
|
+
});
|
|
143
|
+
const file = path.resolve(process.cwd(), args.out);
|
|
144
|
+
writeFileSync(file, JSON.stringify(out, null, 2));
|
|
145
|
+
console.log(`[mono db] wrote ${file}`);
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
}));
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// bin/mono-env.mjs
|
|
3
|
+
import { existsSync, readdirSync, statSync } from 'node:fs'
|
|
4
|
+
import { spawnSync } from 'node:child_process'
|
|
5
|
+
import { resolve, isAbsolute, basename, relative, dirname } from 'node:path'
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
7
|
+
import dotenv from 'dotenv'
|
|
8
|
+
|
|
9
|
+
const args = process.argv.slice(2)
|
|
10
|
+
|
|
11
|
+
const envFiles = []
|
|
12
|
+
const commandArgs = []
|
|
13
|
+
|
|
14
|
+
let appName = null
|
|
15
|
+
let appRoot = '.mono/apps'
|
|
16
|
+
|
|
17
|
+
function resolvePath(file) {
|
|
18
|
+
return isAbsolute(file) ? file : resolve(process.cwd(), file)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < args.length; i++) {
|
|
22
|
+
const arg = args[i]
|
|
23
|
+
|
|
24
|
+
if (arg === '--') {
|
|
25
|
+
commandArgs.push(...args.slice(i + 1))
|
|
26
|
+
break
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (arg === '-e' || arg === '--env') {
|
|
30
|
+
const file = args[i + 1]
|
|
31
|
+
|
|
32
|
+
if (!file) {
|
|
33
|
+
console.error('[mono-env] Missing value after -e / --env')
|
|
34
|
+
process.exit(1)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
envFiles.push(file)
|
|
38
|
+
i++
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (arg === '-a' || arg === '--app') {
|
|
43
|
+
const name = args[i + 1]
|
|
44
|
+
|
|
45
|
+
if (!name) {
|
|
46
|
+
console.error('[mono-env] Missing value after -a / --app')
|
|
47
|
+
process.exit(1)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
appName = name
|
|
51
|
+
i++
|
|
52
|
+
continue
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (arg === '-r' || arg === '--app-root') {
|
|
56
|
+
const root = args[i + 1]
|
|
57
|
+
|
|
58
|
+
if (!root) {
|
|
59
|
+
console.error('[mono-env] Missing value after -r / --app-root')
|
|
60
|
+
process.exit(1)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
appRoot = root
|
|
64
|
+
i++
|
|
65
|
+
continue
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Supports:
|
|
70
|
+
* node mono-env.mjs -e .env.dev vite
|
|
71
|
+
*/
|
|
72
|
+
commandArgs.push(...args.slice(i))
|
|
73
|
+
break
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!envFiles.length) {
|
|
77
|
+
console.warn('[mono-env] Warning: no env file provided. Example: -e .env.dev')
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!commandArgs.length) {
|
|
81
|
+
console.error('[mono-env] Missing command.')
|
|
82
|
+
console.error('[mono-env] Example: node mono-env.mjs -e .env.dev -- vite')
|
|
83
|
+
process.exit(1)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const childEnv = {
|
|
87
|
+
...process.env,
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function loadEnvByPath(fullPath, displayPath, label) {
|
|
91
|
+
if (!existsSync(fullPath)) {
|
|
92
|
+
console.warn(`[mono-env] Warning: ${label} env file not found: ${displayPath}`)
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const result = dotenv.config({
|
|
97
|
+
path: fullPath,
|
|
98
|
+
override: true,
|
|
99
|
+
processEnv: childEnv,
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
if (result.error) {
|
|
103
|
+
console.warn(`[mono-env] Warning: failed to load ${label} env: ${displayPath}`)
|
|
104
|
+
console.warn(result.error.message)
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.log(`[mono-env] Loaded ${label} env: ${displayPath}`)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Every federated app as `{ name, dir }`, the same answer every other command
|
|
113
|
+
* gives: the `.mono/apps` clones PLUS every app read in place through
|
|
114
|
+
* `apps[].path` (a mono-lith sibling), which a directory listing cannot see.
|
|
115
|
+
*
|
|
116
|
+
* The resolver lives in the built `config-node.js` next to this file in
|
|
117
|
+
* `dist/`. Run from the repo's `bin/` (not built) or without a mono.config, it
|
|
118
|
+
* falls back to listing the apps folder — exactly what this script always did.
|
|
119
|
+
*/
|
|
120
|
+
async function getAppRoots() {
|
|
121
|
+
try {
|
|
122
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
123
|
+
// A file URL, not a bare path: on Windows `import('C:\…')` is rejected as an unknown scheme.
|
|
124
|
+
const { resolveFederatedRoots } = await import(pathToFileURL(resolve(here, 'config-node.js')).href)
|
|
125
|
+
return resolveFederatedRoots({ dirname: process.cwd(), appsDir: appRoot })
|
|
126
|
+
.map((r) => ({ name: r.name, dir: r.root }))
|
|
127
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
128
|
+
} catch (e) {
|
|
129
|
+
// A declared `path` with no directory and no `url` is a config error every
|
|
130
|
+
// command reports; do not paper over it with the directory listing.
|
|
131
|
+
if (e instanceof Error && e.message.includes('does not exist and no url is declared')) {
|
|
132
|
+
console.error(`[mono-env] ${e.message}`)
|
|
133
|
+
process.exit(1)
|
|
134
|
+
}
|
|
135
|
+
return listAppsFolder()
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function listAppsFolder() {
|
|
140
|
+
const fullAppRoot = resolve(process.cwd(), appRoot)
|
|
141
|
+
|
|
142
|
+
if (!existsSync(fullAppRoot)) {
|
|
143
|
+
console.warn(`[mono-env] Warning: app root folder not found: ${appRoot}`)
|
|
144
|
+
return []
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return readdirSync(fullAppRoot)
|
|
148
|
+
.filter((name) => statSync(resolve(fullAppRoot, name)).isDirectory())
|
|
149
|
+
.sort()
|
|
150
|
+
.map((name) => ({ name, dir: resolve(fullAppRoot, name) }))
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function loadRootEnv(file) {
|
|
154
|
+
const fullPath = resolvePath(file)
|
|
155
|
+
loadEnvByPath(fullPath, file, 'root')
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function loadAppEnv(app) {
|
|
159
|
+
if (!existsSync(app.dir)) {
|
|
160
|
+
console.warn(`[mono-env] Warning: app folder not found: ${displayDir(app.dir)}`)
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
for (const file of envFiles) {
|
|
165
|
+
const envFileName = basename(file)
|
|
166
|
+
const appEnvPath = resolve(app.dir, envFileName)
|
|
167
|
+
const displayPath = `${displayDir(app.dir)}/${envFileName}`
|
|
168
|
+
|
|
169
|
+
loadEnvByPath(appEnvPath, displayPath, `app:${app.name}`)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function displayDir(dir) {
|
|
174
|
+
const rel = relative(process.cwd(), dir)
|
|
175
|
+
return (rel || dir).replace(/\\/g, '/')
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 1. Load root env first.
|
|
180
|
+
*
|
|
181
|
+
* Example:
|
|
182
|
+
* .env.dev
|
|
183
|
+
*/
|
|
184
|
+
for (const file of envFiles) {
|
|
185
|
+
loadRootEnv(file)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 2. Load app env second.
|
|
190
|
+
*
|
|
191
|
+
* Default behavior:
|
|
192
|
+
* - if -a sales is provided, only load that app (by name — a clone under
|
|
193
|
+
* .mono/apps or a sibling read through apps[].path)
|
|
194
|
+
* - if no -a is provided, load every federated app
|
|
195
|
+
*/
|
|
196
|
+
const allApps = await getAppRoots()
|
|
197
|
+
const apps = appName
|
|
198
|
+
? [allApps.find((a) => a.name === appName) ?? { name: appName, dir: resolve(process.cwd(), appRoot, appName) }]
|
|
199
|
+
: allApps
|
|
200
|
+
const appNames = apps.map((a) => a.name)
|
|
201
|
+
|
|
202
|
+
for (const app of apps) {
|
|
203
|
+
loadAppEnv(app)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (apps.length === 1) {
|
|
207
|
+
childEnv.MONO_APP_NAME = apps[0].name
|
|
208
|
+
childEnv.MONO_APP_DIR = apps[0].dir
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (appNames.length > 1) {
|
|
212
|
+
childEnv.MONO_APP_NAMES = appNames.join(',')
|
|
213
|
+
|
|
214
|
+
console.warn(
|
|
215
|
+
'[mono-env] Warning: multiple app env files loaded. Duplicate keys will override each other. Use unique env names per app.',
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const command = commandArgs.join(' ')
|
|
220
|
+
|
|
221
|
+
console.log(`[mono-env] Apps: ${appNames.length ? appNames.join(', ') : '-'}`)
|
|
222
|
+
console.log(`[mono-env] Command: ${command}`)
|
|
223
|
+
|
|
224
|
+
const result = spawnSync(command, {
|
|
225
|
+
stdio: 'inherit',
|
|
226
|
+
shell: true,
|
|
227
|
+
cwd: process.cwd(),
|
|
228
|
+
env: childEnv,
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
process.exit(result.status ?? 1)
|