@stalfh233/omc-fake-platform 0.5.15 → 0.6.0
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/online-js.d.ts +10 -1
- package/dist/online-js.js +11 -16
- package/dist/programming.d.ts +2 -0
- package/dist/programming.js +155 -0
- package/dist/routes.js +2 -0
- package/dist/state.d.ts +33 -0
- package/dist/state.js +1 -0
- package/package.json +2 -2
package/dist/online-js.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
import { type LaneRoute } from "./state.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* online-js lane: form Online JS (customScript inside draftHtmlJson) is composed
|
|
4
|
+
* through the form/bizsheet faces, so this fake route owns no path of its own.
|
|
5
|
+
*
|
|
6
|
+
* The design-time 在线开发 programming endpoints that used to live here
|
|
7
|
+
* (/api/api/programming/compile|get_source|publish) moved to the dedicated
|
|
8
|
+
* `programming.ts` route — keeping them here made the online-js lane answer for
|
|
9
|
+
* a face it does not own (the exact namespace confusion that once produced the
|
|
10
|
+
* removed `onlinejs.draft/publish` tools).
|
|
11
|
+
*/
|
|
3
12
|
export declare const onlineJsRoute: LaneRoute;
|
package/dist/online-js.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { NOT_HANDLED } from "./state.js";
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return null;
|
|
14
|
-
default:
|
|
15
|
-
return NOT_HANDLED;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
2
|
+
/**
|
|
3
|
+
* online-js lane: form Online JS (customScript inside draftHtmlJson) is composed
|
|
4
|
+
* through the form/bizsheet faces, so this fake route owns no path of its own.
|
|
5
|
+
*
|
|
6
|
+
* The design-time 在线开发 programming endpoints that used to live here
|
|
7
|
+
* (/api/api/programming/compile|get_source|publish) moved to the dedicated
|
|
8
|
+
* `programming.ts` route — keeping them here made the online-js lane answer for
|
|
9
|
+
* a face it does not own (the exact namespace confusion that once produced the
|
|
10
|
+
* removed `onlinejs.draft/publish` tools).
|
|
11
|
+
*/
|
|
12
|
+
export const onlineJsRoute = (_ctx, _input) => NOT_HANDLED;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { businessRefusal, NOT_HANDLED } from "./state.js";
|
|
2
|
+
/**
|
|
3
|
+
* programming lane: the design-time 在线开发 face (`/api/api/programming/*`).
|
|
4
|
+
* Twin of `omc-cli/src/lanes/programming.ts`.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors the 8.6.26 platform semantics (ProgrammingFacadeImpl):
|
|
7
|
+
* draft = version 0 with unconditional overwrite, publish = a NEW published
|
|
8
|
+
* row (version = maxPublished+1) leaving the draft untouched, and — for
|
|
9
|
+
* BUSINESS_RULE sources — publish flips the business rule to coding mode,
|
|
10
|
+
* enables it and marks it published (ProgrammingController.publishBusinessRule).
|
|
11
|
+
*/
|
|
12
|
+
const CODE_TYPE_BUSINESS_RULE = 0;
|
|
13
|
+
const TEMPLATE_PACKAGE = "com.authine.cloudpivot.engine.service.bizrule.handler";
|
|
14
|
+
const PRESET_RULE_CODES = new Set(["Create", "Update", "Delete", "Load", "Cancel", "Available", "GetList"]);
|
|
15
|
+
function templateContent(code, ruleCode) {
|
|
16
|
+
const base = PRESET_RULE_CODES.has(ruleCode) ? `${ruleCode}Handler` : "BaseHandler";
|
|
17
|
+
return [
|
|
18
|
+
`package ${TEMPLATE_PACKAGE};`,
|
|
19
|
+
"",
|
|
20
|
+
"import com.authine.cloudpivot.engine.service.bizrule.handler.context.Request;",
|
|
21
|
+
"",
|
|
22
|
+
`public class ${code} extends ${base} {`,
|
|
23
|
+
"}",
|
|
24
|
+
"",
|
|
25
|
+
].join("\n");
|
|
26
|
+
}
|
|
27
|
+
function sourceKey(schemaCode, ruleCode) {
|
|
28
|
+
return `${schemaCode}#${ruleCode}`;
|
|
29
|
+
}
|
|
30
|
+
function entryOf(ctx, schemaCode, ruleCode) {
|
|
31
|
+
const key = sourceKey(schemaCode, ruleCode);
|
|
32
|
+
const existing = ctx.state.sourceCodes.get(key);
|
|
33
|
+
if (existing)
|
|
34
|
+
return existing;
|
|
35
|
+
const created = { schemaCode, businessRuleCode: ruleCode, codeType: CODE_TYPE_BUSINESS_RULE, draft: null, published: [] };
|
|
36
|
+
ctx.state.sourceCodes.set(key, created);
|
|
37
|
+
return created;
|
|
38
|
+
}
|
|
39
|
+
function readModel(entry, ruleName) {
|
|
40
|
+
const className = entry.draft?.className ?? `${entry.schemaCode}${entry.businessRuleCode}Handler`;
|
|
41
|
+
const code = entry.draft?.code ?? className;
|
|
42
|
+
return {
|
|
43
|
+
code,
|
|
44
|
+
className,
|
|
45
|
+
codeType: entry.codeType,
|
|
46
|
+
schemaCode: entry.schemaCode,
|
|
47
|
+
businessRuleCode: entry.businessRuleCode,
|
|
48
|
+
...(ruleName !== undefined ? { businessRuleName: ruleName } : {}),
|
|
49
|
+
content: entry.draft?.content ?? templateContent(code, entry.businessRuleCode),
|
|
50
|
+
version: entry.draft === null ? null : 0,
|
|
51
|
+
published: entry.published.length > 0,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export const programmingRoute = (ctx, input) => {
|
|
55
|
+
const q = input.query ?? {};
|
|
56
|
+
const body = (input.body ?? {});
|
|
57
|
+
switch (input.path) {
|
|
58
|
+
case "/api/api/programming/list_schemas_by_appcode": {
|
|
59
|
+
// Platform: models of the app filtered to those that HAVE source codes.
|
|
60
|
+
const appCode = String(q.appCode ?? "");
|
|
61
|
+
const schemas = [...ctx.state.models.values()]
|
|
62
|
+
.filter((model) => model.appCode === appCode)
|
|
63
|
+
.filter((model) => [...ctx.state.sourceCodes.values()].some((entry) => entry.schemaCode === model.code && entry.draft !== null))
|
|
64
|
+
.map((model) => ({ code: model.code, name: model.name }));
|
|
65
|
+
return schemas;
|
|
66
|
+
}
|
|
67
|
+
case "/api/api/programming/list_source_by_schemacode": {
|
|
68
|
+
const schemaCode = String(q.schemaCode ?? "");
|
|
69
|
+
const entries = [...ctx.state.sourceCodes.values()].filter((entry) => entry.schemaCode === schemaCode);
|
|
70
|
+
// Platform quirk: a source family row without a persisted draft aborts the
|
|
71
|
+
// whole list with PROGRAMMING_SOURCE_NONEXISTENT.
|
|
72
|
+
const missing = entries.find((entry) => entry.draft === null);
|
|
73
|
+
if (missing)
|
|
74
|
+
return businessRefusal(50000, "PROGRAMMING_SOURCE_NONEXISTENT");
|
|
75
|
+
return entries.map((entry) => {
|
|
76
|
+
const rule = ctx.state.rules.get(sourceKey(schemaCode, entry.businessRuleCode));
|
|
77
|
+
return {
|
|
78
|
+
code: entry.draft.code,
|
|
79
|
+
className: entry.draft.className,
|
|
80
|
+
codeType: entry.codeType,
|
|
81
|
+
schemaCode,
|
|
82
|
+
businessRuleCode: entry.businessRuleCode,
|
|
83
|
+
...(rule ? { businessRuleName: rule.name } : {}),
|
|
84
|
+
content: entry.draft.content,
|
|
85
|
+
version: 0,
|
|
86
|
+
published: entry.published.length > 0,
|
|
87
|
+
...(rule ? { businessRule: rule } : {}),
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
case "/api/api/programming/get_source": {
|
|
92
|
+
const codeType = body.codeType;
|
|
93
|
+
if (codeType !== CODE_TYPE_BUSINESS_RULE)
|
|
94
|
+
return businessRefusal(10005, "SYS_PARAMETER_ERROR");
|
|
95
|
+
const schemaCode = String(body.schemaCode ?? "");
|
|
96
|
+
const ruleCode = String(body.businessRuleCode ?? "");
|
|
97
|
+
if (!schemaCode || !ruleCode)
|
|
98
|
+
return businessRefusal(10005, "schemaCode/businessRuleCode 不能为空");
|
|
99
|
+
const entry = entryOf(ctx, schemaCode, ruleCode);
|
|
100
|
+
const rule = ctx.state.rules.get(sourceKey(schemaCode, ruleCode));
|
|
101
|
+
return readModel(entry, typeof body.businessRuleName === "string" ? body.businessRuleName : rule?.name);
|
|
102
|
+
}
|
|
103
|
+
case "/api/api/programming/saveSourceCode": {
|
|
104
|
+
const schemaCode = String(body.schemaCode ?? "");
|
|
105
|
+
const ruleCode = String(body.businessRuleCode ?? "");
|
|
106
|
+
const content = body.content;
|
|
107
|
+
if (!schemaCode || !ruleCode || typeof content !== "string")
|
|
108
|
+
return businessRefusal(10005, "缺少必传参数");
|
|
109
|
+
const entry = entryOf(ctx, schemaCode, ruleCode);
|
|
110
|
+
const className = String(body.className ?? body.code ?? `${schemaCode}${ruleCode}Handler`);
|
|
111
|
+
entry.draft = { code: String(body.code ?? className), className, content, modifiedAt: Date.now() };
|
|
112
|
+
return readModel(entry, typeof body.businessRuleName === "string" ? body.businessRuleName : undefined);
|
|
113
|
+
}
|
|
114
|
+
case "/api/api/programming/compile": {
|
|
115
|
+
const code = String(body.code ?? "");
|
|
116
|
+
const content = String(body.content ?? "");
|
|
117
|
+
// javac-level minimum the tool relies on: the class declaration must exist
|
|
118
|
+
// and the braces must balance (an unbalanced source is the canonical
|
|
119
|
+
// "compilation failed" shape a caller must fix before publish).
|
|
120
|
+
const bracesBalanced = (content.match(/\{/g)?.length ?? 0) === (content.match(/\}/g)?.length ?? 0);
|
|
121
|
+
const success = content.includes(`class ${code}`) && bracesBalanced;
|
|
122
|
+
return {
|
|
123
|
+
success,
|
|
124
|
+
...(success ? {} : { errors: [{ line: 1, message: `class ${code} not found or unbalanced source` }] }),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
case "/api/api/programming/publish": {
|
|
128
|
+
const schemaCode = String(body.schemaCode ?? "");
|
|
129
|
+
const ruleCode = String(body.businessRuleCode ?? "");
|
|
130
|
+
const content = String(body.content ?? "");
|
|
131
|
+
if (!schemaCode || !ruleCode || content === "")
|
|
132
|
+
return businessRefusal(10005, "缺少必传参数");
|
|
133
|
+
const code = String(body.code ?? `${schemaCode}${ruleCode}Handler`);
|
|
134
|
+
// Platform publish: saveDraftSource → compile → insert published row →
|
|
135
|
+
// flip a BUSINESS_RULE rule to coding mode + enable + publish.
|
|
136
|
+
const entry = entryOf(ctx, schemaCode, ruleCode);
|
|
137
|
+
entry.draft = { code, className: code, content, modifiedAt: Date.now() };
|
|
138
|
+
if (!content.includes(`class ${code}`) || (content.match(/\{/g)?.length ?? 0) !== (content.match(/\}/g)?.length ?? 0))
|
|
139
|
+
return businessRefusal(50000, "PROGRAMMING_COMPILE_FAILED");
|
|
140
|
+
const maxVersion = entry.published.reduce((max, row) => Math.max(max, row.version), 0);
|
|
141
|
+
entry.published.push({ code, className: code, content, version: maxVersion + 1, publishedAt: Date.now() });
|
|
142
|
+
if (body.codeType === CODE_TYPE_BUSINESS_RULE) {
|
|
143
|
+
const rule = ctx.state.rules.get(sourceKey(schemaCode, ruleCode));
|
|
144
|
+
if (rule) {
|
|
145
|
+
rule.developmentMode = "CODING";
|
|
146
|
+
rule.enabled = true;
|
|
147
|
+
rule.publishStatus = "PUBLISHED";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
default:
|
|
153
|
+
return NOT_HANDLED;
|
|
154
|
+
}
|
|
155
|
+
};
|
package/dist/routes.js
CHANGED
|
@@ -10,6 +10,7 @@ import { formRoute } from "./form.js";
|
|
|
10
10
|
import { listViewRoute } from "./list-view.js";
|
|
11
11
|
import { modelRoute } from "./model.js";
|
|
12
12
|
import { onlineJsRoute } from "./online-js.js";
|
|
13
|
+
import { programmingRoute } from "./programming.js";
|
|
13
14
|
import { reportRoute } from "./report.js";
|
|
14
15
|
import { ruleLifecycleRoute } from "./rule-lifecycle.js";
|
|
15
16
|
import { runtimeDataRoute } from "./runtime-data.js";
|
|
@@ -33,6 +34,7 @@ const LANE_ROUTES = [
|
|
|
33
34
|
runtimeDataRoute,
|
|
34
35
|
workflowRoute,
|
|
35
36
|
onlineJsRoute,
|
|
37
|
+
programmingRoute,
|
|
36
38
|
b2Route,
|
|
37
39
|
listViewRoute,
|
|
38
40
|
customPageRoute,
|
package/dist/state.d.ts
CHANGED
|
@@ -310,6 +310,37 @@ export interface FakeFolder {
|
|
|
310
310
|
code?: string;
|
|
311
311
|
parentId?: string;
|
|
312
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* Design-time 在线开发 (programming lane) store — the fake of `h_source_code`.
|
|
315
|
+
*
|
|
316
|
+
* Platform fidelity (8.6.26 source, ProgrammingFacadeImpl):
|
|
317
|
+
* - the DRAFT row is fixed at version=0 and saveSourceCode OVERWRITES its
|
|
318
|
+
* content unconditionally (no optimistic lock);
|
|
319
|
+
* - publish inserts a NEW row (published=true, version = maxPublished+1) and
|
|
320
|
+
* leaves the draft untouched;
|
|
321
|
+
* - runtime executes the latest PUBLISHED row, debug reads the draft;
|
|
322
|
+
* - an unsaved draft still reads back as an in-memory skeleton filled with the
|
|
323
|
+
* rule-type template (version null).
|
|
324
|
+
*/
|
|
325
|
+
export interface FakeSourceCode {
|
|
326
|
+
schemaCode: string;
|
|
327
|
+
businessRuleCode: string;
|
|
328
|
+
/** BUSINESS_RULE=0 / SPI=1 / SERVICE=2 (metadata.app.CodeType index). */
|
|
329
|
+
codeType: number;
|
|
330
|
+
draft: {
|
|
331
|
+
code: string;
|
|
332
|
+
className: string;
|
|
333
|
+
content: string;
|
|
334
|
+
modifiedAt: number;
|
|
335
|
+
} | null;
|
|
336
|
+
published: Array<{
|
|
337
|
+
code: string;
|
|
338
|
+
className: string;
|
|
339
|
+
content: string;
|
|
340
|
+
version: number;
|
|
341
|
+
publishedAt: number;
|
|
342
|
+
}>;
|
|
343
|
+
}
|
|
313
344
|
export interface FakeState {
|
|
314
345
|
fields: Map<string, FakeField>;
|
|
315
346
|
dictionaries: Map<string, FakeDictionary>;
|
|
@@ -353,6 +384,8 @@ export interface FakeState {
|
|
|
353
384
|
/** Ticket 106 — monotonic refId sequence for upload_file. */
|
|
354
385
|
ieUploadSeq: number;
|
|
355
386
|
onlineJs: Map<string, string>;
|
|
387
|
+
/** programming lane (h_source_code): key = `${schemaCode}#${businessRuleCode}`. */
|
|
388
|
+
sourceCodes: Map<string, FakeSourceCode>;
|
|
356
389
|
listViews: Map<string, FakeListView>;
|
|
357
390
|
/** R1-report: report pages keyed by code. */
|
|
358
391
|
reportPages: Map<string, FakeReportPage>;
|
package/dist/state.js
CHANGED
|
@@ -59,6 +59,7 @@ export function createFakeState(options = {}) {
|
|
|
59
59
|
["bpm", { id: "fakepool_bpm", code: "bpm", name: "bpm", databaseType: "MySQL", datasourceType: "DATABASE", jdbcUrl: "jdbc:mysql://127.0.0.1:3306/bpm?useSSL=false", username: "bpm", password: "fake-ciphertext" }],
|
|
60
60
|
]),
|
|
61
61
|
onlineJs: new Map(),
|
|
62
|
+
sourceCodes: new Map(),
|
|
62
63
|
listViews: new Map(),
|
|
63
64
|
reportPages: new Map(),
|
|
64
65
|
biDashboards: new Map(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stalfh233/omc-fake-platform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "OMC 的内存假 CloudPivot 平台(wire 接缝的第二个适配器)+ HTTP 假服务器——@stalfh233/omc-cli 的测试与 bench 基准基座",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"build": "tsc --project tsconfig.build.json"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"omc-core": "0.
|
|
21
|
+
"omc-core": "0.6.0"
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
24
24
|
"node": ">=22.13"
|