@polytric/openws-sdkgen 0.0.4 → 0.0.6

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.
Files changed (30) hide show
  1. package/README.md +2 -2
  2. package/dist/main.cjs +53 -5
  3. package/dist/main.js +53 -5
  4. package/dist/plans/dotnet.cjs +3 -3
  5. package/dist/plans/dotnet.d.cts +2 -143
  6. package/dist/plans/dotnet.d.ts +2 -143
  7. package/dist/plans/dotnet.js +2 -2
  8. package/dist/plans/typescript.cjs +569 -0
  9. package/dist/plans/typescript.d.cts +6 -0
  10. package/dist/plans/typescript.d.ts +6 -0
  11. package/dist/plans/typescript.js +532 -0
  12. package/dist/templates/dotnet/HostRole.cs.ejs +23 -8
  13. package/dist/templates/dotnet/Model.cs.ejs +1 -1
  14. package/dist/templates/dotnet/RemoteRole.cs.ejs +7 -2
  15. package/dist/templates/dotnet/UserHostRole.cs.ejs +26 -4
  16. package/dist/templates/typescript/package.json.ejs +41 -0
  17. package/dist/templates/typescript/src/core/index.ts.ejs +6 -0
  18. package/dist/templates/typescript/src/core/models/index.ts.ejs +3 -0
  19. package/dist/templates/typescript/src/core/models/model.ts.ejs +41 -0
  20. package/dist/templates/typescript/src/core/network.ts.ejs +517 -0
  21. package/dist/templates/typescript/src/core/roles/index.ts.ejs +3 -0
  22. package/dist/templates/typescript/src/core/roles/role.ts.ejs +104 -0
  23. package/dist/templates/typescript/src/index.ts.ejs +4 -0
  24. package/dist/templates/typescript/src/sdk/index.ts.ejs +3 -0
  25. package/dist/templates/typescript/src/sdk/role.ts.ejs +372 -0
  26. package/dist/templates/typescript/tsconfig.json.ejs +14 -0
  27. package/dist/templates/typescript/tsup.config.ts.ejs +10 -0
  28. package/dist/types-BdZPs123.d.cts +115 -0
  29. package/dist/types-BdZPs123.d.ts +115 -0
  30. package/package.json +13 -4
package/README.md CHANGED
@@ -42,7 +42,7 @@ The CLI exposes the following options:
42
42
  - `--project` (string): Project/namespace prefix for generated code.
43
43
  - `--service` (string): Service name (default: `MyService`).
44
44
  - `--hostRole` (string): Participant role name that represents the host side.
45
- - `--language` (string): Target language (`csharp` or `javascript`).
45
+ - `--language` (string): Target language (`csharp`, `javascript`, or `typescript`).
46
46
  - `--environment` (string|array): Target environment (`unity`, `node`, `browser`).
47
47
 
48
48
  ---
@@ -53,7 +53,7 @@ The generator is wired for:
53
53
 
54
54
  - C# (Unity) with `newtonsoft` serialization templates.
55
55
 
56
- Additional targets are configured through build plans in `tooling/sdkgen/dotnet` and can be expanded as needed.
56
+ Additional targets are configured through build plans in `tooling/sdkgen/src/plans` and can be expanded as needed.
57
57
 
58
58
  ---
59
59
 
package/dist/main.cjs CHANGED
@@ -204,7 +204,11 @@ function buildIr(ctx) {
204
204
  description: handlerSpec.description
205
205
  });
206
206
  irNetwork.models.push(
207
- ...buildIrModels(hostRoleSpec.name, handlerName, handlerSpec.payload)
207
+ ...buildIrModels(
208
+ hostRoleSpec.name,
209
+ handlerName + "Payload",
210
+ handlerSpec.payload
211
+ )
208
212
  );
209
213
  }
210
214
  }
@@ -222,7 +226,9 @@ function buildIr(ctx) {
222
226
  handlerName,
223
227
  description: handlerSpec.description
224
228
  });
225
- irNetwork.models.push(...buildIrModels(roleName, handlerName, handlerSpec.payload));
229
+ irNetwork.models.push(
230
+ ...buildIrModels(roleName, handlerName + "Payload", handlerSpec.payload)
231
+ );
226
232
  }
