@mfdaves/okf-odoo 0.0.0-stage → 0.1.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/CHANGELOG.md +44 -0
- package/LICENSE +21 -0
- package/README.md +368 -2
- package/okf/okf-odoo/index.md +11 -0
- package/okf/okf-odoo/overview/okf-odoo.md +51 -0
- package/okf/okf-odoo/reference/access-rights.md +33 -0
- package/okf/okf-odoo/reference/configuration.md +41 -0
- package/okf/okf-odoo/reference/data-tools.md +38 -0
- package/okf/okf-odoo/reference/output.md +35 -0
- package/package.json +54 -4
- package/src/catalog.js +704 -0
- package/src/data-api.js +254 -0
- package/src/index.js +9 -0
- package/src/markdown.js +82 -0
- package/src/odoo.js +340 -0
- package/src/producer.js +280 -0
- package/src/render.js +638 -0
- package/src/schema.js +66 -0
- package/src/tool-pack.js +49 -0
- package/src/tools.js +520 -0
package/src/render.js
ADDED
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Renders a normalised catalog as OKF v0.2 concepts. Output depends only on
|
|
4
|
+
// the catalog and the options: ordering and paths are stable, and the only
|
|
5
|
+
// time value is generated.at, which the host ignores when comparing runs.
|
|
6
|
+
|
|
7
|
+
const crypto = require("node:crypto");
|
|
8
|
+
const path = require("node:path");
|
|
9
|
+
const yaml = require("js-yaml");
|
|
10
|
+
const packageJson = require("../package.json");
|
|
11
|
+
const { cell, clean, codeSpan, inline, lineStart, linkText, row } = require("./markdown");
|
|
12
|
+
|
|
13
|
+
const RELATION_TYPES = Object.freeze([
|
|
14
|
+
"defined_in",
|
|
15
|
+
"extended_by",
|
|
16
|
+
"references",
|
|
17
|
+
"implies",
|
|
18
|
+
"opens",
|
|
19
|
+
"depends_on",
|
|
20
|
+
]);
|
|
21
|
+
const OPERATIONS = { c: "create", r: "read", u: "update", d: "delete" };
|
|
22
|
+
const IDENTIFIER = /^[A-Za-z0-9_.-]+$/;
|
|
23
|
+
|
|
24
|
+
// index.md and log.md are reserved by OKF in every directory of a bundle.
|
|
25
|
+
const RESERVED_BASENAMES = new Set(["index", "log"]);
|
|
26
|
+
|
|
27
|
+
// A path segment that names one file on every file system and is never a
|
|
28
|
+
// reserved basename. Only a lowercase name made of safe characters is used as
|
|
29
|
+
// is; anything else, including a name that differs from another only by case
|
|
30
|
+
// on macOS or Windows, gets a short hash of the original appended.
|
|
31
|
+
function safeSegment(value) {
|
|
32
|
+
const original = String(value).toWellFormed().normalize("NFC");
|
|
33
|
+
if (
|
|
34
|
+
/^[a-z0-9][a-z0-9_.-]*$/.test(original) &&
|
|
35
|
+
!original.endsWith(".") &&
|
|
36
|
+
!RESERVED_BASENAMES.has(original)
|
|
37
|
+
) {
|
|
38
|
+
return original;
|
|
39
|
+
}
|
|
40
|
+
const base = original.replace(/[^A-Za-z0-9_.-]+/g, "-").replace(/^[.-]+|[.-]+$/g, "") || "object";
|
|
41
|
+
const digest = crypto.createHash("sha256").update(original).digest("hex").slice(0, 8);
|
|
42
|
+
return `${base}--${digest}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function conceptMarkdown(frontmatter, body) {
|
|
46
|
+
const header = yaml.dump(frontmatter, { lineWidth: -1, noRefs: true, sortKeys: false });
|
|
47
|
+
return `---\n${header.trimEnd()}\n---\n\n${String(body).trim()}\n`.toWellFormed();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function table(header, rows, empty) {
|
|
51
|
+
if (!rows.length) return empty;
|
|
52
|
+
return [row(header), row(header.map(() => "---")), ...rows.map(row)].join("\n");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function list(items, empty) {
|
|
56
|
+
return items.length ? items.join("\n") : empty;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const files = {
|
|
60
|
+
module: (name) => `modules/${safeSegment(name)}.md`,
|
|
61
|
+
model: (name) => `models/${safeSegment(name)}.md`,
|
|
62
|
+
group: (key) => `groups/${safeSegment(key)}.md`,
|
|
63
|
+
app: (key) => `apps/${safeSegment(key)}.md`,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
function operations(value) {
|
|
67
|
+
const words = [...String(value || "")].map((letter) => OPERATIONS[letter]).filter(Boolean);
|
|
68
|
+
return words.length ? words.join(", ") : "none";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
class Renderer {
|
|
72
|
+
constructor(catalog, options) {
|
|
73
|
+
this.catalog = catalog;
|
|
74
|
+
this.options = options;
|
|
75
|
+
this.sections = new Set(catalog.sections || []);
|
|
76
|
+
this.modules = new Map((catalog.modules || []).map((module) => [module.name, module]));
|
|
77
|
+
this.models = new Map((catalog.models || []).map((model) => [model.model, model]));
|
|
78
|
+
this.groups = new Map((catalog.groups || []).map((group) => [group.key, group]));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
uri(file) {
|
|
82
|
+
return `okf://${this.options.bundle}/${file.slice(0, -3)}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
resource(...parts) {
|
|
86
|
+
const encode = (part) => encodeURIComponent(String(part).toWellFormed());
|
|
87
|
+
return `odoo://${[this.options.source, ...parts].map(encode).join("/")}`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
sources(...models) {
|
|
91
|
+
return models.map((model) => ({
|
|
92
|
+
resource: this.resource(model),
|
|
93
|
+
title: `${this.options.source} ${model}`,
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
generated() {
|
|
98
|
+
const generated = { by: `okf-odoo/${this.options.producerVersion}` };
|
|
99
|
+
if (this.options.generatedAt) generated.at = this.options.generatedAt;
|
|
100
|
+
return generated;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
href(from, to) {
|
|
104
|
+
return path.posix.relative(path.posix.dirname(from), to);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// References are a link when the target is rendered, else plain text that is
|
|
108
|
+
// safe both at the start of a list item and inside a table cell.
|
|
109
|
+
moduleRef(from, name, table = false) {
|
|
110
|
+
return this.modules.has(name)
|
|
111
|
+
? `[${linkText(name)}](${this.href(from, files.module(name))})`
|
|
112
|
+
: codeSpan(name, { table });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
modelRef(from, name, table = false) {
|
|
116
|
+
return this.models.has(name)
|
|
117
|
+
? `[${linkText(name)}](${this.href(from, files.model(name))})`
|
|
118
|
+
: codeSpan(name, { table });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
groupRef(from, group) {
|
|
122
|
+
return this.groups.has(group.key)
|
|
123
|
+
? `[${linkText(group.name)}](${this.href(from, files.group(group.key))})`
|
|
124
|
+
: lineStart(group.name);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
groupRefs(from, groups, empty) {
|
|
128
|
+
return groups.length ? groups.map((group) => this.groupRef(from, group)).join(", ") : empty;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
concept(file, frontmatter, body) {
|
|
132
|
+
const relations = (frontmatter.relations || []).filter(
|
|
133
|
+
(relation, index, all) =>
|
|
134
|
+
all.findIndex(
|
|
135
|
+
(other) => other.type === relation.type && other.target === relation.target,
|
|
136
|
+
) === index,
|
|
137
|
+
);
|
|
138
|
+
const ordered = {
|
|
139
|
+
id: this.uri(file),
|
|
140
|
+
type: frontmatter.type,
|
|
141
|
+
title: clean(frontmatter.title),
|
|
142
|
+
description: clean(frontmatter.description),
|
|
143
|
+
resource: frontmatter.resource,
|
|
144
|
+
sources: frontmatter.sources,
|
|
145
|
+
generated: this.generated(),
|
|
146
|
+
tags: frontmatter.tags,
|
|
147
|
+
};
|
|
148
|
+
if (relations.length) ordered.relations = relations;
|
|
149
|
+
return [file, conceptMarkdown(ordered, body)];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
moduleConcept(module) {
|
|
153
|
+
const file = files.module(module.name);
|
|
154
|
+
const index = this.catalog.modelIndex || [];
|
|
155
|
+
const defined = index.filter((model) => model.definedIn === module.name);
|
|
156
|
+
const extended = index.filter(
|
|
157
|
+
(model) => model.definedIn !== module.name && model.modules.includes(module.name),
|
|
158
|
+
);
|
|
159
|
+
const modelItem = (model) => `- ${this.modelRef(file, model.model)} — ${cell(model.name)}`;
|
|
160
|
+
const facts = [
|
|
161
|
+
`- Technical name: ${codeSpan(module.name)}`,
|
|
162
|
+
`- Installed version: ${codeSpan(module.version)}`,
|
|
163
|
+
module.diskVersion && module.diskVersion !== module.version
|
|
164
|
+
? `- Version on disk: ${codeSpan(module.diskVersion)} (differs from the installed version)`
|
|
165
|
+
: null,
|
|
166
|
+
module.category ? `- Category: ${inline(module.category)}` : null,
|
|
167
|
+
`- Application: ${module.application ? "yes" : "no"}`,
|
|
168
|
+
`- Installed automatically with its dependencies: ${module.autoInstall ? "yes" : "no"}`,
|
|
169
|
+
module.license ? `- License: ${inline(module.license)}` : null,
|
|
170
|
+
`- Documented in full: ${module.selected ? "yes" : "no, summary only"}`,
|
|
171
|
+
].filter(Boolean);
|
|
172
|
+
const body = [
|
|
173
|
+
`# ${inline(module.title)}`,
|
|
174
|
+
"",
|
|
175
|
+
clean(module.summary) ? lineStart(module.summary) : `Odoo module ${codeSpan(module.name)}.`,
|
|
176
|
+
"",
|
|
177
|
+
...facts,
|
|
178
|
+
"",
|
|
179
|
+
"## Dependencies",
|
|
180
|
+
"",
|
|
181
|
+
list(
|
|
182
|
+
module.dependencies.map((name) => `- ${this.moduleRef(file, name)}`),
|
|
183
|
+
"No dependencies.",
|
|
184
|
+
),
|
|
185
|
+
];
|
|
186
|
+
if (this.sections.has("models")) {
|
|
187
|
+
body.push(
|
|
188
|
+
"",
|
|
189
|
+
"## Models defined",
|
|
190
|
+
"",
|
|
191
|
+
list(defined.map(modelItem), "None."),
|
|
192
|
+
"",
|
|
193
|
+
"## Models extended",
|
|
194
|
+
"",
|
|
195
|
+
list(extended.map(modelItem), "None."),
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
return this.concept(
|
|
199
|
+
file,
|
|
200
|
+
{
|
|
201
|
+
type: "Odoo Module",
|
|
202
|
+
title: `${clean(module.title)} (${clean(module.name)})`,
|
|
203
|
+
description: module.summary || `Odoo module ${module.name} (${module.title}).`,
|
|
204
|
+
resource: this.resource("ir.module.module", module.name),
|
|
205
|
+
sources: this.sources("ir.module.module", "ir.module.module.dependency"),
|
|
206
|
+
tags: ["odoo", "module", module.application ? "application" : null].filter(Boolean),
|
|
207
|
+
relations: module.dependencies
|
|
208
|
+
.filter((name) => this.modules.has(name))
|
|
209
|
+
.map((name) => ({ type: "depends_on", target: this.uri(files.module(name)) })),
|
|
210
|
+
},
|
|
211
|
+
body.join("\n"),
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
fieldFlags(file, field) {
|
|
216
|
+
return [
|
|
217
|
+
field.required ? "required" : null,
|
|
218
|
+
field.readonly ? "read-only" : null,
|
|
219
|
+
// A one2many is read through its inverse field and a many2many through
|
|
220
|
+
// a relation table: neither has a column, whatever ir.model.fields says.
|
|
221
|
+
field.type === "one2many" || field.type === "many2many"
|
|
222
|
+
? "not stored (no column)"
|
|
223
|
+
: field.stored
|
|
224
|
+
? "stored"
|
|
225
|
+
: "not stored",
|
|
226
|
+
field.searchable ? null : "not searchable",
|
|
227
|
+
field.type === "one2many" || (!field.stored && !field.related && field.type !== "many2many")
|
|
228
|
+
? "not groupable"
|
|
229
|
+
: null,
|
|
230
|
+
field.index
|
|
231
|
+
? field.index === "indexed"
|
|
232
|
+
? "indexed"
|
|
233
|
+
: `indexed (${inline(field.index)})`
|
|
234
|
+
: null,
|
|
235
|
+
field.translate
|
|
236
|
+
? field.translate === "translated"
|
|
237
|
+
? "translated"
|
|
238
|
+
: `translated (${inline(field.translate)})`
|
|
239
|
+
: null,
|
|
240
|
+
field.companyDependent ? "company-dependent" : null,
|
|
241
|
+
field.related ? `related to ${codeSpan(field.related, { table: true })}` : null,
|
|
242
|
+
field.onDelete ? `on delete ${inline(field.onDelete)}` : null,
|
|
243
|
+
field.custom ? "custom" : null,
|
|
244
|
+
field.groups.length ? `groups: ${this.groupRefs(file, field.groups)}` : null,
|
|
245
|
+
]
|
|
246
|
+
.filter(Boolean)
|
|
247
|
+
.join(", ");
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
modelConcept(model) {
|
|
251
|
+
const file = files.model(model.model);
|
|
252
|
+
const relationTargets = [
|
|
253
|
+
...new Set(
|
|
254
|
+
model.fields
|
|
255
|
+
.map((field) => field.relation)
|
|
256
|
+
.filter((name) => name && name !== model.model && this.models.has(name)),
|
|
257
|
+
),
|
|
258
|
+
].sort();
|
|
259
|
+
const fieldRows = model.fields.map((field) => [
|
|
260
|
+
codeSpan(field.name, { table: true }),
|
|
261
|
+
cell(field.label),
|
|
262
|
+
codeSpan(field.type, { table: true }),
|
|
263
|
+
field.relation
|
|
264
|
+
? `${this.modelRef(file, field.relation, true)}${field.relationField ? ` (${codeSpan(field.relationField, { table: true })})` : ""}`
|
|
265
|
+
: "—",
|
|
266
|
+
this.fieldFlags(file, field) || "—",
|
|
267
|
+
field.modules.map((name) => this.moduleRef(file, name, true)).join(", ") || "—",
|
|
268
|
+
cell(field.help),
|
|
269
|
+
]);
|
|
270
|
+
const selections = model.fields.filter((field) => field.selection.length);
|
|
271
|
+
const extenders = model.modules.filter((name) => name !== model.definedIn);
|
|
272
|
+
const kind = {
|
|
273
|
+
model: "model",
|
|
274
|
+
transient: "transient model (wizard)",
|
|
275
|
+
abstract: "abstract model",
|
|
276
|
+
};
|
|
277
|
+
const body = [
|
|
278
|
+
`# ${inline(model.name)} (${codeSpan(model.model)})`,
|
|
279
|
+
"",
|
|
280
|
+
`- Kind: ${kind[model.kind] || `model or abstract model (Odoo ${this.catalog.odooVersion} does not record which)`}`,
|
|
281
|
+
`- Defined in: ${model.definedIn ? this.moduleRef(file, model.definedIn) : "no module (created in the database)"}`,
|
|
282
|
+
`- Extended by: ${extenders.map((name) => this.moduleRef(file, name)).join(", ") || "no other module"}`,
|
|
283
|
+
model.custom ? "- Custom model created in the database" : null,
|
|
284
|
+
"",
|
|
285
|
+
"## Fields",
|
|
286
|
+
"",
|
|
287
|
+
this.catalog.fieldGroups === false
|
|
288
|
+
? `Field groups are not available on Odoo ${this.catalog.odooVersion}: it does not record which groups may access a field defined in code, so this table cannot show field-level restrictions.\n`
|
|
289
|
+
: null,
|
|
290
|
+
`"not searchable" and "not groupable" follow from how a field is stored; odoo_describe_model gives the exact flags for the signed-in user.${this.catalog.odooVersion === "20" ? " On Odoo 20 a field computed in SQL may be searched and grouped even where marked otherwise." : ""}\n`,
|
|
291
|
+
table(
|
|
292
|
+
["Field", "Label", "Type", "Relation", "Properties", "Modules", "Help"],
|
|
293
|
+
fieldRows,
|
|
294
|
+
"No fields were read.",
|
|
295
|
+
),
|
|
296
|
+
].filter((line) => line !== null);
|
|
297
|
+
if (selections.length) {
|
|
298
|
+
body.push("", "## Selection values", "");
|
|
299
|
+
for (const field of selections) {
|
|
300
|
+
body.push(
|
|
301
|
+
`### ${codeSpan(field.name)}`,
|
|
302
|
+
"",
|
|
303
|
+
...field.selection.map((entry) => `- ${codeSpan(entry.value)} — ${cell(entry.label)}`),
|
|
304
|
+
"",
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (this.sections.has("access")) {
|
|
309
|
+
body.push(
|
|
310
|
+
"",
|
|
311
|
+
"## Access",
|
|
312
|
+
"",
|
|
313
|
+
table(
|
|
314
|
+
["Kind", "Groups", "Operations", "Domain", "Name"],
|
|
315
|
+
model.access.map((entry) => [
|
|
316
|
+
cell(entry.kind),
|
|
317
|
+
this.groupRefs(
|
|
318
|
+
file,
|
|
319
|
+
entry.groups,
|
|
320
|
+
entry.kind === "restriction" ? "everyone" : "all users",
|
|
321
|
+
),
|
|
322
|
+
operations(entry.operations),
|
|
323
|
+
codeSpan(entry.domain, { table: true }),
|
|
324
|
+
cell(entry.name),
|
|
325
|
+
]),
|
|
326
|
+
"No access entries.",
|
|
327
|
+
),
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
if (this.sections.has("crons")) {
|
|
331
|
+
body.push(
|
|
332
|
+
"",
|
|
333
|
+
"## Scheduled jobs",
|
|
334
|
+
"",
|
|
335
|
+
table(
|
|
336
|
+
["Name", "Interval", "Active", "Priority"],
|
|
337
|
+
model.crons.map((cron) => [
|
|
338
|
+
cell(cron.name),
|
|
339
|
+
cell(cron.interval),
|
|
340
|
+
cron.active ? "yes" : "no",
|
|
341
|
+
String(cron.priority),
|
|
342
|
+
]),
|
|
343
|
+
"No scheduled jobs.",
|
|
344
|
+
),
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
if (this.sections.has("reports")) {
|
|
348
|
+
body.push(
|
|
349
|
+
"",
|
|
350
|
+
"## Reports",
|
|
351
|
+
"",
|
|
352
|
+
table(
|
|
353
|
+
["Name", "Report", "Type", "Groups"],
|
|
354
|
+
model.reports.map((report) => [
|
|
355
|
+
cell(report.name),
|
|
356
|
+
codeSpan(report.reportName, { table: true }),
|
|
357
|
+
codeSpan(report.type, { table: true }),
|
|
358
|
+
this.groupRefs(file, report.groups, "—"),
|
|
359
|
+
]),
|
|
360
|
+
"No reports.",
|
|
361
|
+
),
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
if (this.sections.has("serverActions")) {
|
|
365
|
+
body.push(
|
|
366
|
+
"",
|
|
367
|
+
"## Server actions",
|
|
368
|
+
"",
|
|
369
|
+
table(
|
|
370
|
+
["Name", "Type", "In the action menu", "Groups"],
|
|
371
|
+
model.serverActions.map((action) => [
|
|
372
|
+
cell(action.name),
|
|
373
|
+
codeSpan(action.type, { table: true }),
|
|
374
|
+
action.bound ? "yes" : "no",
|
|
375
|
+
this.groupRefs(file, action.groups, "—"),
|
|
376
|
+
]),
|
|
377
|
+
"No server actions.",
|
|
378
|
+
),
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
const readFrom = ["ir.model", "ir.model.fields"];
|
|
382
|
+
if (this.sections.has("access")) {
|
|
383
|
+
readFrom.push(
|
|
384
|
+
...(this.catalog.accessModel === "ir.access"
|
|
385
|
+
? ["ir.access"]
|
|
386
|
+
: ["ir.model.access", "ir.rule"]),
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
if (this.sections.has("crons")) readFrom.push("ir.cron");
|
|
390
|
+
if (this.sections.has("reports")) readFrom.push("ir.actions.report");
|
|
391
|
+
if (this.sections.has("serverActions")) readFrom.push("ir.actions.server");
|
|
392
|
+
const relations = [];
|
|
393
|
+
if (model.definedIn && this.modules.has(model.definedIn)) {
|
|
394
|
+
relations.push({ type: "defined_in", target: this.uri(files.module(model.definedIn)) });
|
|
395
|
+
}
|
|
396
|
+
for (const name of extenders.filter((module) => this.modules.has(module))) {
|
|
397
|
+
relations.push({ type: "extended_by", target: this.uri(files.module(name)) });
|
|
398
|
+
}
|
|
399
|
+
for (const name of relationTargets) {
|
|
400
|
+
relations.push({ type: "references", target: this.uri(files.model(name)) });
|
|
401
|
+
}
|
|
402
|
+
return this.concept(
|
|
403
|
+
file,
|
|
404
|
+
{
|
|
405
|
+
type: "Odoo Model",
|
|
406
|
+
title: model.model,
|
|
407
|
+
description: `Odoo ${kind[model.kind] || "model"} ${model.model} (${model.name})${model.definedIn ? ` defined in ${model.definedIn}` : ""}.`,
|
|
408
|
+
resource: this.resource(model.model),
|
|
409
|
+
sources: this.sources(...readFrom),
|
|
410
|
+
tags: [
|
|
411
|
+
"odoo",
|
|
412
|
+
"model",
|
|
413
|
+
model.kind === "model" ? null : model.kind,
|
|
414
|
+
clean(model.definedIn),
|
|
415
|
+
].filter(Boolean),
|
|
416
|
+
relations,
|
|
417
|
+
},
|
|
418
|
+
body.join("\n"),
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
groupConcept(group) {
|
|
423
|
+
const file = files.group(group.key);
|
|
424
|
+
const impliedBy = (this.catalog.groups || []).filter((other) =>
|
|
425
|
+
other.implies.some((implied) => implied.key === group.key),
|
|
426
|
+
);
|
|
427
|
+
const body = [
|
|
428
|
+
`# ${inline(group.fullName)}`,
|
|
429
|
+
"",
|
|
430
|
+
clean(group.comment)
|
|
431
|
+
? lineStart(group.comment)
|
|
432
|
+
: `Odoo access group ${inline(group.fullName)}.`,
|
|
433
|
+
"",
|
|
434
|
+
group.xmlid ? `- XML id: ${codeSpan(group.xmlid)}` : "- No XML id (created in the database)",
|
|
435
|
+
group.privilege
|
|
436
|
+
? `- ${this.catalog.odooVersion === "18" ? "Application" : "Privilege"}: ${inline(group.privilege)}`
|
|
437
|
+
: null,
|
|
438
|
+
`- Portal or public group: ${group.share ? "yes" : "no"}`,
|
|
439
|
+
"",
|
|
440
|
+
"## Implies",
|
|
441
|
+
"",
|
|
442
|
+
list(
|
|
443
|
+
group.implies.map((implied) => `- ${this.groupRef(file, implied)}`),
|
|
444
|
+
"No implied groups.",
|
|
445
|
+
),
|
|
446
|
+
"",
|
|
447
|
+
"## Implied by",
|
|
448
|
+
"",
|
|
449
|
+
list(
|
|
450
|
+
impliedBy.map(
|
|
451
|
+
(other) => `- ${this.groupRef(file, { key: other.key, name: other.fullName })}`,
|
|
452
|
+
),
|
|
453
|
+
"No group implies this one.",
|
|
454
|
+
),
|
|
455
|
+
].filter((line) => line !== null);
|
|
456
|
+
if (this.sections.has("access")) {
|
|
457
|
+
const granted = (this.catalog.models || []).flatMap((model) =>
|
|
458
|
+
model.access
|
|
459
|
+
.filter((entry) => entry.groups.some((ref) => ref.key === group.key))
|
|
460
|
+
.map((entry) => [
|
|
461
|
+
this.modelRef(file, model.model, true),
|
|
462
|
+
cell(entry.kind),
|
|
463
|
+
operations(entry.operations),
|
|
464
|
+
codeSpan(entry.domain, { table: true }),
|
|
465
|
+
]),
|
|
466
|
+
);
|
|
467
|
+
body.push(
|
|
468
|
+
"",
|
|
469
|
+
"## Access on documented models",
|
|
470
|
+
"",
|
|
471
|
+
table(["Model", "Kind", "Operations", "Domain"], granted, "None."),
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
return this.concept(
|
|
475
|
+
file,
|
|
476
|
+
{
|
|
477
|
+
type: "Odoo Group",
|
|
478
|
+
title: group.fullName,
|
|
479
|
+
description: group.comment || `Odoo access group ${group.fullName}.`,
|
|
480
|
+
resource: this.resource("res.groups", group.key),
|
|
481
|
+
sources: this.sources("res.groups", "ir.model.data"),
|
|
482
|
+
tags: ["odoo", "group", group.share ? "portal" : null].filter(Boolean),
|
|
483
|
+
relations: group.implies
|
|
484
|
+
.filter((implied) => this.groups.has(implied.key))
|
|
485
|
+
.map((implied) => ({ type: "implies", target: this.uri(files.group(implied.key)) })),
|
|
486
|
+
},
|
|
487
|
+
body.join("\n"),
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
actionText(file, action) {
|
|
492
|
+
if (!action) return "";
|
|
493
|
+
if (action.type === "ir.actions.act_window" && action.model) {
|
|
494
|
+
return ` → ${this.modelRef(file, action.model)}`;
|
|
495
|
+
}
|
|
496
|
+
return ` (${codeSpan(action.type)})`;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
appConcept(app) {
|
|
500
|
+
const file = files.app(app.key);
|
|
501
|
+
const items = app.menus.map((menu) => {
|
|
502
|
+
const indent = " ".repeat(menu.depth - 1);
|
|
503
|
+
const groups = menu.groups.length ? ` — groups: ${this.groupRefs(file, menu.groups)}` : "";
|
|
504
|
+
return `${indent}- ${lineStart(menu.path[menu.path.length - 1])}${this.actionText(file, menu.action)}${groups}`;
|
|
505
|
+
});
|
|
506
|
+
const opened = [
|
|
507
|
+
...new Set(
|
|
508
|
+
[app, ...app.menus]
|
|
509
|
+
.map((menu) => menu.action)
|
|
510
|
+
.filter((action) => action?.model && this.models.has(action.model))
|
|
511
|
+
.map((action) => action.model),
|
|
512
|
+
),
|
|
513
|
+
].sort();
|
|
514
|
+
const body = [
|
|
515
|
+
`# ${inline(app.name)}`,
|
|
516
|
+
"",
|
|
517
|
+
`Top-level Odoo menu ${cell(app.name)}${this.actionText(file, app.action)}.`,
|
|
518
|
+
"",
|
|
519
|
+
app.xmlid ? `- XML id: ${codeSpan(app.xmlid)}` : "- No XML id (created in the database)",
|
|
520
|
+
`- Visible to: ${this.groupRefs(file, app.groups, "every user with access to the menus below")}`,
|
|
521
|
+
"",
|
|
522
|
+
"## Menus",
|
|
523
|
+
"",
|
|
524
|
+
list(items, "No submenus."),
|
|
525
|
+
];
|
|
526
|
+
return this.concept(
|
|
527
|
+
file,
|
|
528
|
+
{
|
|
529
|
+
type: "Odoo Application",
|
|
530
|
+
title: app.name,
|
|
531
|
+
description: `Odoo top-level menu ${app.name} with ${app.menus.length} submenus.`,
|
|
532
|
+
resource: this.resource("ir.ui.menu", app.key),
|
|
533
|
+
sources: this.sources("ir.ui.menu", "ir.actions.act_window"),
|
|
534
|
+
tags: ["odoo", "application", "menu"],
|
|
535
|
+
relations: opened.map((name) => ({ type: "opens", target: this.uri(files.model(name)) })),
|
|
536
|
+
},
|
|
537
|
+
body.join("\n"),
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
index() {
|
|
542
|
+
const catalog = this.catalog;
|
|
543
|
+
const block = (title, items) => ["", `## ${title}`, "", list(items, "None.")];
|
|
544
|
+
const body = [`# ${inline(this.options.source)} Odoo catalog`];
|
|
545
|
+
if (this.sections.has("menus")) {
|
|
546
|
+
body.push(
|
|
547
|
+
...block(
|
|
548
|
+
"Applications",
|
|
549
|
+
catalog.apps.map((app) => `- [${linkText(app.name)}](${files.app(app.key)})`),
|
|
550
|
+
),
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
if (this.sections.has("modules")) {
|
|
554
|
+
body.push(
|
|
555
|
+
...block(
|
|
556
|
+
"Modules",
|
|
557
|
+
catalog.modules.map(
|
|
558
|
+
(module) =>
|
|
559
|
+
`- [${linkText(module.name)}](${files.module(module.name)}) — ${cell(module.title)}`,
|
|
560
|
+
),
|
|
561
|
+
),
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
if (this.sections.has("models")) {
|
|
565
|
+
body.push(
|
|
566
|
+
...block(
|
|
567
|
+
"Models",
|
|
568
|
+
catalog.models.map(
|
|
569
|
+
(model) =>
|
|
570
|
+
`- [${linkText(model.model)}](${files.model(model.model)}) — ${cell(model.name)}`,
|
|
571
|
+
),
|
|
572
|
+
),
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
if (this.sections.has("groups")) {
|
|
576
|
+
body.push(
|
|
577
|
+
...block(
|
|
578
|
+
"Groups",
|
|
579
|
+
catalog.groups.map(
|
|
580
|
+
(group) => `- [${linkText(group.fullName)}](${files.group(group.key)})`,
|
|
581
|
+
),
|
|
582
|
+
),
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
return ["index.md", conceptMarkdown({ okf_version: "0.2" }, body.join("\n"))];
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
function normalizeGeneratedAt(value) {
|
|
590
|
+
if (value === undefined || value === null) return null;
|
|
591
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
592
|
+
if (Number.isNaN(date.getTime())) throw new Error("generatedAt must be a valid ISO datetime.");
|
|
593
|
+
return date.toISOString();
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
function buildBundle(catalog, options = {}) {
|
|
597
|
+
if (!catalog || !Array.isArray(catalog.models) || !Array.isArray(catalog.sections)) {
|
|
598
|
+
throw new TypeError("A normalised Odoo catalog is required.");
|
|
599
|
+
}
|
|
600
|
+
const source = String(options.source || "odoo").trim();
|
|
601
|
+
const bundle = String(options.bundle || source).trim();
|
|
602
|
+
if (!IDENTIFIER.test(source) || !IDENTIFIER.test(bundle)) {
|
|
603
|
+
throw new Error(
|
|
604
|
+
"Source and bundle identifiers may contain only letters, numbers, dots, underscores, and hyphens.",
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
const renderer = new Renderer(catalog, {
|
|
608
|
+
source,
|
|
609
|
+
bundle,
|
|
610
|
+
generatedAt: normalizeGeneratedAt(options.generatedAt),
|
|
611
|
+
producerVersion: String(options.producerVersion || packageJson.version),
|
|
612
|
+
});
|
|
613
|
+
const entries = [
|
|
614
|
+
renderer.index(),
|
|
615
|
+
...(catalog.modules || []).map((module) => renderer.moduleConcept(module)),
|
|
616
|
+
...catalog.models.map((model) => renderer.modelConcept(model)),
|
|
617
|
+
...(catalog.groups || []).map((group) => renderer.groupConcept(group)),
|
|
618
|
+
...(catalog.apps || []).map((app) => renderer.appConcept(app)),
|
|
619
|
+
];
|
|
620
|
+
const result = new Map();
|
|
621
|
+
const folded = new Set();
|
|
622
|
+
for (const [file, content] of entries) {
|
|
623
|
+
// Compared without case: macOS and Windows would write both to one file.
|
|
624
|
+
const key = file.toLowerCase();
|
|
625
|
+
if (folded.has(key)) throw new Error(`Two concepts map to the same path: ${file}`);
|
|
626
|
+
folded.add(key);
|
|
627
|
+
result.set(file, content);
|
|
628
|
+
}
|
|
629
|
+
return result;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
module.exports = {
|
|
633
|
+
RELATION_TYPES,
|
|
634
|
+
buildBundle,
|
|
635
|
+
conceptMarkdown,
|
|
636
|
+
normalizeGeneratedAt,
|
|
637
|
+
safeSegment,
|
|
638
|
+
};
|
package/src/schema.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Checks a value against the small JSON Schema subset the tool schemas use:
|
|
4
|
+
// type, enum, properties, required, additionalProperties: false, items,
|
|
5
|
+
// prefixItems, min/maxItems, min/maxLength, pattern, minimum/maximum, anyOf.
|
|
6
|
+
// Returns the path of the first violation, or null. The path names schema
|
|
7
|
+
// properties and array positions only, never a value or an unknown key.
|
|
8
|
+
|
|
9
|
+
function typeOf(value) {
|
|
10
|
+
if (value === null) return "null";
|
|
11
|
+
if (Array.isArray(value)) return "array";
|
|
12
|
+
if (Number.isInteger(value)) return "integer";
|
|
13
|
+
return typeof value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function matchesType(value, type) {
|
|
17
|
+
const actual = typeOf(value);
|
|
18
|
+
return actual === type || (type === "number" && actual === "integer");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function violation(schema, value, path = "") {
|
|
22
|
+
if (!schema || typeof schema !== "object") return null;
|
|
23
|
+
if (schema.anyOf) {
|
|
24
|
+
return schema.anyOf.some((branch) => violation(branch, value, path) === null)
|
|
25
|
+
? null
|
|
26
|
+
: path || "/";
|
|
27
|
+
}
|
|
28
|
+
if (schema.type && !matchesType(value, schema.type)) return path || "/";
|
|
29
|
+
if (schema.enum && !schema.enum.includes(value)) return path || "/";
|
|
30
|
+
if (typeof value === "string") {
|
|
31
|
+
if (schema.minLength !== undefined && value.length < schema.minLength) return path || "/";
|
|
32
|
+
if (schema.maxLength !== undefined && value.length > schema.maxLength) return path || "/";
|
|
33
|
+
if (schema.pattern && !new RegExp(schema.pattern, "u").test(value)) return path || "/";
|
|
34
|
+
}
|
|
35
|
+
if (typeof value === "number") {
|
|
36
|
+
if (schema.minimum !== undefined && value < schema.minimum) return path || "/";
|
|
37
|
+
if (schema.maximum !== undefined && value > schema.maximum) return path || "/";
|
|
38
|
+
}
|
|
39
|
+
if (Array.isArray(value)) {
|
|
40
|
+
if (schema.minItems !== undefined && value.length < schema.minItems) return path || "/";
|
|
41
|
+
if (schema.maxItems !== undefined && value.length > schema.maxItems) return path || "/";
|
|
42
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
43
|
+
const itemSchema = schema.prefixItems?.[index] ?? schema.items;
|
|
44
|
+
const found = violation(itemSchema, value[index], `${path}/${index}`);
|
|
45
|
+
if (found) return found;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (typeOf(value) === "object") {
|
|
49
|
+
for (const key of schema.required || []) {
|
|
50
|
+
if (!Object.hasOwn(value, key)) return `${path}/${key}`;
|
|
51
|
+
}
|
|
52
|
+
for (const [key, child] of Object.entries(value)) {
|
|
53
|
+
const property = schema.properties?.[key];
|
|
54
|
+
if (!property) {
|
|
55
|
+
// The caller's own key is not echoed.
|
|
56
|
+
if (schema.additionalProperties === false) return `${path}/(unexpected property)`;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const found = violation(property, child, `${path}/${key}`);
|
|
60
|
+
if (found) return found;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = { violation };
|