@open-wa/schema 5.0.0-alpha.0 → 5.0.0-alpha.3

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 (102) hide show
  1. package/dist/generated/index.cjs +598 -0
  2. package/dist/generated/index.cjs.map +1 -0
  3. package/dist/generated/index.d.cts +3674 -0
  4. package/dist/generated/index.d.cts.map +1 -0
  5. package/dist/generated/index.d.mts +3674 -0
  6. package/dist/generated/index.d.mts.map +1 -0
  7. package/dist/generated/index.mjs +595 -0
  8. package/dist/generated/index.mjs.map +1 -0
  9. package/dist/http-manifest-BlJWPKsp.d.mts +177 -0
  10. package/dist/http-manifest-BlJWPKsp.d.mts.map +1 -0
  11. package/dist/http-manifest-DCOVY9QZ.d.cts +177 -0
  12. package/dist/http-manifest-DCOVY9QZ.d.cts.map +1 -0
  13. package/dist/http-manifest.cjs +59 -0
  14. package/dist/http-manifest.cjs.map +1 -0
  15. package/dist/http-manifest.d.cts +2 -0
  16. package/dist/http-manifest.d.mts +2 -0
  17. package/dist/http-manifest.mjs +58 -0
  18. package/dist/http-manifest.mjs.map +1 -0
  19. package/dist/implementor-DIBNbQXA.d.cts +8 -0
  20. package/dist/implementor-DIBNbQXA.d.cts.map +1 -0
  21. package/dist/implementor-DoN9ga7C.d.mts +8 -0
  22. package/dist/implementor-DoN9ga7C.d.mts.map +1 -0
  23. package/dist/implementor.cjs +50 -0
  24. package/dist/implementor.cjs.map +1 -0
  25. package/dist/implementor.d.cts +2 -0
  26. package/dist/implementor.d.mts +2 -0
  27. package/dist/implementor.mjs +48 -0
  28. package/dist/implementor.mjs.map +1 -0
  29. package/dist/index-BB9uyLe8.d.cts +1323 -0
  30. package/dist/index-BB9uyLe8.d.cts.map +1 -0
  31. package/dist/index-D77q1gPk.d.mts +1323 -0
  32. package/dist/index-D77q1gPk.d.mts.map +1 -0
  33. package/dist/index.cjs +649 -0
  34. package/dist/index.cjs.map +1 -0
  35. package/dist/index.d.cts +4 -0
  36. package/dist/index.d.mts +4 -0
  37. package/dist/index.mjs +299 -0
  38. package/dist/index.mjs.map +1 -0
  39. package/dist/methods/index.cjs +125 -0
  40. package/dist/methods/index.d.cts +2 -0
  41. package/dist/methods/index.d.mts +2 -0
  42. package/dist/methods/index.mjs +2 -0
  43. package/dist/methods-BXZrkKjP.mjs +2633 -0
  44. package/dist/methods-BXZrkKjP.mjs.map +1 -0
  45. package/dist/methods-CuiwUO7-.cjs +3802 -0
  46. package/dist/methods-CuiwUO7-.cjs.map +1 -0
  47. package/dist/registry-CsyR8i6y.mjs +284 -0
  48. package/dist/registry-CsyR8i6y.mjs.map +1 -0
  49. package/dist/registry-TbMVoiw5.cjs +355 -0
  50. package/dist/registry-TbMVoiw5.cjs.map +1 -0
  51. package/package.json +6 -3
  52. package/CHANGELOG.md +0 -23
  53. package/client_migration_doc.md +0 -467
  54. package/codecs_and_params_plan.md +0 -936
  55. package/migration_plan_doc.md +0 -223
  56. package/scripts/gen-client-implementation.ts +0 -129
  57. package/scripts/gen-client-reference-docs.ts +0 -621
  58. package/scripts/gen-openapi.ts +0 -96
  59. package/scripts/gen-types.ts +0 -43
  60. package/scripts/verify-v5-pipeline.ts +0 -85
  61. package/src/__tests__/generators.contract.test.ts +0 -181
  62. package/src/__tests__/registry.contract.test.ts +0 -81
  63. package/src/client-config.ts +0 -30
  64. package/src/codecs.test.ts +0 -41
  65. package/src/codecs.ts +0 -191
  66. package/src/common-types.ts +0 -280
  67. package/src/config.ts +0 -47
  68. package/src/enums.ts +0 -63
  69. package/src/events/groups.ts +0 -33
  70. package/src/events/index.ts +0 -4
  71. package/src/events/messaging.ts +0 -72
  72. package/src/events/registry.ts +0 -114
  73. package/src/events/state.ts +0 -59
  74. package/src/generated/AliasMap.ts +0 -214
  75. package/src/generated/BaseClient.ts +0 -868
  76. package/src/generated/BaseNamespacedClient.ts +0 -212
  77. package/src/generated/index.ts +0 -5
  78. package/src/generated/openapi.json +0 -7799
  79. package/src/generated/types.ts +0 -377
  80. package/src/http-manifest.ts +0 -97
  81. package/src/implementor.test.ts +0 -88
  82. package/src/implementor.ts +0 -75
  83. package/src/index.ts +0 -43
  84. package/src/methods/business.ts +0 -51
  85. package/src/methods/chats.ts +0 -263
  86. package/src/methods/communities.ts +0 -119
  87. package/src/methods/contacts.ts +0 -158
  88. package/src/methods/groups.ts +0 -376
  89. package/src/methods/index.ts +0 -33
  90. package/src/methods/labels.ts +0 -86
  91. package/src/methods/media.ts +0 -36
  92. package/src/methods/messaging.ts +0 -828
  93. package/src/methods/session.ts +0 -261
  94. package/src/methods/status.ts +0 -120
  95. package/src/open-wa-utils.d.ts +0 -4
  96. package/src/parameters.ts +0 -237
  97. package/src/registry.test.ts +0 -30
  98. package/src/registry.ts +0 -601
  99. package/tsconfig.generated.json +0 -11
  100. package/tsconfig.json +0 -15
  101. package/tsdown.config.ts +0 -16
  102. package/vitest.config.ts +0 -10
