@dokebi/module 0.4.0 → 0.4.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/dist/parts.js ADDED
@@ -0,0 +1,231 @@
1
+ // The UI parts a module offers (D-0203): the Vue components, directives, CSS classes and widgets
2
+ // that page authors, an editor and an AI place on screens — each with its name, a line of what it
3
+ // is and when to use it, its props, slots and events, example markup and the address of its live
4
+ // sample. A module points at one JSON file (`parts: new URL('./parts.json', import.meta.url)`),
5
+ // usually generated from its .vue files so the props are never written twice; `dokebi describe
6
+ // --json` reads and checks it and gives it as `app.modules[].parts`, and the MCP tools of an editor
7
+ // list and fetch parts from there. A part of kind `widget` names a widget of the same module.
8
+ import { readFile, stat } from 'node:fs/promises';
9
+ import { fileURLToPath } from 'node:url';
10
+ import { types } from 'node:util';
11
+ export const PART_KINDS = ['component', 'directive', 'class', 'widget'];
12
+ export const PARTS_LIMITS = Object.freeze({
13
+ /** Bytes of the parts file. */
14
+ fileBytes: 2_000_000,
15
+ parts: 512,
16
+ /** Props, slots, events or variants of one part. */
17
+ members: 128,
18
+ examples: 16,
19
+ /** Characters of one text (a description, a type, a default). */
20
+ textChars: 2000,
21
+ /** Characters of one example. */
22
+ exampleChars: 8000,
23
+ locales: 32,
24
+ });
25
+ /** Thrown for a parts file that breaks a rule; the caller turns it into INVALID_CONTRACT. */
26
+ export class PartsIssue extends Error {
27
+ }
28
+ const NAME = /^(?:[A-Z][A-Za-z0-9]{0,63}|v-[a-z][a-z0-9-]{0,62}|\.[a-z][a-z0-9-]{0,62}|[a-z][a-z0-9-]{0,63})$/;
29
+ const MEMBER = /^[A-Za-z_$#@:][A-Za-z0-9_$.:#@-]{0,127}$/;
30
+ const LOCALE = /^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/;
31
+ const SAMPLE = /^\/[A-Za-z0-9._~/-]{0,255}(?:#[A-Za-z0-9._-]{1,64})?$/;
32
+ const FILE = /^(?!\/)(?!.*\.\.)[A-Za-z0-9._/-]{1,255}$/;
33
+ const plain = (value) => value !== null &&
34
+ typeof value === 'object' &&
35
+ !Array.isArray(value) &&
36
+ !types.isProxy(value) &&
37
+ [Object.prototype, null].includes(Object.getPrototypeOf(value));
38
+ function only(input, keys, where) {
39
+ const extra = Object.keys(input).find((name) => !keys.includes(name));
40
+ if (extra)
41
+ throw new PartsIssue(`${where} has an unknown field: ${extra}`);
42
+ }
43
+ function str(value, where, limit = PARTS_LIMITS.textChars) {
44
+ if (typeof value !== 'string' || value.length === 0 || value.length > limit)
45
+ throw new PartsIssue(`${where} must be a text of 1 to ${limit} characters`);
46
+ return value;
47
+ }
48
+ function text(value, where) {
49
+ if (typeof value === 'string')
50
+ return str(value, where);
51
+ if (plain(value)) {
52
+ const entries = Object.entries(value);
53
+ if (entries.length > 0 &&
54
+ entries.length <= PARTS_LIMITS.locales &&
55
+ entries.every(([locale, item]) => LOCALE.test(locale) &&
56
+ typeof item === 'string' &&
57
+ item.length > 0 &&
58
+ item.length <= PARTS_LIMITS.textChars))
59
+ return Object.freeze(Object.fromEntries(entries));
60
+ }
61
+ throw new PartsIssue(`${where} must be a text or { <locale>: text }`);
62
+ }
63
+ const optionalText = (input, key, where) => input[key] === undefined ? {} : { [key]: text(input[key], `${where}.${key}`) };
64
+ function list(value, where, limit, item) {
65
+ if (value === undefined)
66
+ return undefined;
67
+ if (!Array.isArray(value) || types.isProxy(value))
68
+ throw new PartsIssue(`${where} must be an array`);
69
+ if (value.length > limit)
70
+ throw new PartsIssue(`${where} has more than ${limit} entries`);
71
+ const names = new Set();
72
+ return Object.freeze(value.map((entry, index) => {
73
+ const at = `${where}[${index}]`;
74
+ if (!plain(entry))
75
+ throw new PartsIssue(`${at} must be an object`);
76
+ if (typeof entry.name !== 'string' || !MEMBER.test(entry.name))
77
+ throw new PartsIssue(`${at}.name must be a name`);
78
+ if (names.has(entry.name))
79
+ throw new PartsIssue(`${where} has ${entry.name} twice`);
80
+ names.add(entry.name);
81
+ return item(entry, at);
82
+ }));
83
+ }
84
+ function readPart(input, at, widgets) {
85
+ only(input, [
86
+ 'name',
87
+ 'kind',
88
+ 'title',
89
+ 'description',
90
+ 'use',
91
+ 'file',
92
+ 'props',
93
+ 'slots',
94
+ 'events',
95
+ 'variants',
96
+ 'examples',
97
+ 'sample',
98
+ 'widget',
99
+ ], at);
100
+ if (typeof input.name !== 'string' || !NAME.test(input.name))
101
+ throw new PartsIssue(`${at}.name must be a component (UiButton), directive (v-name), class (.name) or widget name`);
102
+ if (!PART_KINDS.includes(input.kind))
103
+ throw new PartsIssue(`${at}.kind must be one of ${PART_KINDS.join(', ')}`);
104
+ const kind = input.kind;
105
+ if (input.file !== undefined && (typeof input.file !== 'string' || !FILE.test(input.file)))
106
+ throw new PartsIssue(`${at}.file must be a path inside the module folder`);
107
+ if (input.sample !== undefined &&
108
+ (typeof input.sample !== 'string' || !SAMPLE.test(input.sample)))
109
+ throw new PartsIssue(`${at}.sample must be an address of the app: /path or /path#part`);
110
+ if (kind === 'widget') {
111
+ if (typeof input.widget !== 'string' || !widgets.has(input.widget))
112
+ throw new PartsIssue(`${at}.widget must name a widget of the module`);
113
+ }
114
+ else if (input.widget !== undefined)
115
+ throw new PartsIssue(`${at}.widget is for kind widget only`);
116
+ const props = list(input.props, `${at}.props`, PARTS_LIMITS.members, (prop, where) => {
117
+ only(prop, ['name', 'type', 'required', 'default', 'description'], where);
118
+ if (typeof prop.required !== 'boolean')
119
+ throw new PartsIssue(`${where}.required must be true or false`);
120
+ return Object.freeze({
121
+ name: prop.name,
122
+ type: str(prop.type, `${where}.type`),
123
+ required: prop.required,
124
+ ...(prop.default === undefined ? {} : { default: str(prop.default, `${where}.default`) }),
125
+ ...optionalText(prop, 'description', where),
126
+ });
127
+ });
128
+ const slots = list(input.slots, `${at}.slots`, PARTS_LIMITS.members, (slot, where) => {
129
+ only(slot, ['name', 'props', 'description'], where);
130
+ return Object.freeze({
131
+ name: slot.name,
132
+ ...(slot.props === undefined ? {} : { props: str(slot.props, `${where}.props`) }),
133
+ ...optionalText(slot, 'description', where),
134
+ });
135
+ });
136
+ const events = list(input.events, `${at}.events`, PARTS_LIMITS.members, (event, where) => {
137
+ only(event, ['name', 'payload', 'description'], where);
138
+ return Object.freeze({
139
+ name: event.name,
140
+ ...(event.payload === undefined ? {} : { payload: str(event.payload, `${where}.payload`) }),
141
+ ...optionalText(event, 'description', where),
142
+ });
143
+ });
144
+ const variants = list(input.variants, `${at}.variants`, PARTS_LIMITS.members, (variant, where) => {
145
+ only(variant, ['name', 'description'], where);
146
+ return Object.freeze({
147
+ name: variant.name,
148
+ ...optionalText(variant, 'description', where),
149
+ });
150
+ });
151
+ let examples;
152
+ if (input.examples !== undefined) {
153
+ if (!Array.isArray(input.examples) || input.examples.length > PARTS_LIMITS.examples)
154
+ throw new PartsIssue(`${at}.examples must be an array of at most ${PARTS_LIMITS.examples} texts`);
155
+ examples = Object.freeze(input.examples.map((example, index) => str(example, `${at}.examples[${index}]`, PARTS_LIMITS.exampleChars)));
156
+ }
157
+ return Object.freeze({
158
+ name: input.name,
159
+ kind,
160
+ title: text(input.title, `${at}.title`),
161
+ ...optionalText(input, 'description', at),
162
+ ...optionalText(input, 'use', at),
163
+ ...(input.file === undefined ? {} : { file: input.file }),
164
+ ...(props ? { props } : {}),
165
+ ...(slots ? { slots } : {}),
166
+ ...(events ? { events } : {}),
167
+ ...(variants ? { variants } : {}),
168
+ ...(examples ? { examples } : {}),
169
+ ...(input.sample === undefined ? {} : { sample: input.sample }),
170
+ ...(input.widget === undefined ? {} : { widget: input.widget }),
171
+ });
172
+ }
173
+ /** Checks parsed parts (`{ parts: [...] }`) against the module's widget names. */
174
+ export function checkParts(value, widgets, where = 'parts') {
175
+ if (!plain(value))
176
+ throw new PartsIssue(`${where} must be an object { parts: [...] }`);
177
+ only(value, ['$schema', 'parts'], where);
178
+ if (!Array.isArray(value.parts) || types.isProxy(value.parts))
179
+ throw new PartsIssue(`${where}.parts must be an array`);
180
+ if (value.parts.length > PARTS_LIMITS.parts)
181
+ throw new PartsIssue(`${where}.parts has more than ${PARTS_LIMITS.parts} parts`);
182
+ const known = new Set(widgets);
183
+ const seen = new Set();
184
+ const parts = value.parts.map((entry, index) => {
185
+ const at = `${where}.parts[${index}]`;
186
+ if (!plain(entry))
187
+ throw new PartsIssue(`${at} must be an object`);
188
+ const part = readPart(entry, at, known);
189
+ const key = `${part.kind}:${part.name}`;
190
+ if (seen.has(key))
191
+ throw new PartsIssue(`${where}.parts has the ${part.kind} ${part.name} twice`);
192
+ seen.add(key);
193
+ return part;
194
+ });
195
+ return Object.freeze({ parts: Object.freeze(parts) });
196
+ }
197
+ /** Reads and checks a module's parts file (UTF-8 JSON of at most PARTS_LIMITS.fileBytes). */
198
+ export async function readParts(file, widgets) {
199
+ const path = fileURLToPath(file);
200
+ let info;
201
+ try {
202
+ info = await stat(path);
203
+ }
204
+ catch (error) {
205
+ // A parts file the contract names but the module lacks is a broken contract (D-0203 review).
206
+ if (error.code === 'ENOENT')
207
+ throw new PartsIssue(`${path} does not exist`, { cause: error });
208
+ throw error;
209
+ }
210
+ if (!info.isFile())
211
+ throw new PartsIssue(`${path} is not a file`);
212
+ if (info.size > PARTS_LIMITS.fileBytes)
213
+ throw new PartsIssue(`${path} is larger than ${PARTS_LIMITS.fileBytes} bytes`);
214
+ let source;
215
+ try {
216
+ source = new TextDecoder('utf-8', { fatal: true }).decode(await readFile(path));
217
+ }
218
+ catch (error) {
219
+ if (error instanceof TypeError)
220
+ throw new PartsIssue(`${path} is not UTF-8 text`, { cause: error });
221
+ throw error;
222
+ }
223
+ let value;
224
+ try {
225
+ value = JSON.parse(source);
226
+ }
227
+ catch (error) {
228
+ throw new PartsIssue(`${path} is not JSON: ${error.message}`, { cause: error });
229
+ }
230
+ return checkParts(value, widgets, path);
231
+ }
@@ -0,0 +1,25 @@
1
+ /** Thrown for a preset folder that breaks a rule; index.ts turns it into INVALID_CONTRACT. */
2
+ export declare class PresetIssue extends Error {
3
+ }
4
+ /** Limits of one preset folder. */
5
+ export declare const PRESET_LIMITS: Readonly<{
6
+ /** Files in one preset folder. */
7
+ files: 200;
8
+ /** Bytes of one file. */
9
+ fileBytes: 200000;
10
+ /** Folder depth below pages/. */
11
+ depth: 8;
12
+ /** Items of app.yaml modules and menu, children of one menu item. */
13
+ items: 64;
14
+ }>;
15
+ /** The app kinds a preset is made for (dokebi-platform DEC-03). */
16
+ export declare const PRESET_KINDS: readonly ['admin', 'front'];
17
+ export type PresetKind = (typeof PRESET_KINDS)[number];
18
+ /** The keys a preset's app.yaml may have: what it fills in a new app's app.yaml. */
19
+ export declare const PRESET_APP_KEYS: readonly ['layout', 'modules', 'menu'];
20
+ /** Whether a path inside the folder is a site file (`/` separated). */
21
+ export declare function isSiteFile(file: string): boolean;
22
+ /** Checks the app.yaml of a preset: layout, modules and menu only. */
23
+ export declare function checkPresetApp(text: string, where: string): void;
24
+ /** The files of a preset folder, after checking its shape (see the file comment). */
25
+ export declare function readPreset(folder: URL, where: string): Promise<readonly string[]>;
package/dist/preset.js ADDED
@@ -0,0 +1,165 @@
1
+ // A preset of a module (dokebi-platform DEC-12, DEC-16): a folder shaped like an app's definition
2
+ // folder — app.yaml, theme.css, layouts/<name>.html, components/<name>.html, pages/**/*.html — that
3
+ // an editor copies into a new app. Its app.yaml holds only what the preset fills: layout, modules
4
+ // and menu (the new-app window gives the rest). This file checks the folder's shape when the module
5
+ // sets up and lists its files for describe; what the files hold is @dokebi/pages' check.
6
+ import { readdir, readFile, stat } from 'node:fs/promises';
7
+ import { join } from 'node:path';
8
+ import { fileURLToPath } from 'node:url';
9
+ import { parseDocument } from 'yaml';
10
+ /** Thrown for a preset folder that breaks a rule; index.ts turns it into INVALID_CONTRACT. */
11
+ export class PresetIssue extends Error {
12
+ }
13
+ /** Limits of one preset folder. */
14
+ export const PRESET_LIMITS = Object.freeze({
15
+ /** Files in one preset folder. */
16
+ files: 200,
17
+ /** Bytes of one file. */
18
+ fileBytes: 200_000,
19
+ /** Folder depth below pages/. */
20
+ depth: 8,
21
+ /** Items of app.yaml modules and menu, children of one menu item. */
22
+ items: 64,
23
+ });
24
+ /** The app kinds a preset is made for (dokebi-platform DEC-03). */
25
+ export const PRESET_KINDS = ['admin', 'front'];
26
+ /** The keys a preset's app.yaml may have: what it fills in a new app's app.yaml. */
27
+ export const PRESET_APP_KEYS = ['layout', 'modules', 'menu'];
28
+ // The rules below are @dokebi/pages' own (check.ts PART_NAME, definition.ts appDeclaration), so a
29
+ // preset that passes here is an app.yaml the new app starts with (review: they were looser).
30
+ /** A part name (a layout or a component): the names @dokebi/pages takes (D-0198). */
31
+ const PART = /^[a-z][a-z0-9-]{0,39}$/;
32
+ /** A segment of a page path: a name, or a value of the address in brackets (D-0205). */
33
+ const PAGE_SEGMENT = /^(?:[a-z0-9][a-z0-9_-]{0,63}|\[[a-z][a-z0-9_]{0,31}\])$/;
34
+ const MODULE_NAME = /^[a-z0-9][a-z0-9._-]{0,63}$/;
35
+ const ICON = /^[a-z0-9][a-z0-9-]{0,63}$/;
36
+ const PERMISSION = /^[a-z0-9][a-z0-9_-]*(?:\.[a-z0-9][a-z0-9_-]*)+$/;
37
+ /** A menu address as app.yaml takes it. */
38
+ const MENU_PATH = /^\/[A-Za-z0-9/_.-]*$/;
39
+ /** Characters of a menu item's permission at most (app.yaml). */
40
+ const PERMISSION_MAX = 128;
41
+ /** Whether a path inside the folder is a site file (`/` separated). */
42
+ export function isSiteFile(file) {
43
+ if (file === 'app.yaml' || file === 'theme.css')
44
+ return true;
45
+ const part = /^(layouts|components)\/([^/]+)\.html$/.exec(file);
46
+ if (part)
47
+ return PART.test(part[2]);
48
+ if (!file.startsWith('pages/') || !file.endsWith('.html'))
49
+ return false;
50
+ const segments = file.slice('pages/'.length, -'.html'.length).split('/');
51
+ return (segments.length <= PRESET_LIMITS.depth &&
52
+ segments.every((segment) => PAGE_SEGMENT.test(segment)));
53
+ }
54
+ const plain = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
55
+ /** The files of a preset folder, sorted (hidden files such as .DS_Store are left out). */
56
+ async function filesOf(folder, where) {
57
+ const files = [];
58
+ const walk = async (dir, prefix, depth) => {
59
+ if (depth > PRESET_LIMITS.depth + 1)
60
+ throw new PresetIssue(`${where} is nested too deep`);
61
+ for (const entry of await readdir(dir, { withFileTypes: true })) {
62
+ if (entry.name.startsWith('.'))
63
+ continue;
64
+ const path = `${prefix}${entry.name}`;
65
+ if (entry.isDirectory())
66
+ await walk(join(dir, entry.name), `${path}/`, depth + 1);
67
+ else if (entry.isFile()) {
68
+ if (files.length >= PRESET_LIMITS.files)
69
+ throw new PresetIssue(`${where} has more than ${PRESET_LIMITS.files} files`);
70
+ files.push(path);
71
+ }
72
+ else
73
+ throw new PresetIssue(`${where} has ${path}, which is not a file or a folder`);
74
+ }
75
+ };
76
+ await walk(folder, '', 0);
77
+ return files.sort();
78
+ }
79
+ function menuItems(value, at, nested) {
80
+ if (!Array.isArray(value) || value.length > PRESET_LIMITS.items)
81
+ throw new PresetIssue(`${at} must be a list of at most ${PRESET_LIMITS.items} items`);
82
+ value.forEach((item, index) => {
83
+ const place = `${at}[${index}]`;
84
+ if (!plain(item))
85
+ throw new PresetIssue(`${place} must be { title, path }`);
86
+ const keys = ['title', 'path', 'icon', 'permission', ...(nested ? [] : ['children'])];
87
+ const extra = Object.keys(item).find((key) => !keys.includes(key));
88
+ if (extra)
89
+ throw new PresetIssue(`${place} has an unknown key: ${extra}`);
90
+ if (typeof item.title !== 'string' || item.title.trim() === '' || item.title.length > 200)
91
+ throw new PresetIssue(`${place}.title must be a text of 1 to 200 characters`);
92
+ if (typeof item.path !== 'string' ||
93
+ item.path.length > 256 ||
94
+ !MENU_PATH.test(item.path) ||
95
+ item.path.split('/').includes('..'))
96
+ throw new PresetIssue(`${place}.path must be an address starting with / (letters, digits, / _ . -)`);
97
+ if (item.icon !== undefined && (typeof item.icon !== 'string' || !ICON.test(item.icon)))
98
+ throw new PresetIssue(`${place}.icon must be a lower-case icon name`);
99
+ if (item.permission !== undefined &&
100
+ (typeof item.permission !== 'string' ||
101
+ item.permission.length > PERMISSION_MAX ||
102
+ !PERMISSION.test(item.permission)))
103
+ throw new PresetIssue(`${place}.permission must be a permission key`);
104
+ if (item.children !== undefined)
105
+ menuItems(item.children, `${place}.children`, true);
106
+ });
107
+ }
108
+ /** Checks the app.yaml of a preset: layout, modules and menu only. */
109
+ export function checkPresetApp(text, where) {
110
+ const document = parseDocument(text, { prettyErrors: false, uniqueKeys: true });
111
+ if (document.errors.length)
112
+ throw new PresetIssue(`${where}/app.yaml is not YAML: ${document.errors[0]?.message}`);
113
+ let value;
114
+ try {
115
+ value = document.toJS({ maxAliasCount: 0 }) ?? {};
116
+ }
117
+ catch (error) {
118
+ // An alias (`*x`) is refused by maxAliasCount 0 with a ReferenceError: the preset's problem,
119
+ // named as such, never a raw error at start (review).
120
+ throw new PresetIssue(`${where}/app.yaml uses a YAML alias (&name / *name), write it out`, {
121
+ cause: error,
122
+ });
123
+ }
124
+ if (!plain(value))
125
+ throw new PresetIssue(`${where}/app.yaml must be a mapping`);
126
+ const extra = Object.keys(value).find((key) => !PRESET_APP_KEYS.includes(key));
127
+ if (extra)
128
+ throw new PresetIssue(`${where}/app.yaml has ${extra}: a preset fills only ${PRESET_APP_KEYS.join(', ')} (the new-app window gives the rest)`);
129
+ if (value.layout !== undefined && (typeof value.layout !== 'string' || !PART.test(value.layout)))
130
+ throw new PresetIssue(`${where}/app.yaml layout must be a layout name`);
131
+ if (value.modules !== undefined &&
132
+ (!Array.isArray(value.modules) ||
133
+ value.modules.length > PRESET_LIMITS.items ||
134
+ value.modules.some((name) => typeof name !== 'string' || !MODULE_NAME.test(name))))
135
+ throw new PresetIssue(`${where}/app.yaml modules must be a list of module names`);
136
+ if (value.menu !== undefined)
137
+ menuItems(value.menu, `${where}/app.yaml menu`, false);
138
+ }
139
+ /** The files of a preset folder, after checking its shape (see the file comment). */
140
+ export async function readPreset(folder, where) {
141
+ const path = fileURLToPath(folder);
142
+ let info;
143
+ try {
144
+ info = await stat(path);
145
+ }
146
+ catch (error) {
147
+ // A folder that is not there is the contract's problem, named as such; anything else stays.
148
+ if (error.code !== 'ENOENT')
149
+ throw error;
150
+ }
151
+ if (!info?.isDirectory())
152
+ throw new PresetIssue(`${where} is not a folder: ${path}`);
153
+ const files = await filesOf(path, where);
154
+ const other = files.find((file) => !isSiteFile(file));
155
+ if (other)
156
+ throw new PresetIssue(`${where} has ${other}, which is not a site file (app.yaml, theme.css, layouts/<name>.html, components/<name>.html, pages/<path>.html)`);
157
+ for (const file of files) {
158
+ const size = (await stat(join(path, file))).size;
159
+ if (size > PRESET_LIMITS.fileBytes)
160
+ throw new PresetIssue(`${where}/${file} is larger than ${PRESET_LIMITS.fileBytes} bytes`);
161
+ }
162
+ if (files.includes('app.yaml'))
163
+ checkPresetApp(await readFile(join(path, 'app.yaml'), 'utf8'), where);
164
+ return Object.freeze(files);
165
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dokebi/module",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Feature modules for Dokebi apps: controllers, models, views and routes in one folder mounted under a prefix.",
5
5
  "keywords": [
6
6
  "dokebi",
@@ -18,6 +18,10 @@
18
18
  ".": {
19
19
  "types": "./dist/index.d.ts",
20
20
  "import": "./dist/index.js"
21
+ },
22
+ "./dependency": {
23
+ "types": "./dist/dependency.d.ts",
24
+ "import": "./dist/dependency.js"
21
25
  }
22
26
  },
23
27
  "files": [
@@ -36,6 +40,9 @@
36
40
  "typecheck": "tsc -p tsconfig.test.json --noEmit",
37
41
  "test": "node -e \"require('node:fs').rmSync('.tmp/tests',{recursive:true,force:true})\" && tsc -p tsconfig.test.json && node --test .tmp/tests/tests/*.test.js"
38
42
  },
43
+ "dependencies": {
44
+ "yaml": "2.9.1"
45
+ },
39
46
  "peerDependencies": {
40
47
  "@dokebi/controller": "^0.4.0",
41
48
  "@dokebi/core": "^0.4.0",
@@ -52,6 +59,9 @@
52
59
  "hosts": [
53
60
  "modules"
54
61
  ],
62
+ "contributes": [
63
+ "core:describe"
64
+ ],
55
65
  "install": {
56
66
  "directories": [
57
67
  "src/shared/modules"
@@ -93,10 +103,10 @@
93
103
  }
94
104
  },
95
105
  "devDependencies": {
96
- "@dokebi/controller": "0.4.0",
97
- "@dokebi/template-ejs": "0.4.0",
98
- "@dokebi/template-inertia": "0.4.0",
99
- "@dokebi/web": "0.4.0"
106
+ "@dokebi/controller": "0.4.2",
107
+ "@dokebi/template-ejs": "0.4.3",
108
+ "@dokebi/template-inertia": "0.4.6",
109
+ "@dokebi/web": "0.4.6"
100
110
  },
101
111
  "publishConfig": {
102
112
  "access": "public",
@@ -1,11 +1,22 @@
1
1
  import { defineController } from '@dokebi/controller';
2
2
  import type { ModulePage } from '@dokebi/module';
3
- import { summary } from '../models/summary.ts';
3
+ import { ItemsService } from '../services/items.ts';
4
4
 
5
5
  export class ItemsController {
6
+ readonly #service: ItemsService;
7
+ constructor(service: ItemsService) {
8
+ this.#service = service;
9
+ }
6
10
  list(page: ModulePage) {
7
- return { title: '{{module}}', message: summary(page) };
11
+ return this.#service.list({
12
+ appName: page.app.name,
13
+ base: page.base,
14
+ template: page.app.template,
15
+ });
8
16
  }
9
17
  }
10
18
  // Built once with this module's context; read it with module.controller(itemsController).
11
- export const itemsController = defineController('items', () => new ItemsController());
19
+ export const itemsController = defineController(
20
+ 'items',
21
+ () => new ItemsController(new ItemsService()),
22
+ );
@@ -1,6 +1,6 @@
1
- import type { ModulePage } from '@dokebi/module';
1
+ export type ModuleIdentity = { appName: string; base: string; template: string };
2
2
 
3
- /** Models are plain code; controllers pass them what they need. */
4
- export function summary(page: ModulePage): string {
5
- return `{{module}} module in app ${page.app.name} at ${page.base || '/'} (template: ${page.app.template})`;
3
+ /** A pure model for this starter; services provide data without HTTP objects. */
4
+ export function summary(module: ModuleIdentity): string {
5
+ return `{{module}} module in app ${module.appName} at ${module.base || '/'} (template: ${module.template})`;
6
6
  }
@@ -11,6 +11,10 @@ export default defineModule({
11
11
  // Plugins and other modules this module uses (instances or dependency descriptors).
12
12
  requires: [],
13
13
  controllers: [itemsController],
14
+ // Points of plugins this module contributes to (D-0130), for example MCP tools:
15
+ // contributes: [mcpTools], // import { mcpTools } from '@dokebi/mcp'
16
+ // setup(module) { module.contribute(mcpTools, new ListItems(service)); },
17
+ // The contributed objects use this module's own services; the collector sets up after it.
14
18
  // One folder per template; `default` is required. An app replaces a file of this module by
15
19
  // putting it in src/apps/<app>/views/<template>/{{module}}/.
16
20
  views: new URL('./views/', import.meta.url),
@@ -0,0 +1,7 @@
1
+ import { type ModuleIdentity, summary } from '../models/summary.ts';
2
+
3
+ export class ItemsService {
4
+ list(module: ModuleIdentity) {
5
+ return { title: '{{module}}', message: summary(module) };
6
+ }
7
+ }
@@ -1,11 +1,22 @@
1
1
  import { defineController } from '@dokebi/controller';
2
2
  import type { ModulePage } from '@dokebi/module';
3
- import { summary } from '../models/summary.ts';
3
+ import { ItemsService } from '../services/items.ts';
4
4
 
5
5
  export class ItemsController {
6
+ readonly #service: ItemsService;
7
+ constructor(service: ItemsService) {
8
+ this.#service = service;
9
+ }
6
10
  list(page: ModulePage) {
7
- return { title: '{{module}}', message: summary(page) };
11
+ return this.#service.list({
12
+ appName: page.app.name,
13
+ base: page.base,
14
+ template: page.app.template,
15
+ });
8
16
  }
9
17
  }
10
18
  // Built once with this module's context; read it with module.controller(itemsController).
11
- export const itemsController = defineController('items', () => new ItemsController());
19
+ export const itemsController = defineController(
20
+ 'items',
21
+ () => new ItemsController(new ItemsService()),
22
+ );
@@ -1,6 +1,6 @@
1
- import type { ModulePage } from '@dokebi/module';
1
+ export type ModuleIdentity = { appName: string; base: string; template: string };
2
2
 
3
- /** Models are plain code; controllers pass them what they need. */
4
- export function summary(page: ModulePage): string {
5
- return `{{module}} module in app ${page.app.name} at ${page.base || '/'} (template: ${page.app.template})`;
3
+ /** A pure model for this starter; services provide data without HTTP objects. */
4
+ export function summary(module: ModuleIdentity): string {
5
+ return `{{module}} module in app ${module.appName} at ${module.base || '/'} (template: ${module.template})`;
6
6
  }
@@ -12,5 +12,9 @@ export default defineModule({
12
12
  // Plugins and other modules this module uses (instances or dependency descriptors).
13
13
  requires: [],
14
14
  controllers: [itemsController],
15
+ // Points of plugins this module contributes to (D-0130), for example MCP tools:
16
+ // contributes: [mcpTools], // import { mcpTools } from '@dokebi/mcp'
17
+ // setup(module) { module.contribute(mcpTools, new ListItems(service)); },
18
+ // The contributed objects use this module's own services; the collector sets up after it.
15
19
  routes,
16
20
  });
@@ -0,0 +1,7 @@
1
+ import { type ModuleIdentity, summary } from '../models/summary.ts';
2
+
3
+ export class ItemsService {
4
+ list(module: ModuleIdentity) {
5
+ return { title: '{{module}}', message: summary(module) };
6
+ }
7
+ }