@polytric/openws-sdkgen 0.0.3 → 0.0.4

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.
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/plans/dotnet.ts
31
+ var dotnet_exports = {};
32
+ __export(dotnet_exports, {
33
+ default: () => createPlan
34
+ });
35
+ module.exports = __toCommonJS(dotnet_exports);
36
+
37
+ // ../../node_modules/.pnpm/tsup@8.5.1_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
38
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
39
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
40
+
41
+ // src/plans/dotnet.ts
42
+ var import_node_path = __toESM(require("path"), 1);
43
+ var import_node_url = require("url");
44
+ var __dirname = import_node_path.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
45
+ var TEMPLATE_DIR = import_node_path.default.join(__dirname, "../templates/dotnet");
46
+ function pascalCase(str) {
47
+ return str.charAt(0).toUpperCase() + str.slice(1);
48
+ }
49
+ function camelCase(str) {
50
+ return str.charAt(0).toLowerCase() + str.slice(1);
51
+ }
52
+ function createPlan(ctx) {
53
+ const { ir, request } = ctx;
54
+ if (!ir) throw new Error("ir is required");
55
+ if (!request) throw new Error("request is required");
56
+ const assemblyName = `${pascalCase(ir.package.project)}.${pascalCase(ir.package.service)}.Sdk`;
57
+ ir.assemblyName = assemblyName;
58
+ const plan = [
59
+ {
60
+ name: "assembly definition",
61
+ command: "render",
62
+ getData: () => ir,
63
+ template: import_node_path.default.join(TEMPLATE_DIR, "Service.asmdef.ejs"),
64
+ output: import_node_path.default.join(request.outputPath, assemblyName, `${assemblyName}.asmdef`)
65
+ },
66
+ {
67
+ name: "user assembly reference",
68
+ command: "render",
69
+ getData: () => ir,
70
+ template: import_node_path.default.join(TEMPLATE_DIR, "UserService.asmref.ejs"),
71
+ output: import_node_path.default.join(
72
+ request.outputPath,
73
+ `${assemblyName}.User`,
74
+ `${assemblyName}.User.asmref`
75
+ )
76
+ }
77
+ ];
78
+ for (const networkIr of ir.networks) {
79
+ const networkNamespace = `${pascalCase(ir.package.project)}.${pascalCase(ir.package.service)}.${pascalCase(networkIr.name)}`;
80
+ const networkClassName = `${pascalCase(networkIr.name)}Network`;
81
+ const networkOutputPath = import_node_path.default.join(
82
+ request.outputPath,
83
+ assemblyName,
84
+ pascalCase(networkIr.name)
85
+ );
86
+ const userNetworkOutputPath = import_node_path.default.join(
87
+ request.outputPath,
88
+ `${assemblyName}.User`,
89
+ pascalCase(networkIr.name)
90
+ );
91
+ const hostRoles = [];
92
+ const remoteRoles = [];
93
+ for (const role of networkIr.roles) {
94
+ const roleInfo = {
95
+ roleName: role.name,
96
+ className: pascalCase(role.name),
97
+ varName: camelCase(role.name),
98
+ description: role.description || "",
99
+ baseClassName: role.isHost ? "HostRole" : "RemoteRole",
100
+ endpoints: role.endpoints || []
101
+ };
102
+ if (role.isHost) {
103
+ hostRoles.push(roleInfo);
104
+ } else {
105
+ remoteRoles.push(roleInfo);
106
+ }
107
+ }
108
+ const allRoles = [...hostRoles, ...remoteRoles];
109
+ const allModelImports = allRoles.map((role) => `${networkNamespace}.Models.${role.className}`);
110
+ plan.push({
111
+ name: `network ${networkIr.name}`,
112
+ command: "render",
113
+ getData: () => ({
114
+ namespace: networkNamespace,
115
+ networkClassName,
116
+ networkName: networkIr.name,
117
+ description: networkIr.description,
118
+ version: networkIr.version,
119
+ allRoles
120
+ }),
121
+ template: import_node_path.default.join(TEMPLATE_DIR, "Network.cs.ejs"),
122
+ output: import_node_path.default.join(networkOutputPath, `${networkClassName}.cs`)
123
+ });
124
+ for (const modelIr of networkIr.models) {
125
+ modelIr.namespace = `${networkNamespace}.Models.${pascalCase(modelIr.scopeName)}`;
126
+ modelIr.className = pascalCase(modelIr.modelName);
127
+ if (modelIr.properties) {
128
+ for (const propertyIr of modelIr.properties) {
129
+ propertyIr.propertyName = pascalCase(propertyIr.modelName);
130
+ propertyIr.typeName = mapType(propertyIr);
131
+ }
132
+ }
133
+ }
134
+ for (const handlerIr of networkIr.handlers) {
135
+ handlerIr.modelClassName = pascalCase(handlerIr.handlerName);
136
+ handlerIr.messageName = handlerIr.handlerName;
137
+ handlerIr.methodName = pascalCase(handlerIr.handlerName);
138
+ }
139
+ for (const messageIr of networkIr.messages) {
140
+ messageIr.modelClassName = pascalCase(messageIr.handlerName);
141
+ messageIr.messageName = messageIr.handlerName;
142
+ messageIr.methodName = pascalCase(messageIr.handlerName);
143
+ }
144
+ for (const hostRole of hostRoles) {
145
+ const roleHandlers = networkIr.handlers.filter((h) => h.roleName === hostRole.roleName);
146
+ const modelImports = [`${networkNamespace}.Models.${hostRole.className}`];
147
+ plan.push({
148
+ name: `host role ${hostRole.className}`,
149
+ command: "render",
150
+ getData: () => ({
151
+ namespace: `${networkNamespace}.Roles`,
152
+ handlers: roleHandlers,
153
+ remoteRoles,
154
+ modelImports,
155
+ ...hostRole
156
+ }),
157
+ template: import_node_path.default.join(TEMPLATE_DIR, "HostRole.cs.ejs"),
158
+ output: import_node_path.default.join(networkOutputPath, "Roles", `${hostRole.className}.cs`)
159
+ });
160
+ plan.push({
161
+ name: `user host role ${hostRole.className}`,
162
+ command: "render",
163
+ getData: () => ({
164
+ namespace: `${networkNamespace}.Roles`,
165
+ handlers: roleHandlers,
166
+ remoteRoles,
167
+ modelImports: allModelImports,
168
+ ...hostRole
169
+ }),
170
+ template: import_node_path.default.join(TEMPLATE_DIR, "UserHostRole.cs.ejs"),
171
+ output: import_node_path.default.join(userNetworkOutputPath, "Roles", `${hostRole.className}.cs`)
172
+ });
173
+ }
174
+ for (const remoteRole of remoteRoles) {
175
+ const roleMessages = networkIr.messages.filter((m) => m.roleName === remoteRole.roleName);
176
+ const modelImports = [`${networkNamespace}.Models.${remoteRole.className}`];
177
+ plan.push({
178
+ name: `remote role ${remoteRole.className}`,
179
+ command: "render",
180
+ getData: () => ({
181
+ namespace: `${networkNamespace}.Roles`,
182
+ messages: roleMessages,
183
+ modelImports,
184
+ ...remoteRole
185
+ }),
186
+ template: import_node_path.default.join(TEMPLATE_DIR, "RemoteRole.cs.ejs"),
187
+ output: import_node_path.default.join(networkOutputPath, "Roles", `${remoteRole.className}.cs`)
188
+ });
189
+ }
190
+ for (const modelIr of networkIr.models) {
191
+ if (modelIr.type !== "object") continue;
192
+ plan.push({
193
+ name: `model ${modelIr.className}`,
194
+ command: "render",
195
+ getData: () => modelIr,
196
+ template: import_node_path.default.join(TEMPLATE_DIR, "Model.cs.ejs"),
197
+ output: import_node_path.default.join(
198
+ networkOutputPath,
199
+ "Models",
200
+ pascalCase(modelIr.scopeName),
201
+ `${modelIr.className}.cs`
202
+ )
203
+ });
204
+ }
205
+ }
206
+ return {
207
+ ...ctx,
208
+ plan
209
+ };
210
+ }
211
+ function mapType(property) {
212
+ switch (property.type) {
213
+ case "string":
214
+ return "string";
215
+ case "number":
216
+ return "double";
217
+ case "integer":
218
+ return "int";
219
+ case "boolean":
220
+ return "bool";
221
+ case "array":
222
+ if (!property.items) return "List<object>";
223
+ return `List<${mapType(property.items)}>`;
224
+ case "object":
225
+ return pascalCase(property.modelName);
226
+ default:
227
+ return "object";
228
+ }
229
+ }
@@ -0,0 +1,147 @@
1
+ interface PipelineContext {
2
+ argv: string[];
3
+ rawInput?: RawInput;
4
+ request?: BuildRequest;
5
+ spec?: OpenWsSpec;
6
+ ir?: IR;
7
+ plan?: PlanStep[];
8
+ }
9
+ interface RawInput {
10
+ spec: string;
11
+ out: string;
12
+ project: string;
13
+ hostRole: string[];
14
+ language: 'csharp' | 'javascript';
15
+ environment: 'unity' | 'node' | 'browser';
16
+ frameworks?: string[];
17
+ }
18
+ interface BuildRequest {
19
+ specPath: string;
20
+ outputPath: string;
21
+ project: string;
22
+ hostRoles: string[];
23
+ target: {
24
+ csharp?: {
25
+ environment: 'unity';
26
+ frameworks?: string[];
27
+ };
28
+ javascript?: {
29
+ environment: 'node' | 'browser';
30
+ frameworks?: string[];
31
+ };
32
+ };
33
+ }
34
+ interface OpenWsSpec {
35
+ name: string;
36
+ description?: string;
37
+ version?: string;
38
+ networks: Record<string, NetworkSpec>;
39
+ }
40
+ interface NetworkSpec {
41
+ name: string;
42
+ description?: string;
43
+ version?: string;
44
+ roles: Record<string, RoleSpec>;
45
+ }
46
+ interface RoleSpec {
47
+ name: string;
48
+ description?: string;
49
+ endpoints?: Endpoint[];
50
+ messages: Record<string, MessageSpec>;
51
+ }
52
+ interface Endpoint {
53
+ scheme: 'ws' | 'wss';
54
+ host: string;
55
+ port: number;
56
+ path: string;
57
+ }
58
+ interface MessageSpec {
59
+ description?: string;
60
+ from?: string[];
61
+ payload: JsonSchema;
62
+ }
63
+ interface JsonSchema {
64
+ type: string;
65
+ description?: string;
66
+ properties?: Record<string, JsonSchema>;
67
+ items?: JsonSchema;
68
+ required?: string[];
69
+ }
70
+ interface IR {
71
+ package: IRPackage;
72
+ networks: IRNetwork[];
73
+ assemblyName?: string;
74
+ }
75
+ interface IRPackage {
76
+ project: string;
77
+ service: string;
78
+ description?: string;
79
+ version?: string;
80
+ }
81
+ interface IRNetwork {
82
+ name: string;
83
+ description?: string;
84
+ version?: string;
85
+ roles: IRRole[];
86
+ handlers: IRHandler[];
87
+ messages: IRMessage[];
88
+ models: IRModel[];
89
+ }
90
+ interface IRRole {
91
+ name: string;
92
+ description?: string;
93
+ isHost: boolean;
94
+ endpoints: Endpoint[];
95
+ }
96
+ interface IRHandler {
97
+ roleName: string;
98
+ handlerName: string;
99
+ description?: string;
100
+ modelClassName?: string;
101
+ messageName?: string;
102
+ methodName?: string;
103
+ }
104
+ interface IRMessage {
105
+ roleName: string;
106
+ handlerName: string;
107
+ description?: string;
108
+ modelClassName?: string;
109
+ messageName?: string;
110
+ methodName?: string;
111
+ }
112
+ interface IRModel {
113
+ scopeName: string;
114
+ modelName: string;
115
+ type: string;
116
+ description?: string;
117
+ properties?: IRProperty[];
118
+ namespace?: string;
119
+ className?: string;
120
+ }
121
+ interface IRProperty {
122
+ type: string;
123
+ scopeName: string;
124
+ modelName: string;
125
+ description?: string;
126
+ required?: boolean;
127
+ items?: {
128
+ type: string;
129
+ scopeName: string;
130
+ modelName: string;
131
+ description?: string;
132
+ };
133
+ propertyName?: string;
134
+ typeName?: string;
135
+ }
136
+ interface PlanStep {
137
+ name: string;
138
+ command: 'copy' | 'render';
139
+ input?: string;
140
+ output: string;
141
+ template?: string;
142
+ getData?: () => unknown;
143
+ }
144
+
145
+ declare function createPlan(ctx: PipelineContext): PipelineContext;
146
+
147
+ export { createPlan as default };
@@ -0,0 +1,147 @@
1
+ interface PipelineContext {
2
+ argv: string[];
3
+ rawInput?: RawInput;
4
+ request?: BuildRequest;
5
+ spec?: OpenWsSpec;
6
+ ir?: IR;
7
+ plan?: PlanStep[];
8
+ }
9
+ interface RawInput {
10
+ spec: string;
11
+ out: string;
12
+ project: string;
13
+ hostRole: string[];
14
+ language: 'csharp' | 'javascript';
15
+ environment: 'unity' | 'node' | 'browser';
16
+ frameworks?: string[];
17
+ }
18
+ interface BuildRequest {
19
+ specPath: string;
20
+ outputPath: string;
21
+ project: string;
22
+ hostRoles: string[];
23
+ target: {
24
+ csharp?: {
25
+ environment: 'unity';
26
+ frameworks?: string[];
27
+ };
28
+ javascript?: {
29
+ environment: 'node' | 'browser';
30
+ frameworks?: string[];
31
+ };
32
+ };
33
+ }
34
+ interface OpenWsSpec {
35
+ name: string;
36
+ description?: string;
37
+ version?: string;
38
+ networks: Record<string, NetworkSpec>;
39
+ }
40
+ interface NetworkSpec {
41
+ name: string;
42
+ description?: string;
43
+ version?: string;
44
+ roles: Record<string, RoleSpec>;
45
+ }
46
+ interface RoleSpec {
47
+ name: string;
48
+ description?: string;
49
+ endpoints?: Endpoint[];
50
+ messages: Record<string, MessageSpec>;
51
+ }
52
+ interface Endpoint {
53
+ scheme: 'ws' | 'wss';
54
+ host: string;
55
+ port: number;
56
+ path: string;
57
+ }
58
+ interface MessageSpec {
59
+ description?: string;
60
+ from?: string[];
61
+ payload: JsonSchema;
62
+ }
63
+ interface JsonSchema {
64
+ type: string;
65
+ description?: string;
66
+ properties?: Record<string, JsonSchema>;
67
+ items?: JsonSchema;
68
+ required?: string[];
69
+ }
70
+ interface IR {
71
+ package: IRPackage;
72
+ networks: IRNetwork[];
73
+ assemblyName?: string;
74
+ }
75
+ interface IRPackage {
76
+ project: string;
77
+ service: string;
78
+ description?: string;
79
+ version?: string;
80
+ }
81
+ interface IRNetwork {
82
+ name: string;
83
+ description?: string;
84
+ version?: string;
85
+ roles: IRRole[];
86
+ handlers: IRHandler[];
87
+ messages: IRMessage[];
88
+ models: IRModel[];
89
+ }
90
+ interface IRRole {
91
+ name: string;
92
+ description?: string;
93
+ isHost: boolean;
94
+ endpoints: Endpoint[];
95
+ }
96
+ interface IRHandler {
97
+ roleName: string;
98
+ handlerName: string;
99
+ description?: string;
100
+ modelClassName?: string;
101
+ messageName?: string;
102
+ methodName?: string;
103
+ }
104
+ interface IRMessage {
105
+ roleName: string;
106
+ handlerName: string;
107
+ description?: string;
108
+ modelClassName?: string;
109
+ messageName?: string;
110
+ methodName?: string;
111
+ }
112
+ interface IRModel {
113
+ scopeName: string;
114
+ modelName: string;
115
+ type: string;
116
+ description?: string;
117
+ properties?: IRProperty[];
118
+ namespace?: string;
119
+ className?: string;
120
+ }
121
+ interface IRProperty {
122
+ type: string;
123
+ scopeName: string;
124
+ modelName: string;
125
+ description?: string;
126
+ required?: boolean;
127
+ items?: {
128
+ type: string;
129
+ scopeName: string;
130
+ modelName: string;
131
+ description?: string;
132
+ };
133
+ propertyName?: string;
134
+ typeName?: string;
135
+ }
136
+ interface PlanStep {
137
+ name: string;
138
+ command: 'copy' | 'render';
139
+ input?: string;
140
+ output: string;
141
+ template?: string;
142
+ getData?: () => unknown;
143
+ }
144
+
145
+ declare function createPlan(ctx: PipelineContext): PipelineContext;
146
+
147
+ export { createPlan as default };
@@ -0,0 +1,192 @@
1
+ // src/plans/dotnet.ts
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ var __dirname = path.dirname(fileURLToPath(import.meta.url));
5
+ var TEMPLATE_DIR = path.join(__dirname, "../templates/dotnet");
6
+ function pascalCase(str) {
7
+ return str.charAt(0).toUpperCase() + str.slice(1);
8
+ }
9
+ function camelCase(str) {
10
+ return str.charAt(0).toLowerCase() + str.slice(1);
11
+ }
12
+ function createPlan(ctx) {
13
+ const { ir, request } = ctx;
14
+ if (!ir) throw new Error("ir is required");
15
+ if (!request) throw new Error("request is required");
16
+ const assemblyName = `${pascalCase(ir.package.project)}.${pascalCase(ir.package.service)}.Sdk`;
17
+ ir.assemblyName = assemblyName;
18
+ const plan = [
19
+ {
20
+ name: "assembly definition",
21
+ command: "render",
22
+ getData: () => ir,
23
+ template: path.join(TEMPLATE_DIR, "Service.asmdef.ejs"),
24
+ output: path.join(request.outputPath, assemblyName, `${assemblyName}.asmdef`)
25
+ },
26
+ {
27
+ name: "user assembly reference",
28
+ command: "render",
29
+ getData: () => ir,
30
+ template: path.join(TEMPLATE_DIR, "UserService.asmref.ejs"),
31
+ output: path.join(
32
+ request.outputPath,
33
+ `${assemblyName}.User`,
34
+ `${assemblyName}.User.asmref`
35
+ )
36
+ }
37
+ ];
38
+ for (const networkIr of ir.networks) {
39
+ const networkNamespace = `${pascalCase(ir.package.project)}.${pascalCase(ir.package.service)}.${pascalCase(networkIr.name)}`;
40
+ const networkClassName = `${pascalCase(networkIr.name)}Network`;
41
+ const networkOutputPath = path.join(
42
+ request.outputPath,
43
+ assemblyName,
44
+ pascalCase(networkIr.name)
45
+ );
46
+ const userNetworkOutputPath = path.join(
47
+ request.outputPath,
48
+ `${assemblyName}.User`,
49
+ pascalCase(networkIr.name)
50
+ );
51
+ const hostRoles = [];
52
+ const remoteRoles = [];
53
+ for (const role of networkIr.roles) {
54
+ const roleInfo = {
55
+ roleName: role.name,
56
+ className: pascalCase(role.name),
57
+ varName: camelCase(role.name),
58
+ description: role.description || "",
59
+ baseClassName: role.isHost ? "HostRole" : "RemoteRole",
60
+ endpoints: role.endpoints || []
61
+ };
62
+ if (role.isHost) {
63
+ hostRoles.push(roleInfo);
64
+ } else {
65
+ remoteRoles.push(roleInfo);
66
+ }
67
+ }
68
+ const allRoles = [...hostRoles, ...remoteRoles];
69
+ const allModelImports = allRoles.map((role) => `${networkNamespace}.Models.${role.className}`);
70
+ plan.push({
71
+ name: `network ${networkIr.name}`,
72
+ command: "render",
73
+ getData: () => ({
74
+ namespace: networkNamespace,
75
+ networkClassName,
76
+ networkName: networkIr.name,
77
+ description: networkIr.description,
78
+ version: networkIr.version,
79
+ allRoles
80
+ }),
81
+ template: path.join(TEMPLATE_DIR, "Network.cs.ejs"),
82
+ output: path.join(networkOutputPath, `${networkClassName}.cs`)
83
+ });
84
+ for (const modelIr of networkIr.models) {
85
+ modelIr.namespace = `${networkNamespace}.Models.${pascalCase(modelIr.scopeName)}`;
86
+ modelIr.className = pascalCase(modelIr.modelName);
87
+ if (modelIr.properties) {
88
+ for (const propertyIr of modelIr.properties) {
89
+ propertyIr.propertyName = pascalCase(propertyIr.modelName);
90
+ propertyIr.typeName = mapType(propertyIr);
91
+ }
92
+ }
93
+ }
94
+ for (const handlerIr of networkIr.handlers) {
95
+ handlerIr.modelClassName = pascalCase(handlerIr.handlerName);
96
+ handlerIr.messageName = handlerIr.handlerName;
97
+ handlerIr.methodName = pascalCase(handlerIr.handlerName);
98
+ }
99
+ for (const messageIr of networkIr.messages) {
100
+ messageIr.modelClassName = pascalCase(messageIr.handlerName);
101
+ messageIr.messageName = messageIr.handlerName;
102
+ messageIr.methodName = pascalCase(messageIr.handlerName);
103
+ }
104
+ for (const hostRole of hostRoles) {
105
+ const roleHandlers = networkIr.handlers.filter((h) => h.roleName === hostRole.roleName);
106
+ const modelImports = [`${networkNamespace}.Models.${hostRole.className}`];
107
+ plan.push({
108
+ name: `host role ${hostRole.className}`,
109
+ command: "render",
110
+ getData: () => ({
111
+ namespace: `${networkNamespace}.Roles`,
112
+ handlers: roleHandlers,
113
+ remoteRoles,
114
+ modelImports,
115
+ ...hostRole
116
+ }),
117
+ template: path.join(TEMPLATE_DIR, "HostRole.cs.ejs"),
118
+ output: path.join(networkOutputPath, "Roles", `${hostRole.className}.cs`)
119
+ });
120
+ plan.push({
121
+ name: `user host role ${hostRole.className}`,
122
+ command: "render",
123
+ getData: () => ({
124
+ namespace: `${networkNamespace}.Roles`,
125
+ handlers: roleHandlers,
126
+ remoteRoles,
127
+ modelImports: allModelImports,
128
+ ...hostRole
129
+ }),
130
+ template: path.join(TEMPLATE_DIR, "UserHostRole.cs.ejs"),
131
+ output: path.join(userNetworkOutputPath, "Roles", `${hostRole.className}.cs`)
132
+ });
133
+ }
134
+ for (const remoteRole of remoteRoles) {
135
+ const roleMessages = networkIr.messages.filter((m) => m.roleName === remoteRole.roleName);
136
+ const modelImports = [`${networkNamespace}.Models.${remoteRole.className}`];
137
+ plan.push({
138
+ name: `remote role ${remoteRole.className}`,
139
+ command: "render",
140
+ getData: () => ({
141
+ namespace: `${networkNamespace}.Roles`,
142
+ messages: roleMessages,
143
+ modelImports,
144
+ ...remoteRole
145
+ }),
146
+ template: path.join(TEMPLATE_DIR, "RemoteRole.cs.ejs"),
147
+ output: path.join(networkOutputPath, "Roles", `${remoteRole.className}.cs`)
148
+ });
149
+ }
150
+ for (const modelIr of networkIr.models) {
151
+ if (modelIr.type !== "object") continue;
152
+ plan.push({
153
+ name: `model ${modelIr.className}`,
154
+ command: "render",
155
+ getData: () => modelIr,
156
+ template: path.join(TEMPLATE_DIR, "Model.cs.ejs"),
157
+ output: path.join(
158
+ networkOutputPath,
159
+ "Models",
160
+ pascalCase(modelIr.scopeName),
161
+ `${modelIr.className}.cs`
162
+ )
163
+ });
164
+ }
165
+ }
166
+ return {
167
+ ...ctx,
168
+ plan
169
+ };
170
+ }
171
+ function mapType(property) {
172
+ switch (property.type) {
173
+ case "string":
174
+ return "string";
175
+ case "number":
176
+ return "double";
177
+ case "integer":
178
+ return "int";
179
+ case "boolean":
180
+ return "bool";
181
+ case "array":
182
+ if (!property.items) return "List<object>";
183
+ return `List<${mapType(property.items)}>`;
184
+ case "object":
185
+ return pascalCase(property.modelName);
186
+ default:
187
+ return "object";
188
+ }
189
+ }
190
+ export {
191
+ createPlan as default
192
+ };