arri 0.0.44 → 0.1.0-beta.2

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.
@@ -1,179 +0,0 @@
1
- const NUMBER_CHAR_RE = /\d/;
2
- const STR_SPLITTERS = ["-", "_", "/", "."];
3
- function isUppercase(char = "") {
4
- if (NUMBER_CHAR_RE.test(char)) {
5
- return void 0;
6
- }
7
- return char.toUpperCase() === char;
8
- }
9
- function splitByCase(string_, separators) {
10
- const splitters = separators ?? STR_SPLITTERS;
11
- const parts = [];
12
- if (!string_ || typeof string_ !== "string") {
13
- return parts;
14
- }
15
- let buff = "";
16
- let previousUpper;
17
- let previousSplitter;
18
- for (const char of string_) {
19
- const isSplitter = splitters.includes(char);
20
- if (isSplitter === true) {
21
- parts.push(buff);
22
- buff = "";
23
- previousUpper = void 0;
24
- continue;
25
- }
26
- const isUpper = isUppercase(char);
27
- if (previousSplitter === false) {
28
- if (previousUpper === false && isUpper === true) {
29
- parts.push(buff);
30
- buff = char;
31
- previousUpper = isUpper;
32
- continue;
33
- }
34
- if (previousUpper === true && isUpper === false && buff.length > 1) {
35
- const lastChar = buff[buff.length - 1];
36
- parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
37
- buff = lastChar + char;
38
- previousUpper = isUpper;
39
- continue;
40
- }
41
- }
42
- buff += char;
43
- previousUpper = isUpper;
44
- previousSplitter = isSplitter;
45
- }
46
- parts.push(buff);
47
- return parts;
48
- }
49
- function upperFirst(string_) {
50
- return !string_ ? "" : string_[0].toUpperCase() + string_.slice(1);
51
- }
52
- function lowerFirst(string_) {
53
- return !string_ ? "" : string_[0].toLowerCase() + string_.slice(1);
54
- }
55
- function pascalCase(string_) {
56
- return !string_ ? "" : (Array.isArray(string_) ? string_ : splitByCase(string_)).map((p) => upperFirst(p)).join("");
57
- }
58
- function camelCase(string_) {
59
- return lowerFirst(pascalCase(string_));
60
- }
61
- function kebabCase(string_, joiner) {
62
- return !string_ ? "" : (Array.isArray(string_) ? string_ : splitByCase(string_)).map((p) => p.toLowerCase()).join(joiner ?? "-");
63
- }
64
-
65
- const HttpMethodValues = [
66
- "get",
67
- "post",
68
- "put",
69
- "patch",
70
- "delete",
71
- "head"
72
- ];
73
- const isHttpMethod = (input) => {
74
- if (typeof input !== "string") {
75
- return false;
76
- }
77
- return HttpMethodValues.includes(input);
78
- };
79
-
80
- function normalizeWhitespace(input) {
81
- if (input.includes("\n\n")) {
82
- return normalizeWhitespace(input.split("\n\n").join("\n"));
83
- }
84
- const lines = [];
85
- for (const line of input.split("\n")) {
86
- lines.push(line.trim());
87
- }
88
- const result = lines.join("\n").trim();
89
- if (result.includes("\n\n")) {
90
- return normalizeWhitespace(result.split("\n\n").join("\n"));
91
- }
92
- return result;
93
- }
94
- function isProcedureDef(input) {
95
- if (typeof input !== "object") {
96
- return false;
97
- }
98
- const expectedKeys = ["path", "method"];
99
- const existingKeys = Object.keys(input);
100
- for (const key of expectedKeys) {
101
- if (!existingKeys.includes(key)) {
102
- return false;
103
- }
104
- }
105
- return isHttpMethod(input.method) && typeof input.path === "string" && (typeof input.params === "string" || typeof input.params === "undefined") && (typeof input.response === "string" || typeof input.response === "undefined");
106
- }
107
- function isServiceDef(input) {
108
- if (typeof input !== "object") {
109
- return false;
110
- }
111
- for (const key of Object.keys(input)) {
112
- if (typeof input[key] !== "object") {
113
- return false;
114
- }
115
- }
116
- return true;
117
- }
118
- function isApplicationDef(input) {
119
- if (typeof input !== "object") {
120
- return false;
121
- }
122
- if (!("procedures" in input) || typeof input.procedures !== "object") {
123
- return false;
124
- }
125
- if (!("models" in input) || typeof input.models !== "object") {
126
- return false;
127
- }
128
- if (!("errors" in input) || typeof input.errors !== "object") {
129
- return false;
130
- }
131
- return true;
132
- }
133
- function unflattenObject(data) {
134
- if (Object(data) !== data || Array.isArray(data))
135
- return data;
136
- const regex = /\.?([^.[\]]+)|\[(\d+)\]/g;
137
- const result = {};
138
- for (const p in data) {
139
- let cur = result;
140
- let prop = "";
141
- let m;
142
- while (m = regex.exec(p)) {
143
- cur = cur[prop] || (cur[prop] = m[2] ? [] : {});
144
- prop = m[2] || m[1];
145
- }
146
- cur[prop] = data[p];
147
- }
148
- return result[""] || result;
149
- }
150
- function unflattenProcedures(procedures) {
151
- return unflattenObject(procedures);
152
- }
153
- function setNestedObjectProperty(targetProp, value, object) {
154
- const parts = targetProp.split(".");
155
- let current = object;
156
- for (let i = 0; i < parts.length; i++) {
157
- const key = parts[i];
158
- if (i === parts.length - 1) {
159
- current[key] = value;
160
- } else {
161
- if (!current[key]) {
162
- current[key] = {};
163
- }
164
- current = current[key];
165
- }
166
- }
167
- return object;
168
- }
169
- const removeDisallowedChars = (input, disallowedChars) => {
170
- let result = input;
171
- for (const char of disallowedChars) {
172
- if (result.includes(char)) {
173
- result = result.split(char).join("");
174
- }
175
- }
176
- return result;
177
- };
178
-
179
- export { isProcedureDef as a, unflattenProcedures as b, camelCase as c, isApplicationDef as d, isHttpMethod as e, isServiceDef as i, kebabCase as k, normalizeWhitespace as n, pascalCase as p, removeDisallowedChars as r, setNestedObjectProperty as s, unflattenObject as u };