@workos/oagen 0.2.0 → 0.3.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.
@@ -107,15 +107,49 @@ function walkTypeRef(ref, visitor) {
107
107
  //#endregion
108
108
  //#region src/utils/naming.ts
109
109
  /**
110
+ * Known compound tokens that the regex-based splitter over-splits.
111
+ * Each entry is [lowercase-word-sequence, canonical-form].
112
+ * Sorted longest-first so greedy matching works correctly.
113
+ */
114
+ const COMPOUND_WORDS = [[[
115
+ "m",
116
+ "2",
117
+ "m"
118
+ ], "M2M"], [["o", "auth"], "OAuth"]];
119
+ /**
120
+ * Recombine adjacent words that form a known compound token.
121
+ */
122
+ function recombineCompounds(words) {
123
+ const result = [];
124
+ let i = 0;
125
+ while (i < words.length) {
126
+ let matched = false;
127
+ for (const [pattern, canonical] of COMPOUND_WORDS) if (i + pattern.length <= words.length) {
128
+ if (pattern.every((p, j) => words[i + j].toLowerCase() === p)) {
129
+ result.push(canonical);
130
+ i += pattern.length;
131
+ matched = true;
132
+ break;
133
+ }
134
+ }
135
+ if (!matched) {
136
+ result.push(words[i]);
137
+ i++;
138
+ }
139
+ }
140
+ return result;
141
+ }
142
+ /**
110
143
  * Split a string into words, handling:
111
144
  * - camelCase / PascalCase boundaries
112
145
  * - snake_case / kebab-case separators
113
146
  * - Consecutive capitals (e.g., "HTTPClient" → ["HTTP", "Client"])
114
147
  * - Numbers as word boundaries (e.g., "OAuth2Token" → ["OAuth", "2", "Token"])
148
+ * - Known compounds are recombined (e.g., "M2M" stays as one word)
115
149
  */
116
150
  function splitWords(s) {
117
151
  if (!s) return [];
118
- return s.replace(/[^a-zA-Z0-9_\-\s.]/g, "_").replace(/([a-z])([A-Z])/g, "$1\0$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1\0$2").replace(/([a-zA-Z])(\d)/g, "$1\0$2").replace(/(\d)([a-zA-Z])/g, "$1\0$2").split(/[\0_\-\s.]+/).filter((w) => w.length > 0);
152
+ return recombineCompounds(s.replace(/[^a-zA-Z0-9_\-\s.]/g, "_").replace(/([a-z])([A-Z])/g, "$1\0$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1\0$2").replace(/([a-zA-Z])(\d)/g, "$1\0$2").replace(/(\d)([a-zA-Z])/g, "$1\0$2").split(/[\0_\-\s.]+/).filter((w) => w.length > 0));
119
153
  }
120
154
  const ACRONYM_SET = new Set([
121
155
  "SSO",
@@ -123,7 +157,8 @@ const ACRONYM_SET = new Set([
123
157
  "SAML",
124
158
  "SCIM",
125
159
  "JWT",
126
- "HMAC"
160
+ "HMAC",
161
+ "M2M"
127
162
  ]);
128
163
  function toPascalCase(s, acronyms) {
129
164
  const merged = acronyms ? new Set([...ACRONYM_SET, ...acronyms]) : ACRONYM_SET;