@nan0web/core 1.0.3 → 1.1.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/README.md +16 -10
- package/package.json +55 -53
- package/src/AppCore.js +53 -45
- package/src/Model.js +47 -0
- package/src/ProjectModel.js +74 -0
- package/src/index.js +7 -8
- package/types/AppCore.d.ts +39 -8
- package/types/Model.d.ts +32 -0
- package/types/ProjectModel.d.ts +62 -0
- package/types/index.d.ts +7 -4
- package/src/README.md.js +0 -219
- package/src/registry/ApiRegistry.js +0 -7
- package/src/registry/CommandRegistry.js +0 -50
- package/src/registry/ComponentRegistry.js +0 -51
- package/src/registry/RouteRegistry.js +0 -50
- package/src/registry/UiRegistry.js +0 -7
- package/src/system/Validator.js +0 -55
- package/src/system/integrator.js +0 -84
- package/src/system/main.js +0 -82
- package/types/registry/ApiRegistry.d.ts +0 -3
- package/types/registry/CommandRegistry.d.ts +0 -42
- package/types/registry/ComponentRegistry.d.ts +0 -42
- package/types/registry/RouteRegistry.d.ts +0 -42
- package/types/registry/UiRegistry.d.ts +0 -3
- package/types/system/Validator.d.ts +0 -30
- package/types/system/integrator.d.ts +0 -30
- package/types/system/main.d.ts +0 -1
package/src/README.md.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { describe, it, before, beforeEach } from "node:test"
|
|
2
|
-
import assert from "node:assert/strict"
|
|
3
|
-
import FS from "@nan0web/db-fs"
|
|
4
|
-
import { NoConsole } from "@nan0web/log"
|
|
5
|
-
import { DocsParser, DatasetParser } from "@nan0web/test"
|
|
6
|
-
import {
|
|
7
|
-
AppCore,
|
|
8
|
-
AppResult,
|
|
9
|
-
ExecutableCommand,
|
|
10
|
-
} from "./index.js"
|
|
11
|
-
import DB from "@nan0web/db"
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Load package.json once before any test.
|
|
15
|
-
*/
|
|
16
|
-
let pkg
|
|
17
|
-
const fs = new FS()
|
|
18
|
-
|
|
19
|
-
before(async () => {
|
|
20
|
-
const doc = await fs.loadDocument("package.json", {})
|
|
21
|
-
pkg = doc || {}
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
let console = new NoConsole()
|
|
25
|
-
|
|
26
|
-
beforeEach(() => {
|
|
27
|
-
console = new NoConsole()
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Core test suite that also serves as source for README generation.
|
|
32
|
-
*
|
|
33
|
-
* Block comments inside each `it` are extracted by DocsParser to build the final README.
|
|
34
|
-
*/
|
|
35
|
-
function testRender() {
|
|
36
|
-
/**
|
|
37
|
-
* @docs
|
|
38
|
-
* # @nan0web/core
|
|
39
|
-
*
|
|
40
|
-
* Core application framework for nan0web providing a lightweight
|
|
41
|
-
* DB‑backed state container with built‑in internationalisation.
|
|
42
|
-
*
|
|
43
|
-
* <!-- %PACKAGE_STATUS% -->
|
|
44
|
-
*
|
|
45
|
-
* ## Installation
|
|
46
|
-
*/
|
|
47
|
-
it("How to install with npm?", () => {
|
|
48
|
-
/**
|
|
49
|
-
* ```bash
|
|
50
|
-
* npm install @nan0web/core
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
assert.equal(pkg.name, "@nan0web/core")
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @docs
|
|
58
|
-
*/
|
|
59
|
-
it("How to install with pnpm?", () => {
|
|
60
|
-
/**
|
|
61
|
-
* ```bash
|
|
62
|
-
* pnpm add @nan0web/core
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
assert.equal(pkg.name, "@nan0web/core")
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @docs
|
|
70
|
-
*/
|
|
71
|
-
it("How to install with yarn?", () => {
|
|
72
|
-
/**
|
|
73
|
-
* ```bash
|
|
74
|
-
* yarn add @nan0web/core
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
assert.equal(pkg.name, "@nan0web/core")
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @docs
|
|
82
|
-
* ## Basic usage – AppCore
|
|
83
|
-
*
|
|
84
|
-
* Create an `AppCore` instance with a mock DB and inspect its state.
|
|
85
|
-
*/
|
|
86
|
-
it("How to instantiate AppCore?", () => {
|
|
87
|
-
//import { AppCore } from "@nan0web/core"
|
|
88
|
-
const db = new DB()
|
|
89
|
-
const core = new AppCore({ db, title: "Demo", uri: "/demo", locale: "en" })
|
|
90
|
-
console.info(core.title) // ← Demo
|
|
91
|
-
console.info(core.uri) // ← /demo
|
|
92
|
-
assert.equal(core.title, "Demo")
|
|
93
|
-
assert.equal(core.uri, "/demo")
|
|
94
|
-
assert.equal(core.locale, "en")
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @docs
|
|
99
|
-
* ## Internationalisation bootstrap
|
|
100
|
-
*
|
|
101
|
-
* Load translation JSON from the DB and obtain a translation function.
|
|
102
|
-
*/
|
|
103
|
-
it("How does bootstrapI18n load translations?", async () => {
|
|
104
|
-
const db = new DB({
|
|
105
|
-
predefined: [
|
|
106
|
-
["i18n/uk.json", { "hello": "Вітаю!" }]
|
|
107
|
-
]
|
|
108
|
-
})
|
|
109
|
-
await db.connect()
|
|
110
|
-
const core = new AppCore({ db, locale: "uk" })
|
|
111
|
-
await core.init()
|
|
112
|
-
const result = core.t("hello")
|
|
113
|
-
console.info(result) // ← Вітаю!
|
|
114
|
-
assert.equal(result, "Вітаю!")
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* @docs
|
|
119
|
-
* ## State inspection
|
|
120
|
-
*/
|
|
121
|
-
it("How to retrieve current state?", () => {
|
|
122
|
-
const db = new DB()
|
|
123
|
-
const core = new AppCore({ db })
|
|
124
|
-
const state = core.state()
|
|
125
|
-
assert.deepEqual(Object.keys(state), ["data", "actions", "meta", "t"])
|
|
126
|
-
assert.ok(typeof state.t === "function")
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* @docs
|
|
131
|
-
* ## AppResult helper
|
|
132
|
-
*/
|
|
133
|
-
it("How to create an AppResult instance?", () => {
|
|
134
|
-
//import { AppResult } from "@nan0web/core"
|
|
135
|
-
const res = new AppResult({ content: "Done", priority: 2, meta: { ok: true } })
|
|
136
|
-
console.info(res.content[0]) // ← Done
|
|
137
|
-
assert.equal(res.content[0], "Done")
|
|
138
|
-
assert.equal(res.priority, 2)
|
|
139
|
-
assert.deepEqual(res.meta, { ok: true })
|
|
140
|
-
assert.equal(res.error, null)
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* @docs
|
|
145
|
-
* ## run() contract
|
|
146
|
-
*
|
|
147
|
-
* The base `run` method throws an error – subclasses must implement it.
|
|
148
|
-
*/
|
|
149
|
-
it("How does run() behave when not overridden?", async () => {
|
|
150
|
-
const db = new DB()
|
|
151
|
-
const core = new AppCore({ db })
|
|
152
|
-
//await core.run() // ← throws an error → AppCore: run() must be implemented
|
|
153
|
-
assert.ok(core)
|
|
154
|
-
await assert.rejects(
|
|
155
|
-
async () => {
|
|
156
|
-
await core.run()
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
name: "Error",
|
|
160
|
-
message: "AppCore: run() must be implemented"
|
|
161
|
-
}
|
|
162
|
-
)
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* ## ExecutableCommand exposure
|
|
167
|
-
*/
|
|
168
|
-
it("Are exported commands available?", () => {
|
|
169
|
-
assert.ok(ExecutableCommand)
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* ## TypeScript declarations
|
|
174
|
-
*/
|
|
175
|
-
it("Does package expose declaration files?", () => {
|
|
176
|
-
assert.equal(pkg.types, "types/index.d.ts")
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* @docs
|
|
181
|
-
* ## Contributing
|
|
182
|
-
*/
|
|
183
|
-
it("How to contribute? - [check here](./CONTRIBUTING.md)", async () => {
|
|
184
|
-
assert.equal(pkg.scripts?.precommit, "npm test")
|
|
185
|
-
assert.equal(pkg.scripts?.prepush, "npm test")
|
|
186
|
-
assert.equal(pkg.scripts?.prepare, "husky")
|
|
187
|
-
const text = await fs.loadDocument("CONTRIBUTING.md")
|
|
188
|
-
const str = String(text)
|
|
189
|
-
assert.ok(str.includes("# Contributing"))
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* @docs
|
|
194
|
-
* ## License
|
|
195
|
-
*/
|
|
196
|
-
it("How to license ISC? - [check here](./LICENSE)", async () => {
|
|
197
|
-
/** @docs */
|
|
198
|
-
const text = await fs.loadDocument("LICENSE")
|
|
199
|
-
assert.ok(String(text).includes("ISC"))
|
|
200
|
-
})
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/* Run the test suite that also generates the README */
|
|
204
|
-
describe("README.md testing", testRender)
|
|
205
|
-
|
|
206
|
-
describe("Rendering README.md", async () => {
|
|
207
|
-
let text = ""
|
|
208
|
-
const format = new Intl.NumberFormat("en-US").format
|
|
209
|
-
const parser = new DocsParser()
|
|
210
|
-
text = String(parser.decode(testRender))
|
|
211
|
-
await fs.saveDocument("README.md", text)
|
|
212
|
-
const dataset = DatasetParser.parse(text, pkg.name)
|
|
213
|
-
await fs.saveDocument(".datasets/README.dataset.jsonl", dataset)
|
|
214
|
-
|
|
215
|
-
it(`document is rendered in README.md [${format(Buffer.byteLength(text))}b]`, async () => {
|
|
216
|
-
const readme = await fs.loadDocument("README.md")
|
|
217
|
-
assert.ok(readme.includes("## Installation"))
|
|
218
|
-
})
|
|
219
|
-
})
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Registry for CLI command namespaces
|
|
3
|
-
* Tracks registered commands and their owners
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* const registry = new CommandRegistry()
|
|
7
|
-
* registry.register('auth', { setup: () => { ... }, owner: '@nan0web/auth.app' })
|
|
8
|
-
* registry.has('auth') // true
|
|
9
|
-
*/
|
|
10
|
-
export default class CommandRegistry {
|
|
11
|
-
/** @type {Map<string, { setup: Function, owner: string }>} */
|
|
12
|
-
#commands = new Map()
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Register a CLI command namespace
|
|
16
|
-
* @param {string} command - Command name (e.g. 'auth')
|
|
17
|
-
* @param {{ setup: Function, owner: string }} config - Setup function and package name
|
|
18
|
-
* @returns {this}
|
|
19
|
-
*/
|
|
20
|
-
register(command, config) {
|
|
21
|
-
this.#commands.set(command, config)
|
|
22
|
-
return this
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Get all registered commands
|
|
27
|
-
* @returns {Map<string, { setup: Function, owner: string }>}
|
|
28
|
-
*/
|
|
29
|
-
getCommands() {
|
|
30
|
-
return new Map(this.#commands)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Check if command exists
|
|
35
|
-
* @param {string} command
|
|
36
|
-
* @returns {boolean}
|
|
37
|
-
*/
|
|
38
|
-
has(command) {
|
|
39
|
-
return this.#commands.has(command)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Get owner of command
|
|
44
|
-
* @param {string} command
|
|
45
|
-
* @returns {string | null}
|
|
46
|
-
*/
|
|
47
|
-
getOwner(command) {
|
|
48
|
-
return this.#commands.get(command)?.owner || null
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Registry for UI components
|
|
3
|
-
* Tracks registered component namespaces
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* const registry = new ComponentRegistry()
|
|
7
|
-
* registry.register('Auth.Login', { component: () => import('./Auth/Login.jsx'), owner: '@nan0web/auth.app' })
|
|
8
|
-
* registry.getComponent('Auth.Login') // Returns component loader
|
|
9
|
-
*/
|
|
10
|
-
export default class ComponentRegistry {
|
|
11
|
-
/** @type {Map<string, { component: Function, owner: string }>} */
|
|
12
|
-
#components = new Map()
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Register a component namespace
|
|
16
|
-
* @param {string} name - Component path (e.g. 'Auth.Login')
|
|
17
|
-
* @param {{ component: Function, owner: string }} config - Component loader and package name
|
|
18
|
-
* @returns {this}
|
|
19
|
-
*/
|
|
20
|
-
register(name, config) {
|
|
21
|
-
this.#components.set(name, config)
|
|
22
|
-
return this
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Get all registered components
|
|
27
|
-
* @returns {Map<string, { component: Function, owner: string }>}
|
|
28
|
-
*/
|
|
29
|
-
getComponents() {
|
|
30
|
-
return new Map(this.#components)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Get component loader by name
|
|
35
|
-
* @param {string} name
|
|
36
|
-
* @returns {Function | null}
|
|
37
|
-
*/
|
|
38
|
-
getComponent(name) {
|
|
39
|
-
return this.#components.get(name)?.component || null
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Find components by namespace prefix
|
|
44
|
-
* @param {string} namespace - E.g., 'Auth' to find all Auth.* components
|
|
45
|
-
* @returns {Array<string>} Component names
|
|
46
|
-
*/
|
|
47
|
-
findComponents(namespace) {
|
|
48
|
-
return Array.from(this.#components.keys())
|
|
49
|
-
.filter(name => name.startsWith(namespace))
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Registry for API route namespaces
|
|
3
|
-
* Tracks registered prefixes and their owners
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* const registry = new RouteRegistry()
|
|
7
|
-
* registry.register('auth', { setup: (router) => { ... }, owner: '@nan0web/auth.app' })
|
|
8
|
-
* registry.has('auth') // true
|
|
9
|
-
*/
|
|
10
|
-
export default class RouteRegistry {
|
|
11
|
-
/** @type {Map<string, { setup: Function, owner: string }>} */
|
|
12
|
-
#routes = new Map()
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Register a namespace prefix
|
|
16
|
-
* @param {string} prefix - URL prefix (e.g. 'auth')
|
|
17
|
-
* @param {{ setup: Function, owner: string }} config - Setup function and package name
|
|
18
|
-
* @returns {this}
|
|
19
|
-
*/
|
|
20
|
-
register(prefix, config) {
|
|
21
|
-
this.#routes.set(prefix, config)
|
|
22
|
-
return this
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Get all registered routes
|
|
27
|
-
* @returns {Map<string, { setup: Function, owner: string }>}
|
|
28
|
-
*/
|
|
29
|
-
getRoutes() {
|
|
30
|
-
return new Map(this.#routes)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Check if prefix exists
|
|
35
|
-
* @param {string} prefix
|
|
36
|
-
* @returns {boolean}
|
|
37
|
-
*/
|
|
38
|
-
has(prefix) {
|
|
39
|
-
return this.#routes.has(prefix)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Get owner of prefix
|
|
44
|
-
* @param {string} prefix
|
|
45
|
-
* @returns {string | null}
|
|
46
|
-
*/
|
|
47
|
-
getOwner(prefix) {
|
|
48
|
-
return this.#routes.get(prefix)?.owner || null
|
|
49
|
-
}
|
|
50
|
-
}
|
package/src/system/Validator.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import RouteRegistry from '../registry/RouteRegistry.js'
|
|
2
|
-
import CommandRegistry from '../registry/CommandRegistry.js'
|
|
3
|
-
import ComponentRegistry from '../registry/ComponentRegistry.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Validates application integration before registration
|
|
7
|
-
* Checks for namespace collisions across all registries
|
|
8
|
-
*/
|
|
9
|
-
export default class SystemValidator {
|
|
10
|
-
/**
|
|
11
|
-
* @param {Object} registries - System-wide registries
|
|
12
|
-
* @param {RouteRegistry} registries.apiRegistry - Manages API route prefixes
|
|
13
|
-
* @param {CommandRegistry} registries.cliRegistry - Manages CLI commands
|
|
14
|
-
* @param {ComponentRegistry} [registries.uiRegistry] - Manages UI components
|
|
15
|
-
*/
|
|
16
|
-
constructor({ apiRegistry, cliRegistry, uiRegistry }) {
|
|
17
|
-
if (!(apiRegistry instanceof RouteRegistry)) {
|
|
18
|
-
throw new Error('apiRegistry must be an instance of RouteRegistry')
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (!(cliRegistry instanceof CommandRegistry)) {
|
|
22
|
-
throw new Error('cliRegistry must be an instance of CommandRegistry')
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
this.apiRegistry = apiRegistry
|
|
26
|
-
this.cliRegistry = cliRegistry
|
|
27
|
-
this.uiRegistry = uiRegistry || new ComponentRegistry()
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Validate application configuration for potential conflicts
|
|
32
|
-
* @param {Object} application - Must have register() method
|
|
33
|
-
* @param {Object} [configuration] - Custom integration settings
|
|
34
|
-
* @returns {Array<string>} List of collision errors
|
|
35
|
-
*/
|
|
36
|
-
validate(application, configuration = {}) {
|
|
37
|
-
const { api, cli, react } = application.register(configuration)
|
|
38
|
-
const errors = []
|
|
39
|
-
|
|
40
|
-
if (this.apiRegistry.has(api.prefix)) {
|
|
41
|
-
errors.push(`API prefix "${api.prefix}" used by ${this.apiRegistry.getOwner(api.prefix)}`)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (this.cliRegistry.has(cli.command)) {
|
|
45
|
-
errors.push(`CLI command "${cli.command}" used by ${this.cliRegistry.getOwner(cli.command)}`)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Check UI namespace collision (simplified)
|
|
49
|
-
if (react.namespace && this.uiRegistry.findComponents(react.namespace).length > 0) {
|
|
50
|
-
errors.push(`UI namespace "${react.namespace}.*" already has registered components`)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return errors
|
|
54
|
-
}
|
|
55
|
-
}
|
package/src/system/integrator.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import ApiRegistry from '../registry/ApiRegistry.js'
|
|
2
|
-
import CliRegistry from '../registry/CommandRegistry.js'
|
|
3
|
-
import UiRegistry from '../registry/UiRegistry.js'
|
|
4
|
-
import SystemValidator from './Validator.js'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Integrates applications based on configuration file.
|
|
8
|
-
* The config is loaded lazily to avoid TS JSON‑module issues.
|
|
9
|
-
*/
|
|
10
|
-
export class AppIntegrator {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.apiRegistry = new ApiRegistry()
|
|
13
|
-
this.cliRegistry = new CliRegistry()
|
|
14
|
-
this.uiRegistry = new UiRegistry()
|
|
15
|
-
this.validator = new SystemValidator({
|
|
16
|
-
apiRegistry: this.apiRegistry,
|
|
17
|
-
cliRegistry: this.cliRegistry,
|
|
18
|
-
uiRegistry: this.uiRegistry,
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Load the apps configuration (JSON) at runtime.
|
|
24
|
-
* @returns {Promise<Record<string, any>>}
|
|
25
|
-
*/
|
|
26
|
-
async _loadConfig() {
|
|
27
|
-
// @ts-ignore Fix the load
|
|
28
|
-
const { default: cfg } = await import('../config/apps.json')
|
|
29
|
-
return cfg
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Register all configured applications.
|
|
34
|
-
*/
|
|
35
|
-
async registerAll() {
|
|
36
|
-
const config = await this._loadConfig()
|
|
37
|
-
|
|
38
|
-
for (const [packageName, appConfig] of Object.entries(config.apps)) {
|
|
39
|
-
if (!appConfig.enabled) continue
|
|
40
|
-
|
|
41
|
-
const { default: app } = await import(`${packageName}/src/register.js`)
|
|
42
|
-
const validationErrors = this.validator.validate(app, appConfig)
|
|
43
|
-
|
|
44
|
-
if (validationErrors.length > 0) {
|
|
45
|
-
console.error(`❌ ${packageName} conflicts:`, validationErrors)
|
|
46
|
-
continue
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this._registerApp(packageName, app, appConfig)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Internal registration logic.
|
|
55
|
-
* @param {string} packageName
|
|
56
|
-
* @param {object} app
|
|
57
|
-
* @param {object} cfg
|
|
58
|
-
*/
|
|
59
|
-
_registerApp(packageName, app, cfg) {
|
|
60
|
-
const registration = app.register(cfg)
|
|
61
|
-
|
|
62
|
-
if (registration.api) {
|
|
63
|
-
this.apiRegistry.register(registration.api.prefix, {
|
|
64
|
-
setup: registration.api.setup,
|
|
65
|
-
owner: packageName,
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (registration.cli) {
|
|
70
|
-
this.cliRegistry.register(registration.cli.command, {
|
|
71
|
-
setup: registration.cli.setup,
|
|
72
|
-
owner: packageName,
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (registration.ui) {
|
|
77
|
-
// ComponentRegistry expects a `register` method; we store the loader function.
|
|
78
|
-
this.uiRegistry.register(registration.ui.namespace, {
|
|
79
|
-
component: registration.ui.loader,
|
|
80
|
-
owner: packageName,
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
package/src/system/main.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import RouteRegistry from '../registry/RouteRegistry.js'
|
|
2
|
-
import CommandRegistry from '../registry/CommandRegistry.js'
|
|
3
|
-
import SystemValidator from './Validator.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* System bootstrapper
|
|
7
|
-
* Integrates all applications into shared infrastructure
|
|
8
|
-
*
|
|
9
|
-
* Flow:
|
|
10
|
-
* 1. Create registries
|
|
11
|
-
* 2. Validate integrations
|
|
12
|
-
* 3. Register conflict‑free apps
|
|
13
|
-
* 4. Start services
|
|
14
|
-
*/
|
|
15
|
-
async function bootstrapSystem() {
|
|
16
|
-
// Create shared registries
|
|
17
|
-
const apiRegistry = new RouteRegistry()
|
|
18
|
-
const cliRegistry = new CommandRegistry()
|
|
19
|
-
|
|
20
|
-
// Setup validator with all registries
|
|
21
|
-
const validator = new SystemValidator({
|
|
22
|
-
apiRegistry,
|
|
23
|
-
cliRegistry,
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
// Import and validate auth application
|
|
27
|
-
// @ts-ignore Fix the load of aith.app
|
|
28
|
-
const { default: authApp } = await import('@nan0web/auth.app/src/register.js')
|
|
29
|
-
const validationErrors = validator.validate(authApp, {
|
|
30
|
-
api: { prefix: 'auth' },
|
|
31
|
-
cli: { command: 'auth' },
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
// Handle potential conflicts
|
|
35
|
-
if (validationErrors.length > 0) {
|
|
36
|
-
console.error('❌ Integration conflicts detected:', validationErrors)
|
|
37
|
-
console.log('Resolve with: authApp.register({ api: { prefix: "auth2" } })')
|
|
38
|
-
process.exit(1)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Register validated application
|
|
42
|
-
const { api, cli, react } = authApp.register({
|
|
43
|
-
api: { prefix: 'auth' },
|
|
44
|
-
cli: { command: 'auth' },
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
api.setup(apiRegistry)
|
|
48
|
-
cliRegistry.register(cli.command, cli.setup)
|
|
49
|
-
if (react && typeof react.setup === 'function') {
|
|
50
|
-
react.setup(/* component registry placeholder */)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Start infrastructure services
|
|
54
|
-
startApiServer(apiRegistry)
|
|
55
|
-
startCliProcessor(cliRegistry)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/* ---------- Helper stubs for build (replace with real implementations) ---------- */
|
|
59
|
-
function startCliProcessor(registry) {
|
|
60
|
-
console.log('⚙️ CLI processor started with', registry.getCommands().size, 'commands')
|
|
61
|
-
}
|
|
62
|
-
function createHttpServer() {
|
|
63
|
-
return {
|
|
64
|
-
use: (path, handler) => console.log(`🔌 Route mounted: ${path}`),
|
|
65
|
-
listen: (port) => console.log(`🚀 HTTP server listening on port ${port}`),
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/* --------------------------------------------------------------------------- */
|
|
69
|
-
|
|
70
|
-
bootstrapSystem().catch(console.error)
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Start API server with registered routes
|
|
74
|
-
* @param {RouteRegistry} registry
|
|
75
|
-
*/
|
|
76
|
-
function startApiServer(registry) {
|
|
77
|
-
const server = createHttpServer()
|
|
78
|
-
for (const [prefix, { setup }] of registry.getRoutes()) {
|
|
79
|
-
server.use(`/${prefix}`, setup)
|
|
80
|
-
}
|
|
81
|
-
server.listen(420)
|
|
82
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Registry for CLI command namespaces
|
|
3
|
-
* Tracks registered commands and their owners
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* const registry = new CommandRegistry()
|
|
7
|
-
* registry.register('auth', { setup: () => { ... }, owner: '@nan0web/auth.app' })
|
|
8
|
-
* registry.has('auth') // true
|
|
9
|
-
*/
|
|
10
|
-
export default class CommandRegistry {
|
|
11
|
-
/**
|
|
12
|
-
* Register a CLI command namespace
|
|
13
|
-
* @param {string} command - Command name (e.g. 'auth')
|
|
14
|
-
* @param {{ setup: Function, owner: string }} config - Setup function and package name
|
|
15
|
-
* @returns {this}
|
|
16
|
-
*/
|
|
17
|
-
register(command: string, config: {
|
|
18
|
-
setup: Function;
|
|
19
|
-
owner: string;
|
|
20
|
-
}): this;
|
|
21
|
-
/**
|
|
22
|
-
* Get all registered commands
|
|
23
|
-
* @returns {Map<string, { setup: Function, owner: string }>}
|
|
24
|
-
*/
|
|
25
|
-
getCommands(): Map<string, {
|
|
26
|
-
setup: Function;
|
|
27
|
-
owner: string;
|
|
28
|
-
}>;
|
|
29
|
-
/**
|
|
30
|
-
* Check if command exists
|
|
31
|
-
* @param {string} command
|
|
32
|
-
* @returns {boolean}
|
|
33
|
-
*/
|
|
34
|
-
has(command: string): boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Get owner of command
|
|
37
|
-
* @param {string} command
|
|
38
|
-
* @returns {string | null}
|
|
39
|
-
*/
|
|
40
|
-
getOwner(command: string): string | null;
|
|
41
|
-
#private;
|
|
42
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Registry for UI components
|
|
3
|
-
* Tracks registered component namespaces
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* const registry = new ComponentRegistry()
|
|
7
|
-
* registry.register('Auth.Login', { component: () => import('./Auth/Login.jsx'), owner: '@nan0web/auth.app' })
|
|
8
|
-
* registry.getComponent('Auth.Login') // Returns component loader
|
|
9
|
-
*/
|
|
10
|
-
export default class ComponentRegistry {
|
|
11
|
-
/**
|
|
12
|
-
* Register a component namespace
|
|
13
|
-
* @param {string} name - Component path (e.g. 'Auth.Login')
|
|
14
|
-
* @param {{ component: Function, owner: string }} config - Component loader and package name
|
|
15
|
-
* @returns {this}
|
|
16
|
-
*/
|
|
17
|
-
register(name: string, config: {
|
|
18
|
-
component: Function;
|
|
19
|
-
owner: string;
|
|
20
|
-
}): this;
|
|
21
|
-
/**
|
|
22
|
-
* Get all registered components
|
|
23
|
-
* @returns {Map<string, { component: Function, owner: string }>}
|
|
24
|
-
*/
|
|
25
|
-
getComponents(): Map<string, {
|
|
26
|
-
component: Function;
|
|
27
|
-
owner: string;
|
|
28
|
-
}>;
|
|
29
|
-
/**
|
|
30
|
-
* Get component loader by name
|
|
31
|
-
* @param {string} name
|
|
32
|
-
* @returns {Function | null}
|
|
33
|
-
*/
|
|
34
|
-
getComponent(name: string): Function | null;
|
|
35
|
-
/**
|
|
36
|
-
* Find components by namespace prefix
|
|
37
|
-
* @param {string} namespace - E.g., 'Auth' to find all Auth.* components
|
|
38
|
-
* @returns {Array<string>} Component names
|
|
39
|
-
*/
|
|
40
|
-
findComponents(namespace: string): Array<string>;
|
|
41
|
-
#private;
|
|
42
|
-
}
|