@@ -1,621 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { fileURLToPath } from 'node:url';
4
- import { z } from 'zod';
5
- import { getHttpMethodDefinitions, type HttpMethodDefinition } from '../src/http-manifest';
6
- import { clientRegistry, getParameterMetadata, type MethodDefinition, type ParameterMetadata } from '../src/registry';
7
-
8
- import '../src/methods';
9
-
10
- type JsonSchema = {
11
- type?: string | string[];
12
- description?: string;
13
- properties?: Record<string, JsonSchema>;
14
- required?: string[];
15
- items?: JsonSchema;
16
- anyOf?: JsonSchema[];
17
- oneOf?: JsonSchema[];
18
- allOf?: JsonSchema[];
19
- enum?: Array<string | number | boolean | null>;
20
- const?: string | number | boolean | null;
21
- format?: string;
22
- pattern?: string;
23
- minLength?: number;
24
- maxLength?: number;
25
- minimum?: number;
26
- maximum?: number;
27
- additionalProperties?: boolean | JsonSchema;
28
- };
29
-
30
- type ParameterRow = {
31
- name: string;
32
- type: string;
33
- required: boolean;
34
- description: string;
35
- aliases: string[];
36
- deprecatedAliases: string[];
37
- example: string;
38
- };
39
-
40
- const generatorPath = 'packages/schema/scripts/gen-client-reference-docs.ts';
41
- const docsDir = path.resolve(fileURLToPath(new URL('.', import.meta.url)), '../../../apps/docs/content/docs/reference/client');
42
-
43
- function sortStrings(values: string[]): string[] {
44
- return [...values].sort((left, right) => left.localeCompare(right));
45
- }
46
-
47
- function uniqueStrings(values: Array<string | undefined>): string[] {
48
- return Array.from(new Set(values.filter((value): value is string => Boolean(value))));
49
- }
50
-
51
- function schemaToJsonSchema(schema: z.ZodTypeAny): JsonSchema {
52
- const serializableSchema = schema as z.ZodTypeAny & {
53
- toJSONSchema?: (params?: { target?: string }) => unknown;
54
- };
55
-
56
- if (typeof serializableSchema.toJSONSchema !== 'function') {
57
- return {};
58
- }
59
-
60
- return serializableSchema.toJSONSchema({ target: 'openapi-3.0' }) as JsonSchema;
61
- }
62
-
63
- function getInputShape(def: MethodDefinition): Record<string, z.ZodTypeAny> {
64
- return def.meta.inputSchema.shape as Record<string, z.ZodTypeAny>;
65
- }
66
-
67
- function stringifyExample(value: ParameterMetadata['example'] | undefined): string {
68
- if (value === undefined) {
69
- return '-';
70
- }
71
-
72
- return `\`${escapeMarkdownInline(JSON.stringify(value))}\``;
73
- }
74
-
75
- function escapeMarkdownInline(value: string): string {
76
- return value.replace(/`/g, '\\`').replace(/\|/g, '\\|').replace(/{/g, '&#123;').replace(/}/g, '&#125;');
77
- }
78
-
79
- function escapeTableCell(value: string): string {
80
- return escapeMarkdownInline(value.replace(/\n/g, ' '));
81
- }
82
-
83
- function escapeMdxText(value: string): string {
84
- return value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
85
- }
86
-
87
- function formatList(values: string[]): string {
88
- return values.length > 0 ? values.map((value) => `\`${escapeMarkdownInline(value)}\``).join(', ') : '-';
89
- }
90
-
91
- function titleCase(value: string): string {
92
- return value
93
- .split(/[-_\s]+/)
94
- .filter(Boolean)
95
- .map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`)
96
- .join(' ');
97
- }
98
-
99
- function pascalCase(value: string): string {
100
- if (!value) return '';
101
- return value.charAt(0).toUpperCase() + value.slice(1);
102
- }
103
-
104
- function buildAllParamsInterfaces(methods: MethodDefinition[]): string {
105
- const interfaces = methods.map((def) => {
106
- const rows = buildParameterRows(def);
107
- if (rows.length === 0) {
108
- return '';
109
- }
110
-
111
- const interfaceName = pascalCase(def.meta.functionName) + 'Params';
112
- const fields = rows.map((row) => {
113
- const docParts = [];
114
- if (row.description) {
115
- docParts.push(row.description.replace(/\*\//g, '*\\/'));
116
- }
117
- if (row.example && row.example !== '-') {
118
- const exampleCleaned = row.example.replace(/^`|`$/g, '').replace(/\\/g, '');
119
- docParts.push(`@example ${exampleCleaned.replace(/\*\//g, '*\\/')}`);
120
- }
121
- if (row.aliases.length > 0) {
122
- docParts.push(`@remarks Key aliases: ${row.aliases.map((a) => `'${a}'`).join(', ')}`);
123
- }
124
- if (row.deprecatedAliases.length > 0) {
125
- docParts.push(`@remarks Deprecated key aliases: ${row.deprecatedAliases.map((a) => `'${a}'`).join(', ')}`);
126
- }
127
-
128
- const docComment = docParts.length > 0
129
- ? ` /**\n * ${docParts.map((part) => part.split('\n').join('\n * ')).join('\n * ')}\n */\n`
130
- : '';
131
-
132
- const name = row.name;
133
- const optionalSign = row.required ? '' : '?';
134
- const tsType = cleanTsType(row.type);
135
-
136
- return `${docComment} ${name}${optionalSign}: ${tsType};`;
137
- });
138
-
139
- return [
140
- `export interface ${interfaceName} {`,
141
- ...fields,
142
- `}`
143
- ].join('\n');
144
- }).filter(Boolean);
145
-
146
- return [
147
- '// This file is auto-generated by packages/schema/scripts/gen-client-reference-docs.ts',
148
- '// Do not edit this file directly.',
149
- '',
150
- ...interfaces
151
- ].join('\n\n') + '\n';
152
- }
153
-
154
- function summarizeSchema(schema: JsonSchema): string {
155
- if (schema.const !== undefined) {
156
- return JSON.stringify(schema.const);
157
- }
158
-
159
- if (schema.enum && schema.enum.length > 0) {
160
- return schema.enum.map((value) => JSON.stringify(value)).join(' | ');
161
- }
162
-
163
- const compound = schema.anyOf ?? schema.oneOf;
164
- if (compound && compound.length > 0) {
165
- return uniqueStrings(compound.map(summarizeSchema)).join(' | ');
166
- }
167
-
168
- if (schema.allOf && schema.allOf.length > 0) {
169
- return uniqueStrings(schema.allOf.map(summarizeSchema)).join(' & ');
170
- }
171
-
172
- if (Array.isArray(schema.type)) {
173
- return schema.type.join(' | ');
174
- }
175
-
176
- if (schema.type === 'array') {
177
- return `${schema.items ? summarizeSchema(schema.items) : 'unknown'}[]`;
178
- }
179
-
180
- if (schema.type === 'object') {
181
- const propertyNames = schema.properties ? Object.keys(schema.properties) : [];
182
- if (propertyNames.length === 0) {
183
- return 'object';
184
- }
185
-
186
- return `object { ${sortStrings(propertyNames).join(', ')} }`;
187
- }
188
-
189
- return schema.type ?? 'unknown';
190
- }
191
-
192
- function buildParameterRows(def: MethodDefinition): ParameterRow[] {
193
- const inputSchema = schemaToJsonSchema(def.meta.inputSchema);
194
- const properties = inputSchema.properties ?? {};
195
- const required = new Set(inputSchema.required ?? []);
196
- const inputShape = getInputShape(def);
197
- const orderedNames = uniqueStrings([
198
- ...def.meta.parameterOrder,
199
- ...sortStrings(Object.keys(properties).filter((name) => !def.meta.parameterOrder.includes(name))),
200
- ]);
201
-
202
- return orderedNames.map((name) => {
203
- const property = properties[name] ?? {};
204
- const metadata = inputShape[name] ? getParameterMetadata(inputShape[name]) : undefined;
205
- const descriptionParts = uniqueStrings([
206
- property.description,
207
- metadata?.formatDescription,
208
- metadata?.brandedType ? `Branded type: ${metadata.brandedType}` : undefined,
209
- metadata?.pattern ? `Pattern: ${metadata.pattern}` : property.pattern ? `Pattern: ${property.pattern}` : undefined,
210
- ]);
211
-
212
- return {
213
- name,
214
- type: summarizeSchema(property),
215
- required: required.has(name),
216
- description: descriptionParts.join(' '),
217
- aliases: sortStrings(metadata?.keyAliases ?? []),
218
- deprecatedAliases: sortStrings(metadata?.deprecatedKeyAliases ?? []),
219
- example: stringifyExample(metadata?.example),
220
- };
221
- });
222
- }
223
- function cleanTsType(typeStr: string): string {
224
- let cleaned = typeStr.trim();
225
- if (cleaned === 'unknown' || !cleaned) {
226
- return 'any';
227
- }
228
- if (cleaned.startsWith('object {')) {
229
- const inner = cleaned.substring('object {'.length, cleaned.length - 1).trim();
230
- if (inner) {
231
- const parts = inner.split(',').map((p) => p.trim());
232
- return `{ ${parts.map((p) => `${p}: any;`).join(' ')} }`;
233
- }
234
- return 'Record<string, any>';
235
- }
236
- if (cleaned === 'object') {
237
- return 'Record<string, any>';
238
- }
239
- return cleaned;
240
- }
241
-
242
- function buildParameterTable(def: MethodDefinition, rows: ParameterRow[]): string {
243
- if (rows.length === 0) {
244
- return 'This method does not define input parameters.';
245
- }
246
-
247
- const interfaceName = pascalCase(def.meta.functionName) + 'Params';
248
- return `<AutoTypeTable path="./generated-method-params.ts" name="${interfaceName}" />`;
249
- }
250
-
251
- function buildGeneratedWarning(): string {
252
- return `> Generated file warning: this page is generated by \`${generatorPath}\`. Do not edit generated method content by hand.`;
253
- }
254
-
255
- function buildFrontmatter(title: string, description: string, icon?: string): string {
256
- const lines = [
257
- '---',
258
- `title: ${JSON.stringify(title)}`,
259
- `description: ${JSON.stringify(description)}`,
260
- ];
261
-
262
- if (icon) {
263
- lines.push(`icon: ${JSON.stringify(icon)}`);
264
- }
265
-
266
- lines.push('---');
267
- return lines.join('\n');
268
- }
269
-
270
- function buildRouteBlock(route: HttpMethodDefinition | undefined): string {
271
- if (!route) {
272
- return [
273
- '### Routes',
274
- '',
275
- '| Type | Method | Path | Name | Status |',
276
- '| --- | --- | --- | --- | --- |',
277
- '| Primary | - | - | - | Not registered |',
278
- ].join('\n');
279
- }
280
-
281
- const aliasRows = route.aliasRoutes
282
- .filter((aliasRoute) => aliasRoute.path !== route.path)
283
- .sort((left, right) => left.name.localeCompare(right.name))
284
- .map((aliasRoute) => [
285
- aliasRoute.deprecated ? 'Deprecated alias' : 'Alias',
286
- `\`${escapeTableCell(route.httpMethod)}\``,
287
- `\`${escapeTableCell(aliasRoute.path)}\``,
288
- `\`${escapeTableCell(aliasRoute.name)}\``,
289
- aliasRoute.deprecated ? '**Deprecated**' : 'Active',
290
- ]);
291
-
292
- const rows = [
293
- ['Primary', `\`${escapeTableCell(route.httpMethod)}\``, `\`${escapeTableCell(route.path)}\``, `\`${escapeTableCell(route.functionName)}\``, 'Active'],
294
- ...aliasRows,
295
- ];
296
-
297
- return [
298
- '### Routes',
299
- '',
300
- '| Type | Method | Path | Name | Status |',
301
- '| --- | --- | --- | --- | --- |',
302
- ...rows.map((row) => `| ${row.join(' | ')} |`),
303
- ].join('\n');
304
- }
305
-
306
- function buildOverviewBlock(def: MethodDefinition): string {
307
- const meta = def.meta;
308
- const rows = [
309
- ['Namespace', `\`${escapeTableCell(meta.namespace ?? 'core')}\``],
310
- ['Action', meta.action ? `\`${escapeTableCell(meta.action)}\`` : '-'],
311
- ['Functionality', meta.functionality ? `\`${escapeTableCell(meta.functionality)}\`` : '-'],
312
- ['Positional parameter order', formatList(meta.parameterOrder)],
313
- ['Aliases', formatList(sortStrings(meta.allAliases ?? []))],
314
- ['Deprecated aliases', formatList(sortStrings(meta.deprecatedAliases ?? []))],
315
- ['License', meta.license ? `\`${escapeTableCell(meta.license)}\`` : '`none`'],
316
- ['WAPI override', meta.wapiOverride ? `\`${escapeTableCell(meta.wapiOverride)}\`` : '-'],
317
- ['Deprecated', meta.deprecated ? '**Yes**' : 'No'],
318
- ];
319
-
320
- return [
321
- '### Overview',
322
- '',
323
- '| Prop | Value |',
324
- '| --- | --- |',
325
- ...rows.map(([prop, value]) => `| ${prop} | ${value} |`),
326
- ].join('\n');
327
- }
328
-
329
- function buildLicenseCallout(def: MethodDefinition): string {
330
- const license = def.meta.license;
331
- if (!license || license === 'none') {
332
- return '';
333
- }
334
-
335
- return `<LicensedFeatureCallout tier="${license}" />`;
336
- }
337
-
338
- function buildOutputBlock(outputSummary: string): string {
339
- return [
340
- '| Prop | Value |',
341
- '| --- | --- |',
342
- `| Return type | \`${escapeTableCell(outputSummary)}\` |`,
343
- ].join('\n');
344
- }
345
-
346
- function decodeMarkdownInline(value: string): string {
347
- return value.replace(/^`|`$/g, '').replace(/\\`/g, '`').replace(/\\\|/g, '|').replace(/&#123;/g, '{').replace(/&#125;/g, '}');
348
- }
349
-
350
- function sampleValueForParameter(row: ParameterRow): string {
351
- if (row.example !== '-') {
352
- return decodeMarkdownInline(row.example);
353
- }
354
-
355
- if (row.type.endsWith('[]')) {
356
- return '[]';
357
- }
358
-
359
- if (row.type.includes('number')) {
360
- return '1';
361
- }
362
-
363
- if (row.type.includes('boolean')) {
364
- return 'true';
365
- }
366
-
367
- if (row.type.startsWith('object') || row.type === 'unknown') {
368
- return '{}';
369
- }
370
-
371
- return JSON.stringify(row.name);
372
- }
373
-
374
- function buildParameterObject(rows: ParameterRow[], indent: string): string {
375
- if (rows.length === 0) {
376
- return '{}';
377
- }
378
-
379
- return [
380
- '{',
381
- ...rows.map((row) => `${indent}${row.name}: ${sampleValueForParameter(row)},`),
382
- '}',
383
- ].join('\n');
384
- }
385
-
386
- function buildJsonBody(rows: ParameterRow[], indent: string): string {
387
- if (rows.length === 0) {
388
- return '{}';
389
- }
390
-
391
- const entries = rows.map((row) => {
392
- const sample = sampleValueForParameter(row);
393
- try {
394
- return [row.name, JSON.parse(sample)] as const;
395
- } catch {
396
- return [row.name, sample] as const;
397
- }
398
- });
399
-
400
- return JSON.stringify(Object.fromEntries(entries), null, 2).split('\n').map((line, index) => index === 0 ? line : `${indent}${line}`).join('\n');
401
- }
402
-
403
- function buildCurlExample(route: HttpMethodDefinition | undefined, rows: ParameterRow[]): string {
404
- if (!route) {
405
- return '# HTTP route is not registered for this method yet.';
406
- }
407
-
408
- const url = `http://localhost:8080${route.path}`;
409
- if (route.httpMethod === 'GET' && rows.length > 0) {
410
- return [
411
- `curl -G ${JSON.stringify(url)} \\`,
412
- ' -H "x-api-key: YOUR_API_KEY" \\',
413
- ...rows.map((row, index) => {
414
- const suffix = index === rows.length - 1 ? '' : ' \\';
415
- return ` --data-urlencode ${JSON.stringify(`${row.name}=${sampleValueForParameter(row).replace(/^"|"$/g, '')}`)}${suffix}`;
416
- }),
417
- ].join('\n');
418
- }
419
-
420
- return [
421
- `curl -X ${route.httpMethod} ${JSON.stringify(url)} \\`,
422
- ' -H "content-type: application/json" \\',
423
- ' -H "x-api-key: YOUR_API_KEY" \\',
424
- ` --data '${buildJsonBody(rows, ' ')}'`,
425
- ].join('\n');
426
- }
427
-
428
- function buildUsageTabs(def: MethodDefinition, route: HttpMethodDefinition | undefined, rows: ParameterRow[]): string {
429
- const namespace = def.meta.namespace ?? 'core';
430
- const namespacedName = def.meta.namespacedName ?? def.meta.functionName;
431
- const parameterObject = buildParameterObject(rows, ' ');
432
-
433
- return [
434
- '### Usage',
435
- '',
436
- '<Tabs items={["Client", "Namespaced client", "HTTP API"]}>',
437
- ' <Tab value="Client">',
438
- '',
439
- '```ts',
440
- `const result = await client.${def.meta.functionName}(${parameterObject});`,
441
- '```',
442
- '',
443
- ' </Tab>',
444
- ' <Tab value="Namespaced client">',
445
- '',
446
- '```ts',
447
- `const result = await client.${namespace}.${namespacedName}(${parameterObject});`,
448
- '```',
449
- '',
450
- ' </Tab>',
451
- ' <Tab value="HTTP API">',
452
- '',
453
- '```bash',
454
- buildCurlExample(route, rows),
455
- '```',
456
- '',
457
- ' </Tab>',
458
- '</Tabs>',
459
- ].join('\n');
460
- }
461
-
462
- function buildMethodSection(def: MethodDefinition, route: HttpMethodDefinition | undefined): string {
463
- const outputSummary = summarizeSchema(schemaToJsonSchema(def.meta.outputSchema));
464
- const parameters = buildParameterRows(def);
465
- const licenseSuffix = (def.meta.license && def.meta.license !== 'none') ? ` - ${def.meta.license}` : '';
466
- const licenseCallout = buildLicenseCallout(def);
467
-
468
- const parts = [
469
- `## \`${def.meta.functionName}\`${licenseSuffix}`,
470
- '',
471
- def.meta.description ?? `Client method ${def.meta.functionName}.`,
472
- '',
473
- licenseCallout,
474
- '',
475
- buildOverviewBlock(def),
476
- '',
477
- buildRouteBlock(route),
478
- '',
479
- buildUsageTabs(def, route, parameters),
480
- '',
481
- '### Parameters',
482
- '',
483
- buildParameterTable(def, parameters),
484
- '',
485
- '### Output',
486
- '',
487
- buildOutputBlock(outputSummary),
488
- ];
489
-
490
- return parts.filter((part, index) => part !== '' || parts[index - 1] !== '').join('\n');
491
- }
492
-
493
- function slugForNamespace(namespace: string): string {
494
- return namespace.replace(/[^a-z0-9-]/gi, '-').toLowerCase();
495
- }
496
-
497
- function writeFileIfChanged(filePath: string, content: string): void {
498
- if (fs.existsSync(filePath) && fs.readFileSync(filePath, 'utf-8') === content) {
499
- return;
500
- }
501
-
502
- fs.writeFileSync(filePath, content);
503
- }
504
-
505
- function cleanGeneratedDocs(): void {
506
- if (!fs.existsSync(docsDir)) {
507
- fs.mkdirSync(docsDir, { recursive: true });
508
- return;
509
- }
510
-
511
- for (const entry of fs.readdirSync(docsDir)) {
512
- if (entry.endsWith('.mdx') || entry === 'meta.json' || entry === 'methods-map.json' || entry === 'generated-method-params.ts') {
513
- fs.rmSync(path.join(docsDir, entry));
514
- }
515
- }
516
- }
517
-
518
- const methods = clientRegistry
519
- .getAll()
520
- .slice()
521
- .sort((left, right) => left.meta.functionName.localeCompare(right.meta.functionName));
522
- const routesByFunctionName = new Map(
523
- getHttpMethodDefinitions('/api')
524
- .slice()
525
- .sort((left, right) => left.functionName.localeCompare(right.functionName))
526
- .map((route) => [route.functionName, route])
527
- );
528
- const methodsByNamespace = new Map<string, MethodDefinition[]>();
529
-
530
- for (const def of methods) {
531
- const namespace = def.meta.namespace ?? 'core';
532
- const namespaceMethods = methodsByNamespace.get(namespace) ?? [];
533
- namespaceMethods.push(def);
534
- methodsByNamespace.set(namespace, namespaceMethods);
535
- }
536
-
537
- cleanGeneratedDocs();
538
-
539
- const namespaces = sortStrings(Array.from(methodsByNamespace.keys()));
540
- const meta = {
541
- title: 'Client API',
542
- icon: 'BookOpen',
543
- pages: ['index', 'client', ...namespaces.map(slugForNamespace)],
544
- };
545
-
546
- const indexContent = [
547
- buildFrontmatter('Client API Reference', 'Generated reference for schema-registry client methods.', 'BookOpen'),
548
- '',
549
- '# Client API Reference',
550
- '',
551
- buildGeneratedWarning(),
552
- '',
553
- 'These pages are generated from `packages/schema/src/registry.ts` and `packages/schema/src/methods/*.ts`.',
554
- '',
555
- '## Namespaces',
556
- '',
557
- '<Cards>',
558
- '',
559
- ...namespaces.map((namespace) => {
560
- const namespaceMethods = methodsByNamespace.get(namespace) ?? [];
561
- const slug = slugForNamespace(namespace);
562
- return [
563
- ` <Card title="${escapeMdxText(titleCase(namespace))}" href="./${slug}">`,
564
- ` ${namespaceMethods.length} client methods`,
565
- ' </Card>',
566
- '',
567
- ].join('\n');
568
- }),
569
- '</Cards>',
570
- ].join('\n');
571
-
572
- writeFileIfChanged(path.join(docsDir, 'index.mdx'), `${indexContent}\n`);
573
- writeFileIfChanged(path.join(docsDir, 'meta.json'), `${JSON.stringify(meta, null, 2)}\n`);
574
-
575
- const clientContent = [
576
- buildFrontmatter('Client Reference', 'Comprehensive flat client method reference.', 'BookOpen'),
577
- '',
578
- '# Client Reference',
579
- '',
580
- buildGeneratedWarning(),
581
- '',
582
- 'This page documents all client methods alphabetically in a single flat namespace for easy reference.',
583
- '',
584
- methods.map((def) => buildMethodSection(def, routesByFunctionName.get(def.meta.functionName))).join('\n\n'),
585
- ].join('\n');
586
-
587
- writeFileIfChanged(path.join(docsDir, 'client.mdx'), `${clientContent}\n`);
588
-
589
- for (const namespace of namespaces) {
590
- const namespaceMethods = methodsByNamespace.get(namespace) ?? [];
591
- const pageContent = [
592
- buildFrontmatter(
593
- `${titleCase(namespace)} Client API`,
594
- `Generated client method reference for the ${namespace} namespace.`,
595
- 'BookOpen'
596
- ),
597
- '',
598
- `# ${titleCase(namespace)} Client API`,
599
- '',
600
- buildGeneratedWarning(),
601
- '',
602
- `This page documents ${namespaceMethods.length} schema-registry client methods in the \`${namespace}\` namespace.`,
603
- '',
604
- namespaceMethods.map((def) => buildMethodSection(def, routesByFunctionName.get(def.meta.functionName))).join('\n\n'),
605
- ].join('\n');
606
-
607
- writeFileIfChanged(path.join(docsDir, `${slugForNamespace(namespace)}.mdx`), `${pageContent}\n`);
608
- }
609
-
610
- const methodsMap: Record<string, string> = {};
611
- for (const def of methods) {
612
- const nsSlug = slugForNamespace(def.meta.namespace ?? 'core');
613
- methodsMap[def.meta.functionName] = `/docs/reference/client/${nsSlug}#${def.meta.functionName.toLowerCase()}`;
614
- }
615
-
616
- writeFileIfChanged(path.join(docsDir, 'methods-map.json'), `${JSON.stringify(methodsMap, null, 2)}\n`);
617
-
618
- const interfacesContent = buildAllParamsInterfaces(methods);
619
- writeFileIfChanged(path.join(docsDir, 'generated-method-params.ts'), interfacesContent);
620
-
621
- console.log(`Successfully generated Client API reference docs with ${methods.length} methods across ${namespaces.length} namespaces plus flat client page, methods map, and parameter interfaces`);