@kubb/core 2.8.2 → 2.9.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.
package/dist/utils.cjs CHANGED
@@ -10,6 +10,9 @@ var _chunkGNWOOGXAcjs = require('./chunk-GNWOOGXA.cjs');
10
10
  var _chunkAWUFUNOJcjs = require('./chunk-AWUFUNOJ.cjs');
11
11
 
12
12
 
13
+
14
+
15
+
13
16
  var _chunkDJLNT4KCcjs = require('./chunk-DJLNT4KC.cjs');
14
17
 
15
18
  // src/utils/index.ts
@@ -18,49 +21,120 @@ _chunkDJLNT4KCcjs.init_cjs_shims.call(void 0, );
18
21
  // src/utils/FunctionParams.ts
19
22
  _chunkDJLNT4KCcjs.init_cjs_shims.call(void 0, );
20
23
  var _naturalorderby = require('natural-orderby');
21
- var FunctionParams = class {
24
+ var _items, _orderItems, orderItems_fn, _addParams, addParams_fn;
25
+ var _FunctionParams = class _FunctionParams {
22
26
  constructor(type) {
23
- this.items = [];
27
+ _chunkDJLNT4KCcjs.__privateAdd.call(void 0, this, _items, []);
24
28
  this.type = type;
25
29
  return this;
26
30
  }
31
+ get items() {
32
+ return _chunkDJLNT4KCcjs.__privateGet.call(void 0, this, _items).flat();
33
+ }
27
34
  add(item) {
28
35
  if (!item) {
29
36
  return this;
30
37
  }
31
38
  if (Array.isArray(item)) {
32
- item.filter(Boolean).forEach((it) => this.items.push(it));
39
+ item.filter(Boolean).forEach((it) => _chunkDJLNT4KCcjs.__privateGet.call(void 0, this, _items).push(it));
33
40
  return this;
34
41
  }
35
- this.items.push(item);
42
+ _chunkDJLNT4KCcjs.__privateGet.call(void 0, this, _items).push(item);
36
43
  return this;
37
44
  }
38
- toString() {
39
- const sortedData = _naturalorderby.orderBy.call(void 0, this.items.filter(Boolean), [(v) => !v.default, (v) => _nullishCoalesce(v.required, () => ( true))], ["desc", "desc"]);
40
- return sortedData.filter(({ enabled = true }) => enabled).reduce((acc, { name, type, required = true, ...rest }) => {
41
- if (!name) {
42
- acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
43
- return acc;
45
+ static toObject(items) {
46
+ let type = [];
47
+ let name = [];
48
+ const enabled = items.every((item) => item.enabled) ? _optionalChain([items, 'access', _ => _.at, 'call', _2 => _2(0), 'optionalAccess', _3 => _3.enabled]) : true;
49
+ const required = _nullishCoalesce(items.every((item) => item.required), () => ( true));
50
+ items.forEach((item) => {
51
+ var _a, _b;
52
+ name = _chunkDJLNT4KCcjs.__privateMethod.call(void 0, _a = _FunctionParams, _addParams, addParams_fn).call(_a, name, { ...item, type: void 0 });
53
+ if (items.some((item2) => item2.type)) {
54
+ type = _chunkDJLNT4KCcjs.__privateMethod.call(void 0, _b = _FunctionParams, _addParams, addParams_fn).call(_b, type, item);
44
55
  }
45
- const parameterName = name.startsWith("{") ? name : _chunkAWUFUNOJcjs.camelCase.call(void 0, name);
46
- if (type) {
47
- if (required) {
48
- acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
49
- } else {
50
- acc.push(`${parameterName}?: ${type}`);
51
- }
52
- } else {
53
- acc.push(`${parameterName}`);
56
+ });
57
+ return {
58
+ name: `{ ${name.join(", ")} }`,
59
+ type: type.length ? `{ ${type.join(", ")} }` : void 0,
60
+ enabled,
61
+ required
62
+ };
63
+ }
64
+ static toString(items) {
65
+ const sortedData = _chunkDJLNT4KCcjs.__privateMethod.call(void 0, this, _orderItems, orderItems_fn).call(this, items);
66
+ return sortedData.reduce((acc, item) => {
67
+ var _a, _b;
68
+ if (Array.isArray(item)) {
69
+ const subItems = _chunkDJLNT4KCcjs.__privateMethod.call(void 0, this, _orderItems, orderItems_fn).call(this, item);
70
+ const objectItem = _FunctionParams.toObject(subItems);
71
+ return _chunkDJLNT4KCcjs.__privateMethod.call(void 0, _a = _FunctionParams, _addParams, addParams_fn).call(_a, acc, objectItem);
54
72
  }
55
- return acc;
73
+ return _chunkDJLNT4KCcjs.__privateMethod.call(void 0, _b = _FunctionParams, _addParams, addParams_fn).call(_b, acc, item);
56
74
  }, []).join(", ");
57
75
  }
76
+ toObject() {
77
+ var _a;
78
+ const items = _chunkDJLNT4KCcjs.__privateMethod.call(void 0, _a = _FunctionParams, _orderItems, orderItems_fn).call(_a, _chunkDJLNT4KCcjs.__privateGet.call(void 0, this, _items)).flat();
79
+ return _FunctionParams.toObject(items);
80
+ }
81
+ toString() {
82
+ var _a;
83
+ const items = _chunkDJLNT4KCcjs.__privateMethod.call(void 0, _a = _FunctionParams, _orderItems, orderItems_fn).call(_a, _chunkDJLNT4KCcjs.__privateGet.call(void 0, this, _items));
84
+ return _FunctionParams.toString(items);
85
+ }
86
+ };
87
+ _items = new WeakMap();
88
+ _orderItems = new WeakSet();
89
+ orderItems_fn = function(items) {
90
+ return _naturalorderby.orderBy.call(void 0, items.filter(Boolean), [
91
+ (v) => {
92
+ if (Array.isArray(v)) {
93
+ return void 0;
94
+ }
95
+ return !v.default;
96
+ },
97
+ (v) => {
98
+ if (Array.isArray(v)) {
99
+ return void 0;
100
+ }
101
+ return _nullishCoalesce(v.required, () => ( true));
102
+ }
103
+ ], [
104
+ "desc",
105
+ "desc"
106
+ ]);
107
+ };
108
+ _addParams = new WeakSet();
109
+ addParams_fn = function(acc, item) {
110
+ const { enabled = true, name, type, required = true, ...rest } = item;
111
+ if (!enabled) {
112
+ return acc;
113
+ }
114
+ if (!name) {
115
+ acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
116
+ return acc;
117
+ }
118
+ const parameterName = name.startsWith("{") ? name : _chunkAWUFUNOJcjs.camelCase.call(void 0, name);
119
+ if (type) {
120
+ if (required) {
121
+ acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
122
+ } else {
123
+ acc.push(`${parameterName}?: ${type}`);
124
+ }
125
+ } else {
126
+ acc.push(`${parameterName}`);
127
+ }
128
+ return acc;
58
129
  };
130
+ _chunkDJLNT4KCcjs.__privateAdd.call(void 0, _FunctionParams, _orderItems);
131
+ _chunkDJLNT4KCcjs.__privateAdd.call(void 0, _FunctionParams, _addParams);
132
+ var FunctionParams = _FunctionParams;
59
133
 
60
134
  // src/utils/promise.ts
61
135
  _chunkDJLNT4KCcjs.init_cjs_shims.call(void 0, );
62
136
  function isPromise(result) {
63
- return !!result && typeof _optionalChain([result, 'optionalAccess', _ => _.then]) === "function";
137
+ return !!result && typeof _optionalChain([result, 'optionalAccess', _4 => _4.then]) === "function";
64
138
  }
65
139
  function isPromiseFulfilledResult(result) {
66
140
  return result.status === "fulfilled";
@@ -76,8 +150,8 @@ function renderTemplate(template, data = void 0) {
76
150
  return template.replace(/{{(.*?)}}/g, "");
77
151
  }
78
152
  const matches = template.match(/{{(.*?)}}/g);
79
- return _optionalChain([matches, 'optionalAccess', _2 => _2.reduce, 'call', _3 => _3((prev, curr) => {
80
- const index = _optionalChain([curr, 'access', _4 => _4.split, 'call', _5 => _5(/{{|}}/), 'access', _6 => _6.filter, 'call', _7 => _7(Boolean), 'access', _8 => _8[0], 'optionalAccess', _9 => _9.trim, 'call', _10 => _10()]);
153
+ return _optionalChain([matches, 'optionalAccess', _5 => _5.reduce, 'call', _6 => _6((prev, curr) => {
154
+ const index = _optionalChain([curr, 'access', _7 => _7.split, 'call', _8 => _8(/{{|}}/), 'access', _9 => _9.filter, 'call', _10 => _10(Boolean), 'access', _11 => _11[0], 'optionalAccess', _12 => _12.trim, 'call', _13 => _13()]);
81
155
  if (index === void 0) {
82
156
  return prev;
83
157
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/index.ts","../src/utils/FunctionParams.ts","../src/utils/promise.ts","../src/utils/renderTemplate.ts","../src/utils/timeout.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;;ACAA;AAAA,SAAS,eAAe;AAiCjB,IAAM,iBAAN,MAAqB;AAAA,EAG1B,YAAY,MAA6B;AADzC,SAAO,QAA6B,CAAC;AAEnC,SAAK,OAAO;AAEZ,WAAO;AAAA,EACT;AAAA,EAEA,IAAI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,WAAW;AAC3B;AAEO,SAAS,wBAA2B,QAAwG;AACjJ,SAAO,OAAO,WAAW;AAC3B;;;ACZA;AAAO,SAAS,eAAgF,UAAkB,OAA0B,QAAmB;AAC7J,MAAI,CAAC,QAAQ,CAAC,OAAO,KAAK,IAAI,EAAE,QAAQ;AACtC,WAAO,SAAS,QAAQ,cAAc,EAAE;AAAA,EAC1C;AAEA,QAAM,UAAU,SAAS,MAAM,YAAY;AAE3C,SACE,SAAS,OAAO,CAAC,MAAM,SAAS;AAC9B,UAAM,QAAQ,KAAK,MAAM,OAAO,EAAE,OAAO,OAAO,EAAE,CAAC,GAAG,KAAK;AAC3D,QAAI,UAAU,QAAW;AACvB,aAAO;AAAA,IACT;AACA,UAAM,QAAQ,KAAK,KAAK;AAExB,QAAI,UAAU,QAAW;AACvB,aAAO;AAAA,IACT;AAEA,WAAO,KACJ,QAAQ,MAAM,MAAM;AACnB,UAAI,OAAO,UAAU,WAAW;AAC9B,eAAO,GAAG,MAAM,SAAS,CAAC,MAAM;AAAA,MAClC;AAEA,aAAQ,SAAoB;AAAA,IAC9B,CAAC,EACA,KAAK;AAAA,EACV,GAAG,QAAQ,KAAK;AAEpB;;;AC9BA;AAAA,eAAsB,QAAQ,IAA8B;AAC1D,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,eAAW,MAAM;AACf,cAAQ,IAAI;AAAA,IACd,GAAG,EAAE;AAAA,EACP,CAAC;AACH","sourcesContent":["export type { FunctionParamsAST } from './FunctionParams.ts'\nexport { FunctionParams } from './FunctionParams.ts'\nexport { isPromise, isPromiseFulfilledResult, isPromiseRejectedResult } from './promise.ts'\nexport { renderTemplate } from './renderTemplate.ts'\nexport { timeout } from './timeout.ts'\nexport { getUniqueName, setUniqueName } from './uniqueName.ts'\nexport type { URLObject } from './URLPath.ts'\nexport { URLPath } from './URLPath.ts'\n","import { orderBy } from 'natural-orderby'\n\nimport { camelCase } from '../transformers/casing.ts'\n\ntype FunctionParamsASTWithoutType = {\n name?: string\n type?: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n\ntype FunctionParamsASTWithType = {\n name?: never\n type: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n\nexport type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType\nexport class FunctionParams {\n public type?: 'generics' | 'typed'\n public items: FunctionParamsAST[] = []\n constructor(type?: 'generics' | 'typed') {\n this.type = type\n\n return this\n }\n\n add(item: FunctionParamsAST | Array<FunctionParamsAST | undefined> | undefined): FunctionParams {\n if (!item) {\n return this\n }\n\n if (Array.isArray(item)) {\n item.filter(Boolean).forEach((it) => this.items.push(it))\n return this\n }\n this.items.push(item)\n\n return this\n }\n\n toString(): string {\n const sortedData = orderBy(this.items.filter(Boolean), [(v) => !v.default, (v) => v.required ?? true], ['desc', 'desc'])\n\n return sortedData\n .filter(({ enabled = true }) => enabled)\n .reduce((acc, { name, type, required = true, ...rest }) => {\n if (!name) {\n // when name is not se we will use TypeScript generics\n acc.push(`${type}${rest.default ? ` = ${rest.default}` : ''}`)\n\n return acc\n }\n // TODO check whey we still need the camelcase here\n const parameterName = name.startsWith('{') ? name : camelCase(name)\n\n if (type) {\n if (required) {\n acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ''}`)\n } else {\n acc.push(`${parameterName}?: ${type}`)\n }\n } else {\n acc.push(`${parameterName}`)\n }\n\n return acc\n }, [] as string[])\n .join(', ')\n }\n}\n","import type { PossiblePromise } from '@kubb/types'\n\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return !!result && typeof (result as Promise<unknown>)?.then === 'function'\n}\n\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","export function renderTemplate<TData extends Record<string, unknown> = Record<string, unknown>>(template: string, data: TData | undefined = undefined): string {\n if (!data || !Object.keys(data).length) {\n return template.replace(/{{(.*?)}}/g, '')\n }\n\n const matches = template.match(/{{(.*?)}}/g)\n\n return (\n matches?.reduce((prev, curr) => {\n const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim()\n if (index === undefined) {\n return prev\n }\n const value = data[index]\n\n if (value === undefined) {\n return prev\n }\n\n return prev\n .replace(curr, () => {\n if (typeof value === 'boolean') {\n return `${value.toString()}` || 'false'\n }\n\n return (value as string) || ''\n })\n .trim()\n }, template) || ''\n )\n}\n","export async function timeout(ms: number): Promise<unknown> {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(true)\n }, ms)\n })\n}\n"]}
1
+ {"version":3,"sources":["../src/utils/index.ts","../src/utils/FunctionParams.ts","../src/utils/promise.ts","../src/utils/renderTemplate.ts","../src/utils/timeout.ts"],"names":["item"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;ACAA;AAAA,SAAS,eAAe;AAAxB;AAiCO,IAAM,kBAAN,MAAM,gBAAe;AAAA,EAG1B,YAAY,MAA6B;AADzC,+BAAyD,CAAC;AAExD,SAAK,OAAO;AAEZ,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,QAA6B;AAC/B,WAAO,mBAAK,QAAO,KAAK;AAAA,EAC1B;AAAA,EAEA,IAAI,MAAkH;AACpH,QAAI,CAAC,MAAM;AACT,aAAO;AAAA,IACT;AAEA,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,WAAK,OAAO,OAAO,EAAE,QAAQ,CAAC,OAAO,mBAAK,QAAO,KAAK,EAAE,CAAC;AACzD,aAAO;AAAA,IACT;AACA,uBAAK,QAAO,KAAK,IAAI;AAErB,WAAO;AAAA,EACT;AAAA,EAkDA,OAAO,SAAS,OAA+C;AAC7D,QAAI,OAAiB,CAAC;AACtB,QAAI,OAAiB,CAAC;A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AwG;AACjJ,SAAO,OAAO,WAAW;AAC3B;;;ACZA;AAAO,SAAS,eAAgF,UAAkB,OAA0B,QAAmB;AAC7J,MAAI,CAAC,QAAQ,CAAC,OAAO,KAAK,IAAI,EAAE,QAAQ;AACtC,WAAO,SAAS,QAAQ,cAAc,EAAE;AAAA,EAC1C;AAEA,QAAM,UAAU,SAAS,MAAM,YAAY;AAE3C,SACE,SAAS,OAAO,CAAC,MAAM,SAAS;AAC9B,UAAM,QAAQ,KAAK,MAAM,OAAO,EAAE,OAAO,OAAO,EAAE,CAAC,GAAG,KAAK;AAC3D,QAAI,UAAU,QAAW;AACvB,aAAO;AAAA,IACT;AACA,UAAM,QAAQ,KAAK,KAAK;AAExB,QAAI,UAAU,QAAW;AACvB,aAAO;AAAA,IACT;AAEA,WAAO,KACJ,QAAQ,MAAM,MAAM;AACnB,UAAI,OAAO,UAAU,WAAW;AAC9B,eAAO,GAAG,MAAM,SAAS,CAAC,MAAM;AAAA,MAClC;AAEA,aAAQ,SAAoB;AAAA,IAC9B,CAAC,EACA,KAAK;AAAA,EACV,GAAG,QAAQ,KAAK;AAEpB;;;AC9BA;AAAA,eAAsB,QAAQ,IAA8B;AAC1D,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,eAAW,MAAM;AACf,cAAQ,IAAI;AAAA,IACd,GAAG,EAAE;AAAA,EACP,CAAC;AACH","sourcesContent":["export type { FunctionParamsAST } from './FunctionParams.ts'\nexport { FunctionParams } from './FunctionParams.ts'\nexport { isPromise, isPromiseFulfilledResult, isPromiseRejectedResult } from './promise.ts'\nexport { renderTemplate } from './renderTemplate.ts'\nexport { timeout } from './timeout.ts'\nexport { getUniqueName, setUniqueName } from './uniqueName.ts'\nexport type { URLObject } from './URLPath.ts'\nexport { URLPath } from './URLPath.ts'\n","import { orderBy } from 'natural-orderby'\n\nimport { camelCase } from '../transformers/casing.ts'\n\ntype FunctionParamsASTWithoutType = {\n name?: string\n type?: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n\ntype FunctionParamsASTWithType = {\n name?: never\n type: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n\nexport type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType\nexport class FunctionParams {\n type?: 'generics' | 'typed'\n #items: Array<FunctionParamsAST | FunctionParamsAST[]> = []\n constructor(type?: 'generics' | 'typed') {\n this.type = type\n\n return this\n }\n\n get items(): FunctionParamsAST[] {\n return this.#items.flat()\n }\n\n add(item: FunctionParamsAST | Array<FunctionParamsAST | FunctionParamsAST[] | undefined> | undefined): FunctionParams {\n if (!item) {\n return this\n }\n\n if (Array.isArray(item)) {\n item.filter(Boolean).forEach((it) => this.#items.push(it))\n return this\n }\n this.#items.push(item)\n\n return this\n }\n static #orderItems(items: Array<FunctionParamsAST | FunctionParamsAST[]>) {\n return orderBy(items.filter(Boolean), [\n (v) => {\n if (Array.isArray(v)) {\n return undefined\n }\n return !v.default\n },\n (v) => {\n if (Array.isArray(v)) {\n return undefined\n }\n return v.required ?? true\n },\n ], [\n 'desc',\n 'desc',\n ])\n }\n\n static #addParams(acc: string[], item: FunctionParamsAST) {\n const { enabled = true, name, type, required = true, ...rest } = item\n\n if (!enabled) {\n return acc\n }\n\n if (!name) {\n // when name is not se we will use TypeScript generics\n acc.push(`${type}${rest.default ? ` = ${rest.default}` : ''}`)\n\n return acc\n }\n // TODO check whey we still need the camelcase here\n const parameterName = name.startsWith('{') ? name : camelCase(name)\n\n if (type) {\n if (required) {\n acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ''}`)\n } else {\n acc.push(`${parameterName}?: ${type}`)\n }\n } else {\n acc.push(`${parameterName}`)\n }\n\n return acc\n }\n\n static toObject(items: FunctionParamsAST[]): FunctionParamsAST {\n let type: string[] = []\n let name: string[] = []\n\n const enabled = items.every(item => item.enabled) ? items.at(0)?.enabled : true\n const required = items.every(item => item.required) ?? true\n\n items.forEach(item => {\n name = FunctionParams.#addParams(name, { ...item, type: undefined })\n if (items.some(item => item.type)) {\n type = FunctionParams.#addParams(type, item)\n }\n })\n\n return {\n name: `{ ${name.join(', ')} }`,\n type: type.length ? `{ ${type.join(', ')} }` : undefined,\n enabled,\n required,\n }\n }\n\n static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string {\n const sortedData = this.#orderItems(items)\n\n return sortedData\n .reduce((acc, item) => {\n if (Array.isArray(item)) {\n const subItems = this.#orderItems(item) as FunctionParamsAST[]\n const objectItem = FunctionParams.toObject(subItems)\n\n return FunctionParams.#addParams(acc, objectItem)\n }\n\n return FunctionParams.#addParams(acc, item)\n }, [] as string[])\n .join(', ')\n }\n\n toObject(): FunctionParamsAST {\n const items = FunctionParams.#orderItems(this.#items).flat()\n\n return FunctionParams.toObject(items)\n }\n\n toString(): string {\n const items = FunctionParams.#orderItems(this.#items)\n\n return FunctionParams.toString(items)\n }\n}\n","import type { PossiblePromise } from '@kubb/types'\n\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return !!result && typeof (result as Promise<unknown>)?.then === 'function'\n}\n\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","export function renderTemplate<TData extends Record<string, unknown> = Record<string, unknown>>(template: string, data: TData | undefined = undefined): string {\n if (!data || !Object.keys(data).length) {\n return template.replace(/{{(.*?)}}/g, '')\n }\n\n const matches = template.match(/{{(.*?)}}/g)\n\n return (\n matches?.reduce((prev, curr) => {\n const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim()\n if (index === undefined) {\n return prev\n }\n const value = data[index]\n\n if (value === undefined) {\n return prev\n }\n\n return prev\n .replace(curr, () => {\n if (typeof value === 'boolean') {\n return `${value.toString()}` || 'false'\n }\n\n return (value as string) || ''\n })\n .trim()\n }, template) || ''\n )\n}\n","export async function timeout(ms: number): Promise<unknown> {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(true)\n }, ms)\n })\n}\n"]}
package/dist/utils.d.cts CHANGED
@@ -28,10 +28,14 @@ type FunctionParamsASTWithType = {
28
28
  };
29
29
  type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType;
30
30
  declare class FunctionParams {
31
+ #private;
31
32
  type?: 'generics' | 'typed';
32
- items: FunctionParamsAST[];
33
33
  constructor(type?: 'generics' | 'typed');
34
- add(item: FunctionParamsAST | Array<FunctionParamsAST | undefined> | undefined): FunctionParams;
34
+ get items(): FunctionParamsAST[];
35
+ add(item: FunctionParamsAST | Array<FunctionParamsAST | FunctionParamsAST[] | undefined> | undefined): FunctionParams;
36
+ static toObject(items: FunctionParamsAST[]): FunctionParamsAST;
37
+ static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string;
38
+ toObject(): FunctionParamsAST;
35
39
  toString(): string;
36
40
  }
37
41
 
package/dist/utils.d.ts CHANGED
@@ -28,10 +28,14 @@ type FunctionParamsASTWithType = {
28
28
  };
29
29
  type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType;
30
30
  declare class FunctionParams {
31
+ #private;
31
32
  type?: 'generics' | 'typed';
32
- items: FunctionParamsAST[];
33
33
  constructor(type?: 'generics' | 'typed');
34
- add(item: FunctionParamsAST | Array<FunctionParamsAST | undefined> | undefined): FunctionParams;
34
+ get items(): FunctionParamsAST[];
35
+ add(item: FunctionParamsAST | Array<FunctionParamsAST | FunctionParamsAST[] | undefined> | undefined): FunctionParams;
36
+ static toObject(items: FunctionParamsAST[]): FunctionParamsAST;
37
+ static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string;
38
+ toObject(): FunctionParamsAST;
35
39
  toString(): string;
36
40
  }
37
41
 
package/dist/utils.js CHANGED
@@ -9,6 +9,9 @@ import {
9
9
  camelCase
10
10
  } from "./chunk-SV7GUBBD.js";
11
11
  import {
12
+ __privateAdd,
13
+ __privateGet,
14
+ __privateMethod,
12
15
  init_esm_shims
13
16
  } from "./chunk-77TYOFGF.js";
14
17
 
@@ -18,44 +21,115 @@ init_esm_shims();
18
21
  // src/utils/FunctionParams.ts
19
22
  init_esm_shims();
20
23
  import { orderBy } from "natural-orderby";
21
- var FunctionParams = class {
24
+ var _items, _orderItems, orderItems_fn, _addParams, addParams_fn;
25
+ var _FunctionParams = class _FunctionParams {
22
26
  constructor(type) {
23
- this.items = [];
27
+ __privateAdd(this, _items, []);
24
28
  this.type = type;
25
29
  return this;
26
30
  }
31
+ get items() {
32
+ return __privateGet(this, _items).flat();
33
+ }
27
34
  add(item) {
28
35
  if (!item) {
29
36
  return this;
30
37
  }
31
38
  if (Array.isArray(item)) {
32
- item.filter(Boolean).forEach((it) => this.items.push(it));
39
+ item.filter(Boolean).forEach((it) => __privateGet(this, _items).push(it));
33
40
  return this;
34
41
  }
35
- this.items.push(item);
42
+ __privateGet(this, _items).push(item);
36
43
  return this;
37
44
  }
38
- toString() {
39
- const sortedData = orderBy(this.items.filter(Boolean), [(v) => !v.default, (v) => v.required ?? true], ["desc", "desc"]);
40
- return sortedData.filter(({ enabled = true }) => enabled).reduce((acc, { name, type, required = true, ...rest }) => {
41
- if (!name) {
42
- acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
43
- return acc;
45
+ static toObject(items) {
46
+ let type = [];
47
+ let name = [];
48
+ const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true;
49
+ const required = items.every((item) => item.required) ?? true;
50
+ items.forEach((item) => {
51
+ var _a, _b;
52
+ name = __privateMethod(_a = _FunctionParams, _addParams, addParams_fn).call(_a, name, { ...item, type: void 0 });
53
+ if (items.some((item2) => item2.type)) {
54
+ type = __privateMethod(_b = _FunctionParams, _addParams, addParams_fn).call(_b, type, item);
44
55
  }
45
- const parameterName = name.startsWith("{") ? name : camelCase(name);
46
- if (type) {
47
- if (required) {
48
- acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
49
- } else {
50
- acc.push(`${parameterName}?: ${type}`);
51
- }
52
- } else {
53
- acc.push(`${parameterName}`);
56
+ });
57
+ return {
58
+ name: `{ ${name.join(", ")} }`,
59
+ type: type.length ? `{ ${type.join(", ")} }` : void 0,
60
+ enabled,
61
+ required
62
+ };
63
+ }
64
+ static toString(items) {
65
+ const sortedData = __privateMethod(this, _orderItems, orderItems_fn).call(this, items);
66
+ return sortedData.reduce((acc, item) => {
67
+ var _a, _b;
68
+ if (Array.isArray(item)) {
69
+ const subItems = __privateMethod(this, _orderItems, orderItems_fn).call(this, item);
70
+ const objectItem = _FunctionParams.toObject(subItems);
71
+ return __privateMethod(_a = _FunctionParams, _addParams, addParams_fn).call(_a, acc, objectItem);
54
72
  }
55
- return acc;
73
+ return __privateMethod(_b = _FunctionParams, _addParams, addParams_fn).call(_b, acc, item);
56
74
  }, []).join(", ");
57
75
  }
76
+ toObject() {
77
+ var _a;
78
+ const items = __privateMethod(_a = _FunctionParams, _orderItems, orderItems_fn).call(_a, __privateGet(this, _items)).flat();
79
+ return _FunctionParams.toObject(items);
80
+ }
81
+ toString() {
82
+ var _a;
83
+ const items = __privateMethod(_a = _FunctionParams, _orderItems, orderItems_fn).call(_a, __privateGet(this, _items));
84
+ return _FunctionParams.toString(items);
85
+ }
86
+ };
87
+ _items = new WeakMap();
88
+ _orderItems = new WeakSet();
89
+ orderItems_fn = function(items) {
90
+ return orderBy(items.filter(Boolean), [
91
+ (v) => {
92
+ if (Array.isArray(v)) {
93
+ return void 0;
94
+ }
95
+ return !v.default;
96
+ },
97
+ (v) => {
98
+ if (Array.isArray(v)) {
99
+ return void 0;
100
+ }
101
+ return v.required ?? true;
102
+ }
103
+ ], [
104
+ "desc",
105
+ "desc"
106
+ ]);
107
+ };
108
+ _addParams = new WeakSet();
109
+ addParams_fn = function(acc, item) {
110
+ const { enabled = true, name, type, required = true, ...rest } = item;
111
+ if (!enabled) {
112
+ return acc;
113
+ }
114
+ if (!name) {
115
+ acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
116
+ return acc;
117
+ }
118
+ const parameterName = name.startsWith("{") ? name : camelCase(name);
119
+ if (type) {
120
+ if (required) {
121
+ acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
122
+ } else {
123
+ acc.push(`${parameterName}?: ${type}`);
124
+ }
125
+ } else {
126
+ acc.push(`${parameterName}`);
127
+ }
128
+ return acc;
58
129
  };
130
+ __privateAdd(_FunctionParams, _orderItems);
131
+ __privateAdd(_FunctionParams, _addParams);
132
+ var FunctionParams = _FunctionParams;
59
133
 
60
134
  // src/utils/promise.ts
61
135
  init_esm_shims();
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/index.ts","../src/utils/FunctionParams.ts","../src/utils/promise.ts","../src/utils/renderTemplate.ts","../src/utils/timeout.ts"],"sourcesContent":["export type { FunctionParamsAST } from './FunctionParams.ts'\nexport { FunctionParams } from './FunctionParams.ts'\nexport { isPromise, isPromiseFulfilledResult, isPromiseRejectedResult } from './promise.ts'\nexport { renderTemplate } from './renderTemplate.ts'\nexport { timeout } from './timeout.ts'\nexport { getUniqueName, setUniqueName } from './uniqueName.ts'\nexport type { URLObject } from './URLPath.ts'\nexport { URLPath } from './URLPath.ts'\n","import { orderBy } from 'natural-orderby'\n\nimport { camelCase } from '../transformers/casing.ts'\n\ntype FunctionParamsASTWithoutType = {\n name?: string\n type?: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n\ntype FunctionParamsASTWithType = {\n name?: never\n type: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n\nexport type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType\nexport class FunctionParams {\n public type?: 'generics' | 'typed'\n public items: FunctionParamsAST[] = []\n constructor(type?: 'generics' | 'typed') {\n this.type = type\n\n return this\n }\n\n add(item: FunctionParamsAST | Array<FunctionParamsAST | undefined> | undefined): FunctionParams {\n if (!item) {\n return this\n }\n\n if (Array.isArray(item)) {\n item.filter(Boolean).forEach((it) => this.items.push(it))\n return this\n }\n this.items.push(item)\n\n return this\n }\n\n toString(): string {\n const sortedData = orderBy(this.items.filter(Boolean), [(v) => !v.default, (v) => v.required ?? true], ['desc', 'desc'])\n\n return sortedData\n .filter(({ enabled = true }) => enabled)\n .reduce((acc, { name, type, required = true, ...rest }) => {\n if (!name) {\n // when name is not se we will use TypeScript generics\n acc.push(`${type}${rest.default ? ` = ${rest.default}` : ''}`)\n\n return acc\n }\n // TODO check whey we still need the camelcase here\n const parameterName = name.startsWith('{') ? name : camelCase(name)\n\n if (type) {\n if (required) {\n acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ''}`)\n } else {\n acc.push(`${parameterName}?: ${type}`)\n }\n } else {\n acc.push(`${parameterName}`)\n }\n\n return acc\n }, [] as string[])\n .join(', ')\n }\n}\n","import type { PossiblePromise } from '@kubb/types'\n\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return !!result && typeof (result as Promise<unknown>)?.then === 'function'\n}\n\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","export function renderTemplate<TData extends Record<string, unknown> = Record<string, unknown>>(template: string, data: TData | undefined = undefined): string {\n if (!data || !Object.keys(data).length) {\n return template.replace(/{{(.*?)}}/g, '')\n }\n\n const matches = template.match(/{{(.*?)}}/g)\n\n return (\n matches?.reduce((prev, curr) => {\n const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim()\n if (index === undefined) {\n return prev\n }\n const value = data[index]\n\n if (value === undefined) {\n return prev\n }\n\n return prev\n .replace(curr, () => {\n if (typeof value === 'boolean') {\n return `${value.toString()}` || 'false'\n }\n\n return (value as string) || ''\n })\n .trim()\n }, template) || ''\n )\n}\n","export async function timeout(ms: number): Promise<unknown> {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(true)\n }, ms)\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA;;;ACAA;AAAA,SAAS,eAAe;AAiCjB,IAAM,iBAAN,MAAqB;AAAA,EAG1B,YAAY,MAA6B;AADzC,SAAO,QAA6B,CAAC;AAEnC,SAAK,OAAO;AAEZ,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,MAA4F;AAC9F,QAAI,CAAC,MAAM;AACT,aAAO;AAAA,IACT;AAEA,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,WAAK,OAAO,OAAO,EAAE,QAAQ,CAAC,OAAO,KAAK,MAAM,KAAK,EAAE,CAAC;AACxD,aAAO;AAAA,IACT;AACA,SAAK,MAAM,KAAK,IAAI;AAEpB,WAAO;AAAA,EACT;AAAA,EAEA,WAAmB;AACjB,UAAM,aAAa,QAAQ,KAAK,MAAM,OAAO,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,YAAY,IAAI,GAAG,CAAC,QAAQ,MAAM,CAAC;AAEvH,WAAO,WACJ,OAAO,CAAC,EAAE,UAAU,KAAK,MAAM,OAAO,EACtC,OAAO,CAAC,KAAK,EAAE,MAAM,MAAM,WAAW,MAAM,GAAG,KAAK,MAAM;AACzD,UAAI,CAAC,MAAM;AAET,YAAI,KAAK,GAAG,IAAI,GAAG,KAAK,UAAU,MAAM,KAAK,OAAO,KAAK,EAAE,EAAE;AAE7D,eAAO;AAAA,MACT;AAEA,YAAM,gBAAgB,KAAK,WAAW,GAAG,IAAI,OAAO,UAAU,IAAI;AAElE,UAAI,MAAM;AACR,YAAI,UAAU;AACZ,cAAI,KA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CAAC,YAAY;AAC9B,eAAW,MAAM;AACf,cAAQ,IAAI;AAAA,IACd,GAAG,EAAE;AAAA,EACP,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/utils/index.ts","../src/utils/FunctionParams.ts","../src/utils/promise.ts","../src/utils/renderTemplate.ts","../src/utils/timeout.ts"],"sourcesContent":["export type { FunctionParamsAST } from './FunctionParams.ts'\nexport { FunctionParams } from './FunctionParams.ts'\nexport { isPromise, isPromiseFulfilledResult, isPromiseRejectedResult } from './promise.ts'\nexport { renderTemplate } from './renderTemplate.ts'\nexport { timeout } from './timeout.ts'\nexport { getUniqueName, setUniqueName } from './uniqueName.ts'\nexport type { URLObject } from './URLPath.ts'\nexport { URLPath } from './URLPath.ts'\n","import { orderBy } from 'natural-orderby'\n\nimport { camelCase } from '../transformers/casing.ts'\n\ntype FunctionParamsASTWithoutType = {\n name?: string\n type?: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n\ntype FunctionParamsASTWithType = {\n name?: never\n type: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n\nexport type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType\nexport class FunctionParams {\n type?: 'generics' | 'typed'\n #items: Array<FunctionParamsAST | FunctionParamsAST[]> = []\n constructor(type?: 'generics' | 'typed') {\n this.type = type\n\n return this\n }\n\n get items(): FunctionParamsAST[] {\n return this.#items.flat()\n }\n\n add(item: FunctionParamsAST | Array<FunctionParamsAST | FunctionParamsAST[] | undefined> | undefined): FunctionParams {\n if (!item) {\n return this\n }\n\n if (Array.isArray(item)) {\n item.filter(Boolean).forEach((it) => this.#items.push(it))\n return this\n }\n this.#items.push(item)\n\n return this\n }\n static #orderItems(items: Array<FunctionParamsAST | FunctionParamsAST[]>) {\n return orderBy(items.filter(Boolean), [\n (v) => {\n if (Array.isArray(v)) {\n return undefined\n }\n return !v.default\n },\n (v) => {\n if (Array.isArray(v)) {\n return undefined\n }\n return v.required ?? true\n },\n ], [\n 'desc',\n 'desc',\n ])\n }\n\n static #addParams(acc: string[], item: FunctionParamsAST) {\n const { enabled = true, name, type, required = true, ...rest } = item\n\n if (!enabled) {\n return acc\n }\n\n if (!name) {\n // when name is not se we will use TypeScript generics\n acc.push(`${type}${rest.default ? ` = ${rest.default}` : ''}`)\n\n return acc\n }\n // TODO check whey we still need the camelcase here\n const parameterName = name.startsWith('{') ? name : camelCase(name)\n\n if (type) {\n if (required) {\n acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ''}`)\n } else {\n acc.push(`${parameterName}?: ${type}`)\n }\n } else {\n acc.push(`${parameterName}`)\n }\n\n return acc\n }\n\n static toObject(items: FunctionParamsAST[]): FunctionParamsAST {\n let type: string[] = []\n let name: string[] = []\n\n const enabled = items.every(item => item.enabled) ? items.at(0)?.enabled : true\n const required = items.every(item => item.required) ?? true\n\n items.forEach(item => {\n name = FunctionParams.#addParams(name, { ...item, type: undefined })\n if (items.some(item => item.type)) {\n type = FunctionParams.#addParams(type, item)\n }\n })\n\n return {\n name: `{ ${name.join(', ')} }`,\n type: type.length ? `{ ${type.join(', ')} }` : undefined,\n enabled,\n required,\n }\n }\n\n static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string {\n const sortedData = this.#orderItems(items)\n\n return sortedData\n .reduce((acc, item) => {\n if (Array.isArray(item)) {\n const subItems = this.#orderItems(item) as FunctionParamsAST[]\n const objectItem = FunctionParams.toObject(subItems)\n\n return FunctionParams.#addParams(acc, objectItem)\n }\n\n return FunctionParams.#addParams(acc, item)\n }, [] as string[])\n .join(', ')\n }\n\n toObject(): FunctionParamsAST {\n const items = FunctionParams.#orderItems(this.#items).flat()\n\n return FunctionParams.toObject(items)\n }\n\n toString(): string {\n const items = FunctionParams.#orderItems(this.#items)\n\n return FunctionParams.toString(items)\n }\n}\n","import type { PossiblePromise } from '@kubb/types'\n\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return !!result && typeof (result as Promise<unknown>)?.then === 'function'\n}\n\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","export function renderTemplate<TData extends Record<string, unknown> = Record<string, unknown>>(template: string, data: TData | undefined = undefined): string {\n if (!data || !Object.keys(data).length) {\n return template.replace(/{{(.*?)}}/g, '')\n }\n\n const matches = template.match(/{{(.*?)}}/g)\n\n return (\n matches?.reduce((prev, curr) => {\n const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim()\n if (index === undefined) {\n return prev\n }\n const value = data[index]\n\n if (value === undefined) {\n return prev\n }\n\n return prev\n .replace(curr, () => {\n if (typeof value === 'boolean') {\n return `${value.toString()}` || 'false'\n }\n\n return (value as string) || ''\n })\n .trim()\n }, template) || ''\n )\n}\n","export async function timeout(ms: number): Promise<unknown> {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(true)\n }, ms)\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;ACAA;AAAA,SAAS,eAAe;AAAxB;AAiCO,IAAM,kBAAN,MAAM,gBAAe;AAAA,EAG1B,YAAY,MAA6B;AADzC,+BAAyD,CAAC;AAExD,SAAK,OAAO;AAEZ,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,QAA6B;AAC/B,WAAO,mBAAK,QAAO,KAAK;AAAA,EAC1B;AAAA,EAEA,IAAI,MAAkH;AACpH,QAAI,CAAC,MAAM;AACT,aAAO;AAAA,IACT;AAEA,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,WAAK,OAAO,OAAO,EAAE,QAAQ,CAAC,OAAO,mBAAK,QAAO,KAAK,EAAE,CAAC;AACzD,aAAO;AAAA,IACT;AACA,uBAAK,QAAO,KA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AC,UAAU,OAAQ,QAA6B,SAAS;AACnE;AAEO,SAAS,yBAAsC,QAA4E;AAChI,SAAO,OAAO,WAAW;AAC3B;AAEO,SAAS,wBAA2B,QAAwG;AACjJ,SAAO,OAAO,WAAW;AAC3B;;;ACZA;AAAO,SAAS,eAAgF,UAAkB,OAA0B,QAAmB;AAC7J,MAAI,CAAC,QAAQ,CAAC,OAAO,KAAK,IAAI,EAAE,QAAQ;AACtC,WAAO,SAAS,QAAQ,cAAc,EAAE;AAAA,EAC1C;AAEA,QAAM,UAAU,SAAS,MAAM,YAAY;AAE3C,SACE,SAAS,OAAO,CAAC,MAAM,SAAS;AAC9B,UAAM,QAAQ,KAAK,MAAM,OAAO,EAAE,OAAO,OAAO,EAAE,CAAC,GAAG,KAAK;AAC3D,QAAI,UAAU,QAAW;AACvB,aAAO;AAAA,IACT;AACA,UAAM,QAAQ,KAAK,KAAK;AAExB,QAAI,UAAU,QAAW;AACvB,aAAO;AAAA,IACT;AAEA,WAAO,KACJ,QAAQ,MAAM,MAAM;AACnB,UAAI,OAAO,UAAU,WAAW;AAC9B,eAAO,GAAG,MAAM,SAAS,CAAC,MAAM;AAAA,MAClC;AAEA,aAAQ,SAAoB;AAAA,IAC9B,CAAC,EACA,KAAK;AAAA,EACV,GAAG,QAAQ,KAAK;AAEpB;;;AC9BA;AAAA,eAAsB,QAAQ,IAA8B;AAC1D,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,eAAW,MAAM;AACf,cAAQ,IAAI;AAAA,IACd,GAAG,EAAE;AAAA,EACP,CAAC;AACH;","names":["item"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "2.8.2",
3
+ "version": "2.9.0",
4
4
  "description": "Generator core",
5
5
  "keywords": [
6
6
  "typescript",
@@ -95,8 +95,8 @@
95
95
  "p-queue": "^8.0.1",
96
96
  "seedrandom": "^3.0.5",
97
97
  "semver": "^7.6.0",
98
- "@kubb/parser": "2.8.2",
99
- "@kubb/types": "2.8.2"
98
+ "@kubb/parser": "2.9.0",
99
+ "@kubb/types": "2.9.0"
100
100
  },
101
101
  "devDependencies": {
102
102
  "@types/fs-extra": "^11.0.4",
@@ -32,55 +32,128 @@ type FunctionParamsASTWithType = {
32
32
 
33
33
  export type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType
34
34
  export class FunctionParams {
35
- public type?: 'generics' | 'typed'
36
- public items: FunctionParamsAST[] = []
35
+ type?: 'generics' | 'typed'
36
+ #items: Array<FunctionParamsAST | FunctionParamsAST[]> = []
37
37
  constructor(type?: 'generics' | 'typed') {
38
38
  this.type = type
39
39
 
40
40
  return this
41
41
  }
42
42
 
43
- add(item: FunctionParamsAST | Array<FunctionParamsAST | undefined> | undefined): FunctionParams {
43
+ get items(): FunctionParamsAST[] {
44
+ return this.#items.flat()
45
+ }
46
+
47
+ add(item: FunctionParamsAST | Array<FunctionParamsAST | FunctionParamsAST[] | undefined> | undefined): FunctionParams {
44
48
  if (!item) {
45
49
  return this
46
50
  }
47
51
 
48
52
  if (Array.isArray(item)) {
49
- item.filter(Boolean).forEach((it) => this.items.push(it))
53
+ item.filter(Boolean).forEach((it) => this.#items.push(it))
50
54
  return this
51
55
  }
52
- this.items.push(item)
56
+ this.#items.push(item)
53
57
 
54
58
  return this
55
59
  }
60
+ static #orderItems(items: Array<FunctionParamsAST | FunctionParamsAST[]>) {
61
+ return orderBy(items.filter(Boolean), [
62
+ (v) => {
63
+ if (Array.isArray(v)) {
64
+ return undefined
65
+ }
66
+ return !v.default
67
+ },
68
+ (v) => {
69
+ if (Array.isArray(v)) {
70
+ return undefined
71
+ }
72
+ return v.required ?? true
73
+ },
74
+ ], [
75
+ 'desc',
76
+ 'desc',
77
+ ])
78
+ }
56
79
 
57
- toString(): string {
58
- const sortedData = orderBy(this.items.filter(Boolean), [(v) => !v.default, (v) => v.required ?? true], ['desc', 'desc'])
80
+ static #addParams(acc: string[], item: FunctionParamsAST) {
81
+ const { enabled = true, name, type, required = true, ...rest } = item
82
+
83
+ if (!enabled) {
84
+ return acc
85
+ }
86
+
87
+ if (!name) {
88
+ // when name is not se we will use TypeScript generics
89
+ acc.push(`${type}${rest.default ? ` = ${rest.default}` : ''}`)
90
+
91
+ return acc
92
+ }
93
+ // TODO check whey we still need the camelcase here
94
+ const parameterName = name.startsWith('{') ? name : camelCase(name)
95
+
96
+ if (type) {
97
+ if (required) {
98
+ acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ''}`)
99
+ } else {
100
+ acc.push(`${parameterName}?: ${type}`)
101
+ }
102
+ } else {
103
+ acc.push(`${parameterName}`)
104
+ }
105
+
106
+ return acc
107
+ }
108
+
109
+ static toObject(items: FunctionParamsAST[]): FunctionParamsAST {
110
+ let type: string[] = []
111
+ let name: string[] = []
112
+
113
+ const enabled = items.every(item => item.enabled) ? items.at(0)?.enabled : true
114
+ const required = items.every(item => item.required) ?? true
115
+
116
+ items.forEach(item => {
117
+ name = FunctionParams.#addParams(name, { ...item, type: undefined })
118
+ if (items.some(item => item.type)) {
119
+ type = FunctionParams.#addParams(type, item)
120
+ }
121
+ })
122
+
123
+ return {
124
+ name: `{ ${name.join(', ')} }`,
125
+ type: type.length ? `{ ${type.join(', ')} }` : undefined,
126
+ enabled,
127
+ required,
128
+ }
129
+ }
130
+
131
+ static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string {
132
+ const sortedData = this.#orderItems(items)
59
133
 
60
134
  return sortedData
61
- .filter(({ enabled = true }) => enabled)
62
- .reduce((acc, { name, type, required = true, ...rest }) => {
63
- if (!name) {
64
- // when name is not se we will use TypeScript generics
65
- acc.push(`${type}${rest.default ? ` = ${rest.default}` : ''}`)
135
+ .reduce((acc, item) => {
136
+ if (Array.isArray(item)) {
137
+ const subItems = this.#orderItems(item) as FunctionParamsAST[]
138
+ const objectItem = FunctionParams.toObject(subItems)
66
139
 
67
- return acc
68
- }
69
- // TODO check whey we still need the camelcase here
70
- const parameterName = name.startsWith('{') ? name : camelCase(name)
71
-
72
- if (type) {
73
- if (required) {
74
- acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ''}`)
75
- } else {
76
- acc.push(`${parameterName}?: ${type}`)
77
- }
78
- } else {
79
- acc.push(`${parameterName}`)
140
+ return FunctionParams.#addParams(acc, objectItem)
80
141
  }
81
142
 
82
- return acc
143
+ return FunctionParams.#addParams(acc, item)
83
144
  }, [] as string[])
84
145
  .join(', ')
85
146
  }
147
+
148
+ toObject(): FunctionParamsAST {
149
+ const items = FunctionParams.#orderItems(this.#items).flat()
150
+
151
+ return FunctionParams.toObject(items)
152
+ }
153
+
154
+ toString(): string {
155
+ const items = FunctionParams.#orderItems(this.#items)
156
+
157
+ return FunctionParams.toString(items)
158
+ }
86
159
  }