227
233
  }
228
234
  ir.networks.push(irNetwork);
@@ -238,6 +244,14 @@ function buildIr(ctx) {
238
244
  var planIndex = {
239
245
  csharp: {
240
246
  unity: "./plans/dotnet.js"
247
+ },
248
+ javascript: {
249
+ node: "./plans/typescript.js",
250
+ browser: "./plans/typescript.js"
251
+ },
252
+ typescript: {
253
+ node: "./plans/typescript.js",
254
+ browser: "./plans/typescript.js"
241
255
  }
242
256
  };
243
257
  async function dispatchBuildPlan(ctx) {
@@ -257,6 +271,16 @@ async function dispatchBuildPlan(ctx) {
257
271
  var import_node_path = __toESM(require("path"), 1);
258
272
  var import_node_process = __toESM(require("process"), 1);
259
273
  var import_schema2 = __toESM(require("@pocketgems/schema"), 1);
274
+
275
+ // src/utils.ts
276
+ function toCamelCase(str) {
277
+ 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) => {
278
+ const lower = word.toLowerCase();
279
+ return index === 0 ? lower : lower.charAt(0).toUpperCase() + lower.slice(1);
280
+ }).join("");
281
+ }
282
+
283
+ // src/build-request.ts
260
284
  var validateBuildRequest = import_schema2.default.obj({
261
285
  specPath: import_schema2.default.str,
262
286
  outputPath: import_schema2.default.str,
@@ -270,18 +294,21 @@ var validateBuildRequest = import_schema2.default.obj({
270
294
  javascript: import_schema2.default.obj({
271
295
  environment: import_schema2.default.str.enum("node", "browser"),
272
296
  frameworks: import_schema2.default.arr(import_schema2.default.str.enum("fastify")).optional()
297
+ }).optional(),
298
+ typescript: import_schema2.default.obj({
299
+ environment: import_schema2.default.str.enum("node", "browser"),
300
+ frameworks: import_schema2.default.arr(import_schema2.default.str.enum("fastify")).optional()
273
301
  }).optional()
274
302
  }).min(1).max(1).desc("The target platform to generate code for")
275
303
  }).compile("BuildRequestValidator");
276
304
  function buildRequest(ctx) {
277
305
  const { rawInput } = ctx;
278
306
  if (!rawInput) throw new Error("rawInput is required");
279
- console.log("Host roles:", rawInput.hostRole);
280
307
  const request = {
281
308
  specPath: import_node_path.default.join(import_node_process.default.cwd(), rawInput.spec),
282
309
  outputPath: import_node_path.default.join(import_node_process.default.cwd(), rawInput.out),
283
310
  project: rawInput.project,
284
- hostRoles: rawInput.hostRole,
311
+ hostRoles: rawInput.hostRole.map((r) => toCamelCase(r)),
285
312
  target: {
286
313
  [rawInput.language]: {
287
314
  environment: rawInput.environment,
@@ -341,6 +368,27 @@ function loadSpec(ctx) {
341
368
  if (!request) throw new Error("request is required");
342
369
  const { specPath } = request;
343
370
  const spec = JSON.parse(import_node_fs2.default.readFileSync(specPath, "utf8"));
371
+ spec.name = toCamelCase(spec.name);
372
+ for (const [networkName, networkSpec] of Object.entries(spec.networks)) {
373
+ for (const [roleName, roleSpec] of Object.entries(networkSpec.roles)) {
374
+ for (const [messageName, messageSpec] of Object.entries(roleSpec.messages)) {
375
+ delete roleSpec.messages[messageName];
376
+ roleSpec.messages[toCamelCase(messageName)] = {
377
+ ...messageSpec
378
+ };
379
+ }
380
+ delete spec.networks[networkName];
381
+ networkSpec.roles[toCamelCase(roleName)] = {
382
+ ...roleSpec,
383
+ name: toCamelCase(roleName)
384
+ };
385
+ }
386
+ delete spec.networks[networkName];
387
+ spec.networks[toCamelCase(networkName)] = {
388
+ ...networkSpec,
389
+ name: toCamelCase(networkName)
390
+ };
391
+ }
344
392
  return {
345
393
  ...ctx,
346
394
  spec
@@ -371,7 +419,7 @@ function parseInput(ctx) {
371
419
  }).option("language", {
372
420
  type: "string",
373
421
  description: "The language to generate code for",
374
- choices: ["csharp", "javascript"],
422
+ choices: ["csharp", "javascript", "typescript"],
375
423
  default: "csharp"
376
424
  }).option("environment", {
377
425
  type: "string",
package/dist/main.js CHANGED
@@ -181,7 +181,11 @@ function buildIr(ctx) {
181
181
  description: handlerSpec.description
182
182
  });
183
183
  irNetwork.models.push(
184
- ...buildIrModels(hostRoleSpec.name, handlerName, handlerSpec.payload)
184
+ ...buildIrModels(
185
+ hostRoleSpec.name,
186
+ handlerName + "Payload",
187
+ handlerSpec.payload
188
+ )
185
189
  );
186
190
  }
187
191
  }
@@ -199,7 +203,9 @@ function buildIr(ctx) {
199
203
  handlerName,
200
204
  description: handlerSpec.description
201
205
  });
202
- irNetwork.models.push(...buildIrModels(roleName, handlerName, handlerSpec.payload));
206
+ irNetwork.models.push(
207
+ ...buildIrModels(roleName, handlerName + "Payload", handlerSpec.payload)
208
+ );
203
209
  }
204
210
  }
205
211
  ir.networks.push(irNetwork);
@@ -215,6 +221,14 @@ function buildIr(ctx) {
215
221
  var planIndex = {
216
222
  csharp: {
217
223
  unity: "./plans/dotnet.js"
224
+ },
225
+ javascript: {
226
+ node: "./plans/typescript.js",
227
+ browser: "./plans/typescript.js"
228
+ },
229
+ typescript: {
230
+ node: "./plans/typescript.js",
231
+ browser: "./plans/typescript.js"
218
232
  }
219
233
  };
220
234
  async function dispatchBuildPlan(ctx) {
@@ -234,6 +248,16 @@ async function dispatchBuildPlan(ctx) {
234
248
  import path from "path";
235
249
  import process2 from "process";
236
250
  import S2 from "@pocketgems/schema";
251
+
252
+ // src/utils.ts
253
+ function toCamelCase(str) {
254
+ 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) => {
255
+ const lower = word.toLowerCase();
256
+ return index === 0 ? lower : lower.charAt(0).toUpperCase() + lower.slice(1);
257
+ }).join("");
258
+ }
259
+
260
+ // src/build-request.ts
237
261
  var validateBuildRequest = S2.obj({
238
262
  specPath: S2.str,
239
263
  outputPath: S2.str,
@@ -247,18 +271,21 @@ var validateBuildRequest = S2.obj({
247
271
  javascript: S2.obj({
248
272
  environment: S2.str.enum("node", "browser"),
249
273
  frameworks: S2.arr(S2.str.enum("fastify")).optional()
274
+ }).optional(),
275
+ typescript: S2.obj({
276
+ environment: S2.str.enum("node", "browser"),
277
+ frameworks: S2.arr(S2.str.enum("fastify")).optional()
250
278
  }).optional()
251
279
  }).min(1).max(1).desc("The target platform to generate code for")
252
280
  }).compile("BuildRequestValidator");
253
281
  function buildRequest(ctx) {
254
282
  const { rawInput } = ctx;
255
283
  if (!rawInput) throw new Error("rawInput is required");
256
- console.log("Host roles:", rawInput.hostRole);
257
284
  const request = {
258
285
  specPath: path.join(process2.cwd(), rawInput.spec),
259
286
  outputPath: path.join(process2.cwd(), rawInput.out),
260
287
  project: rawInput.project,
261
- hostRoles: rawInput.hostRole,
288
+ hostRoles: rawInput.hostRole.map((r) => toCamelCase(r)),
262
289
  target: {
263
290
  [rawInput.language]: {
264
291
  environment: rawInput.environment,
@@ -318,6 +345,27 @@ function loadSpec(ctx) {
318
345
  if (!request) throw new Error("request is required");
319
346
  const { specPath } = request;
320
347
  const spec = JSON.parse(fs2.readFileSync(specPath, "utf8"));
348
+ spec.name = toCamelCase(spec.name);
349
+ for (const [networkName, networkSpec] of Object.entries(spec.networks)) {
350
+ for (const [roleName, roleSpec] of Object.entries(networkSpec.roles)) {
351
+ for (const [messageName, messageSpec] of Object.entries(roleSpec.messages)) {
352
+ delete roleSpec.messages[messageName];
353
+ roleSpec.messages[toCamelCase(messageName)] = {
354
+ ...messageSpec
355
+ };
356
+ }
357
+ delete spec.networks[networkName];
358
+ networkSpec.roles[toCamelCase(roleName)] = {
359
+ ...roleSpec,
360
+ name: toCamelCase(roleName)
361
+ };
362
+ }
363
+ delete spec.networks[networkName];
364
+ spec.networks[toCamelCase(networkName)] = {
365
+ ...networkSpec,
366
+ name: toCamelCase(networkName)
367
+ };
368
+ }
321
369
  return {
322
370
  ...ctx,
323
371
  spec
@@ -348,7 +396,7 @@ function parseInput(ctx) {
348
396
  }).option("language", {
349
397
  type: "string",
350
398
  description: "The language to generate code for",
351
- choices: ["csharp", "javascript"],
399
+ choices: ["csharp", "javascript", "typescript"],
352
400
  default: "csharp"
353
401
  }).option("environment", {
354
402
  type: "string",
@@ -34,7 +34,7 @@ __export(dotnet_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(dotnet_exports);
36
36
 
37
- // ../../node_modules/.pnpm/tsup@8.5.1_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
37
+ // ../../node_modules/.pnpm/tsup@8.5.1_tsx@4.21.0_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/cjs_shims.js
38
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
39
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
40
40
 
@@ -132,12 +132,12 @@ function createPlan(ctx) {
132
132
  }
133
133
  }
134
134
  for (const handlerIr of networkIr.handlers) {
135
- handlerIr.modelClassName = pascalCase(handlerIr.handlerName);
135
+ handlerIr.modelClassName = pascalCase(handlerIr.handlerName) + "Payload";
136
136
  handlerIr.messageName = handlerIr.handlerName;
137
137
  handlerIr.methodName = pascalCase(handlerIr.handlerName);
138
138
  }
139
139
  for (const messageIr of networkIr.messages) {
140
- messageIr.modelClassName = pascalCase(messageIr.handlerName);
140
+ messageIr.modelClassName = pascalCase(messageIr.handlerName) + "Payload";
141
141
  messageIr.messageName = messageIr.handlerName;
142
142
  messageIr.methodName = pascalCase(messageIr.handlerName);
143
143
  }
@@ -1,146 +1,5 @@
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
- }
1
+ import { P as PipelineContext } from '../types-BdZPs123.cjs';
2
+ import '@polytric/openws-spec/types';
144
3
 
145
4
  declare function createPlan(ctx: PipelineContext): PipelineContext;
146
5
 
@@ -1,146 +1,5 @@
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
- }
1
+ import { P as PipelineContext } from '../types-BdZPs123.js';
2
+ import '@polytric/openws-spec/types';
144
3
 
145
4
  declare function createPlan(ctx: PipelineContext): PipelineContext;
146
5
 
@@ -92,12 +92,12 @@ function createPlan(ctx) {
92
92
  }
93
93
  }
94
94
  for (const handlerIr of networkIr.handlers) {
95
- handlerIr.modelClassName = pascalCase(handlerIr.handlerName);
95
+ handlerIr.modelClassName = pascalCase(handlerIr.handlerName) + "Payload";
96
96
  handlerIr.messageName = handlerIr.handlerName;
97
97
  handlerIr.methodName = pascalCase(handlerIr.handlerName);
98
98
  }
99
99
  for (const messageIr of networkIr.messages) {
100
- messageIr.modelClassName = pascalCase(messageIr.handlerName);
100
+ messageIr.modelClassName = pascalCase(messageIr.handlerName) + "Payload";
101
101
  messageIr.messageName = messageIr.handlerName;
102
102
  messageIr.methodName = pascalCase(messageIr.handlerName);
103
103
  }