@polytric/openws-sdkgen 0.0.3 → 0.0.5
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/main.cjs +62 -209
- package/dist/main.d.cts +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +439 -0
- package/dist/plans/dotnet.cjs +229 -0
- package/dist/plans/dotnet.d.cts +113 -0
- package/dist/plans/dotnet.d.ts +113 -0
- package/dist/plans/dotnet.js +192 -0
- package/dist/templates/dotnet/HostRole.cs.ejs +67 -0
- package/{src/dotnet/template → dist/templates/dotnet}/Model.cs.ejs +1 -1
- package/{src/dotnet/template → dist/templates/dotnet}/RemoteRole.cs.ejs +7 -2
- package/dist/templates/dotnet/UserHostRole.cs.ejs +51 -0
- package/package.json +5 -5
- package/src/dotnet/template/HostRole.cs.ejs +0 -52
- package/src/dotnet/template/UserHostRole.cs.ejs +0 -29
- /package/{src/dotnet/template → dist/templates/dotnet}/Network.cs.ejs +0 -0
- /package/{src/dotnet/template → dist/templates/dotnet}/Service.asmdef.ejs +0 -0
- /package/{src/dotnet/template → dist/templates/dotnet}/UserService.asmref.ejs +0 -0
package/dist/main.cjs
CHANGED
|
@@ -23,10 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
mod
|
|
24
24
|
));
|
|
25
25
|
|
|
26
|
-
// ../../node_modules/.pnpm/tsup@8.5.1_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
|
|
27
|
-
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;
|
|
28
|
-
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
29
|
-
|
|
30
26
|
// src/build-ir.ts
|
|
31
27
|
var import_schema = __toESM(require("@pocketgems/schema"), 1);
|
|
32
28
|
var validateIr = import_schema.default.obj({
|
|
@@ -208,7 +204,11 @@ function buildIr(ctx) {
|
|
|
208
204
|
description: handlerSpec.description
|
|
209
205
|
});
|
|
210
206
|
irNetwork.models.push(
|
|
211
|
-
...buildIrModels(
|
|
207
|
+
...buildIrModels(
|
|
208
|
+
hostRoleSpec.name,
|
|
209
|
+
handlerName + "Payload",
|
|
210
|
+
handlerSpec.payload
|
|
211
|
+
)
|
|
212
212
|
);
|
|
213
213
|
}
|
|
214
214
|
}
|
|
@@ -226,7 +226,9 @@ function buildIr(ctx) {
|
|
|
226
226
|
handlerName,
|
|
227
227
|
description: handlerSpec.description
|
|
228
228
|
});
|
|
229
|
-
irNetwork.models.push(
|
|
229
|
+
irNetwork.models.push(
|
|
230
|
+
...buildIrModels(roleName, handlerName + "Payload", handlerSpec.payload)
|
|
231
|
+
);
|
|
230
232
|
}
|
|
231
233
|
}
|
|
232
234
|
ir.networks.push(irNetwork);
|
|
@@ -238,217 +240,39 @@ function buildIr(ctx) {
|
|
|
238
240
|
};
|
|
239
241
|
}
|
|
240
242
|
|
|
241
|
-
// src/dotnet/build-plan.ts
|
|
242
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
243
|
-
var import_node_url = require("url");
|
|
244
|
-
var __dirname = import_node_path.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
|
|
245
|
-
function pascalCase(str) {
|
|
246
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
247
|
-
}
|
|
248
|
-
function camelCase(str) {
|
|
249
|
-
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
250
|
-
}
|
|
251
|
-
function createPlan(ctx) {
|
|
252
|
-
const { ir, request } = ctx;
|
|
253
|
-
if (!ir) throw new Error("ir is required");
|
|
254
|
-
if (!request) throw new Error("request is required");
|
|
255
|
-
const assemblyName = `${pascalCase(ir.package.project)}.${pascalCase(ir.package.service)}.Sdk`;
|
|
256
|
-
ir.assemblyName = assemblyName;
|
|
257
|
-
const plan = [
|
|
258
|
-
{
|
|
259
|
-
name: "assembly definition",
|
|
260
|
-
command: "render",
|
|
261
|
-
getData: () => ir,
|
|
262
|
-
template: import_node_path.default.join(__dirname, "template", "Service.asmdef.ejs"),
|
|
263
|
-
output: import_node_path.default.join(request.outputPath, assemblyName, `${assemblyName}.asmdef`)
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
name: "user assembly reference",
|
|
267
|
-
command: "render",
|
|
268
|
-
getData: () => ir,
|
|
269
|
-
template: import_node_path.default.join(__dirname, "template", "UserService.asmref.ejs"),
|
|
270
|
-
output: import_node_path.default.join(
|
|
271
|
-
request.outputPath,
|
|
272
|
-
`${assemblyName}.User`,
|
|
273
|
-
`${assemblyName}.User.asmref`
|
|
274
|
-
)
|
|
275
|
-
}
|
|
276
|
-
];
|
|
277
|
-
for (const networkIr of ir.networks) {
|
|
278
|
-
const networkNamespace = `${pascalCase(ir.package.project)}.${pascalCase(ir.package.service)}.${pascalCase(networkIr.name)}`;
|
|
279
|
-
const networkClassName = `${pascalCase(networkIr.name)}Network`;
|
|
280
|
-
const networkOutputPath = import_node_path.default.join(
|
|
281
|
-
request.outputPath,
|
|
282
|
-
assemblyName,
|
|
283
|
-
pascalCase(networkIr.name)
|
|
284
|
-
);
|
|
285
|
-
const userNetworkOutputPath = import_node_path.default.join(
|
|
286
|
-
request.outputPath,
|
|
287
|
-
`${assemblyName}.User`,
|
|
288
|
-
pascalCase(networkIr.name)
|
|
289
|
-
);
|
|
290
|
-
const hostRoles = [];
|
|
291
|
-
const remoteRoles = [];
|
|
292
|
-
for (const role of networkIr.roles) {
|
|
293
|
-
const roleInfo = {
|
|
294
|
-
roleName: role.name,
|
|
295
|
-
className: pascalCase(role.name),
|
|
296
|
-
varName: camelCase(role.name),
|
|
297
|
-
description: role.description || "",
|
|
298
|
-
baseClassName: role.isHost ? "HostRole" : "RemoteRole",
|
|
299
|
-
endpoints: role.endpoints || []
|
|
300
|
-
};
|
|
301
|
-
if (role.isHost) {
|
|
302
|
-
hostRoles.push(roleInfo);
|
|
303
|
-
} else {
|
|
304
|
-
remoteRoles.push(roleInfo);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
const allRoles = [...hostRoles, ...remoteRoles];
|
|
308
|
-
const allModelImports = allRoles.map((role) => `${networkNamespace}.Models.${role.className}`);
|
|
309
|
-
plan.push({
|
|
310
|
-
name: `network ${networkIr.name}`,
|
|
311
|
-
command: "render",
|
|
312
|
-
getData: () => ({
|
|
313
|
-
namespace: networkNamespace,
|
|
314
|
-
networkClassName,
|
|
315
|
-
networkName: networkIr.name,
|
|
316
|
-
description: networkIr.description,
|
|
317
|
-
version: networkIr.version,
|
|
318
|
-
allRoles
|
|
319
|
-
}),
|
|
320
|
-
template: import_node_path.default.join(__dirname, "template", "Network.cs.ejs"),
|
|
321
|
-
output: import_node_path.default.join(networkOutputPath, `${networkClassName}.cs`)
|
|
322
|
-
});
|
|
323
|
-
for (const modelIr of networkIr.models) {
|
|
324
|
-
modelIr.namespace = `${networkNamespace}.Models.${pascalCase(modelIr.scopeName)}`;
|
|
325
|
-
modelIr.className = pascalCase(modelIr.modelName);
|
|
326
|
-
if (modelIr.properties) {
|
|
327
|
-
for (const propertyIr of modelIr.properties) {
|
|
328
|
-
propertyIr.propertyName = pascalCase(propertyIr.modelName);
|
|
329
|
-
propertyIr.typeName = mapType(propertyIr);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
for (const handlerIr of networkIr.handlers) {
|
|
334
|
-
handlerIr.modelClassName = pascalCase(handlerIr.handlerName);
|
|
335
|
-
handlerIr.messageName = handlerIr.handlerName;
|
|
336
|
-
handlerIr.methodName = pascalCase(handlerIr.handlerName);
|
|
337
|
-
}
|
|
338
|
-
for (const messageIr of networkIr.messages) {
|
|
339
|
-
messageIr.modelClassName = pascalCase(messageIr.handlerName);
|
|
340
|
-
messageIr.messageName = messageIr.handlerName;
|
|
341
|
-
messageIr.methodName = pascalCase(messageIr.handlerName);
|
|
342
|
-
}
|
|
343
|
-
for (const hostRole of hostRoles) {
|
|
344
|
-
const roleHandlers = networkIr.handlers.filter((h) => h.roleName === hostRole.roleName);
|
|
345
|
-
const modelImports = [`${networkNamespace}.Models.${hostRole.className}`];
|
|
346
|
-
plan.push({
|
|
347
|
-
name: `host role ${hostRole.className}`,
|
|
348
|
-
command: "render",
|
|
349
|
-
getData: () => ({
|
|
350
|
-
namespace: `${networkNamespace}.Roles`,
|
|
351
|
-
handlers: roleHandlers,
|
|
352
|
-
remoteRoles,
|
|
353
|
-
modelImports,
|
|
354
|
-
...hostRole
|
|
355
|
-
}),
|
|
356
|
-
template: import_node_path.default.join(__dirname, "template", "HostRole.cs.ejs"),
|
|
357
|
-
output: import_node_path.default.join(networkOutputPath, "Roles", `${hostRole.className}.cs`)
|
|
358
|
-
});
|
|
359
|
-
plan.push({
|
|
360
|
-
name: `user host role ${hostRole.className}`,
|
|
361
|
-
command: "render",
|
|
362
|
-
getData: () => ({
|
|
363
|
-
namespace: `${networkNamespace}.Roles`,
|
|
364
|
-
handlers: roleHandlers,
|
|
365
|
-
remoteRoles,
|
|
366
|
-
modelImports: allModelImports,
|
|
367
|
-
...hostRole
|
|
368
|
-
}),
|
|
369
|
-
template: import_node_path.default.join(__dirname, "template", "UserHostRole.cs.ejs"),
|
|
370
|
-
output: import_node_path.default.join(userNetworkOutputPath, "Roles", `${hostRole.className}.cs`)
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
for (const remoteRole of remoteRoles) {
|
|
374
|
-
const roleMessages = networkIr.messages.filter((m) => m.roleName === remoteRole.roleName);
|
|
375
|
-
const modelImports = [`${networkNamespace}.Models.${remoteRole.className}`];
|
|
376
|
-
plan.push({
|
|
377
|
-
name: `remote role ${remoteRole.className}`,
|
|
378
|
-
command: "render",
|
|
379
|
-
getData: () => ({
|
|
380
|
-
namespace: `${networkNamespace}.Roles`,
|
|
381
|
-
messages: roleMessages,
|
|
382
|
-
modelImports,
|
|
383
|
-
...remoteRole
|
|
384
|
-
}),
|
|
385
|
-
template: import_node_path.default.join(__dirname, "template", "RemoteRole.cs.ejs"),
|
|
386
|
-
output: import_node_path.default.join(networkOutputPath, "Roles", `${remoteRole.className}.cs`)
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
for (const modelIr of networkIr.models) {
|
|
390
|
-
if (modelIr.type !== "object") continue;
|
|
391
|
-
plan.push({
|
|
392
|
-
name: `model ${modelIr.className}`,
|
|
393
|
-
command: "render",
|
|
394
|
-
getData: () => modelIr,
|
|
395
|
-
template: import_node_path.default.join(__dirname, "template", "Model.cs.ejs"),
|
|
396
|
-
output: import_node_path.default.join(
|
|
397
|
-
networkOutputPath,
|
|
398
|
-
"Models",
|
|
399
|
-
pascalCase(modelIr.scopeName),
|
|
400
|
-
`${modelIr.className}.cs`
|
|
401
|
-
)
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
return {
|
|
406
|
-
...ctx,
|
|
407
|
-
plan
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
function mapType(property) {
|
|
411
|
-
switch (property.type) {
|
|
412
|
-
case "string":
|
|
413
|
-
return "string";
|
|
414
|
-
case "number":
|
|
415
|
-
return "double";
|
|
416
|
-
case "integer":
|
|
417
|
-
return "int";
|
|
418
|
-
case "boolean":
|
|
419
|
-
return "bool";
|
|
420
|
-
case "array":
|
|
421
|
-
if (!property.items) return "List<object>";
|
|
422
|
-
return `List<${mapType(property.items)}>`;
|
|
423
|
-
case "object":
|
|
424
|
-
return pascalCase(property.modelName);
|
|
425
|
-
default:
|
|
426
|
-
return "object";
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
243
|
// src/build-plan.ts
|
|
431
244
|
var planIndex = {
|
|
432
245
|
csharp: {
|
|
433
|
-
unity:
|
|
246
|
+
unity: "./plans/dotnet.js"
|
|
434
247
|
}
|
|
435
248
|
};
|
|
436
|
-
function dispatchBuildPlan(ctx) {
|
|
249
|
+
async function dispatchBuildPlan(ctx) {
|
|
437
250
|
const { request } = ctx;
|
|
438
251
|
if (!request) throw new Error("request is required");
|
|
439
252
|
const language = Object.keys(request.target)[0];
|
|
440
253
|
const targetConfig = request.target[language];
|
|
441
254
|
if (!targetConfig) throw new Error(`No target config for language: ${language}`);
|
|
442
255
|
const environment = targetConfig.environment;
|
|
443
|
-
const
|
|
444
|
-
if (!
|
|
256
|
+
const planPath = planIndex[language]?.[environment];
|
|
257
|
+
if (!planPath) throw new Error(`No plan for ${language}/${environment}`);
|
|
258
|
+
const { default: plan } = await import(planPath);
|
|
445
259
|
return plan(ctx);
|
|
446
260
|
}
|
|
447
261
|
|
|
448
262
|
// src/build-request.ts
|
|
449
|
-
var
|
|
263
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
450
264
|
var import_node_process = __toESM(require("process"), 1);
|
|
451
265
|
var import_schema2 = __toESM(require("@pocketgems/schema"), 1);
|
|
266
|
+
|
|
267
|
+
// src/utils.ts
|
|
268
|
+
function toCamelCase(str) {
|
|
269
|
+
return str.replace(/[-_\s]+/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/\s+/).filter(Boolean).map((word, index) => {
|
|
270
|
+
const lower = word.toLowerCase();
|
|
271
|
+
return index === 0 ? lower : lower.charAt(0).toUpperCase() + lower.slice(1);
|
|
272
|
+
}).join("");
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// src/build-request.ts
|
|
452
276
|
var validateBuildRequest = import_schema2.default.obj({
|
|
453
277
|
specPath: import_schema2.default.str,
|
|
454
278
|
outputPath: import_schema2.default.str,
|
|
@@ -468,12 +292,11 @@ var validateBuildRequest = import_schema2.default.obj({
|
|
|
468
292
|
function buildRequest(ctx) {
|
|
469
293
|
const { rawInput } = ctx;
|
|
470
294
|
if (!rawInput) throw new Error("rawInput is required");
|
|
471
|
-
console.log("Host roles:", rawInput.hostRole);
|
|
472
295
|
const request = {
|
|
473
|
-
specPath:
|
|
474
|
-
outputPath:
|
|
296
|
+
specPath: import_node_path.default.join(import_node_process.default.cwd(), rawInput.spec),
|
|
297
|
+
outputPath: import_node_path.default.join(import_node_process.default.cwd(), rawInput.out),
|
|
475
298
|
project: rawInput.project,
|
|
476
|
-
hostRoles: rawInput.hostRole,
|
|
299
|
+
hostRoles: rawInput.hostRole.map((r) => toCamelCase(r)),
|
|
477
300
|
target: {
|
|
478
301
|
[rawInput.language]: {
|
|
479
302
|
environment: rawInput.environment,
|
|
@@ -490,7 +313,7 @@ function buildRequest(ctx) {
|
|
|
490
313
|
|
|
491
314
|
// src/execute-plan.ts
|
|
492
315
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
493
|
-
var
|
|
316
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
494
317
|
var import_ejs = __toESM(require("ejs"), 1);
|
|
495
318
|
var rendererCache = {};
|
|
496
319
|
function renderTemplate(templatePath, data) {
|
|
@@ -517,7 +340,7 @@ function executePlan(ctx) {
|
|
|
517
340
|
if (!getData || !template) continue;
|
|
518
341
|
const data = getData();
|
|
519
342
|
console.log(data);
|
|
520
|
-
import_node_fs.default.mkdirSync(
|
|
343
|
+
import_node_fs.default.mkdirSync(import_node_path2.default.dirname(output), { recursive: true });
|
|
521
344
|
import_node_fs.default.writeFileSync(output, renderTemplate(template, { ctx: data }));
|
|
522
345
|
break;
|
|
523
346
|
}
|
|
@@ -533,6 +356,27 @@ function loadSpec(ctx) {
|
|
|
533
356
|
if (!request) throw new Error("request is required");
|
|
534
357
|
const { specPath } = request;
|
|
535
358
|
const spec = JSON.parse(import_node_fs2.default.readFileSync(specPath, "utf8"));
|
|
359
|
+
spec.name = toCamelCase(spec.name);
|
|
360
|
+
for (const [networkName, networkSpec] of Object.entries(spec.networks)) {
|
|
361
|
+
for (const [roleName, roleSpec] of Object.entries(networkSpec.roles)) {
|
|
362
|
+
for (const [messageName, messageSpec] of Object.entries(roleSpec.messages)) {
|
|
363
|
+
delete roleSpec.messages[messageName];
|
|
364
|
+
roleSpec.messages[toCamelCase(messageName)] = {
|
|
365
|
+
...messageSpec
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
delete spec.networks[networkName];
|
|
369
|
+
networkSpec.roles[toCamelCase(roleName)] = {
|
|
370
|
+
...roleSpec,
|
|
371
|
+
name: toCamelCase(roleName)
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
delete spec.networks[networkName];
|
|
375
|
+
spec.networks[toCamelCase(networkName)] = {
|
|
376
|
+
...networkSpec,
|
|
377
|
+
name: toCamelCase(networkName)
|
|
378
|
+
};
|
|
379
|
+
}
|
|
536
380
|
return {
|
|
537
381
|
...ctx,
|
|
538
382
|
spec
|
|
@@ -603,7 +447,16 @@ var Pipeline = [
|
|
|
603
447
|
dispatchBuildPlan,
|
|
604
448
|
executePlan
|
|
605
449
|
];
|
|
606
|
-
function main() {
|
|
607
|
-
|
|
450
|
+
async function main() {
|
|
451
|
+
let ctx = { argv: process.argv };
|
|
452
|
+
for (const step of Pipeline) {
|
|
453
|
+
ctx = await step(ctx);
|
|
454
|
+
}
|
|
455
|
+
return ctx;
|
|
608
456
|
}
|
|
609
|
-
|
|
457
|
+
main().then((result) => {
|
|
458
|
+
console.log(JSON.stringify(result, null, 2));
|
|
459
|
+
}).catch((err) => {
|
|
460
|
+
console.error(err);
|
|
461
|
+
process.exit(1);
|
|
462
|
+
});
|
package/dist/main.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|