arri 0.0.38 → 0.0.40

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.
@@ -0,0 +1,192 @@
1
+ 'use strict';
2
+
3
+ const NUMBER_CHAR_RE = /\d/;
4
+ const STR_SPLITTERS = ["-", "_", "/", "."];
5
+ function isUppercase(char = "") {
6
+ if (NUMBER_CHAR_RE.test(char)) {
7
+ return void 0;
8
+ }
9
+ return char.toUpperCase() === char;
10
+ }
11
+ function splitByCase(string_, separators) {
12
+ const splitters = separators ?? STR_SPLITTERS;
13
+ const parts = [];
14
+ if (!string_ || typeof string_ !== "string") {
15
+ return parts;
16
+ }
17
+ let buff = "";
18
+ let previousUpper;
19
+ let previousSplitter;
20
+ for (const char of string_) {
21
+ const isSplitter = splitters.includes(char);
22
+ if (isSplitter === true) {
23
+ parts.push(buff);
24
+ buff = "";
25
+ previousUpper = void 0;
26
+ continue;
27
+ }
28
+ const isUpper = isUppercase(char);
29
+ if (previousSplitter === false) {
30
+ if (previousUpper === false && isUpper === true) {
31
+ parts.push(buff);
32
+ buff = char;
33
+ previousUpper = isUpper;
34
+ continue;
35
+ }
36
+ if (previousUpper === true && isUpper === false && buff.length > 1) {
37
+ const lastChar = buff[buff.length - 1];
38
+ parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
39
+ buff = lastChar + char;
40
+ previousUpper = isUpper;
41
+ continue;
42
+ }
43
+ }
44
+ buff += char;
45
+ previousUpper = isUpper;
46
+ previousSplitter = isSplitter;
47
+ }
48
+ parts.push(buff);
49
+ return parts;
50
+ }
51
+ function upperFirst(string_) {
52
+ return !string_ ? "" : string_[0].toUpperCase() + string_.slice(1);
53
+ }
54
+ function lowerFirst(string_) {
55
+ return !string_ ? "" : string_[0].toLowerCase() + string_.slice(1);
56
+ }
57
+ function pascalCase(string_) {
58
+ return !string_ ? "" : (Array.isArray(string_) ? string_ : splitByCase(string_)).map((p) => upperFirst(p)).join("");
59
+ }
60
+ function camelCase(string_) {
61
+ return lowerFirst(pascalCase(string_));
62
+ }
63
+ function kebabCase(string_, joiner) {
64
+ return !string_ ? "" : (Array.isArray(string_) ? string_ : splitByCase(string_)).map((p) => p.toLowerCase()).join(joiner ?? "-");
65
+ }
66
+
67
+ const HttpMethodValues = [
68
+ "get",
69
+ "post",
70
+ "put",
71
+ "patch",
72
+ "delete",
73
+ "head"
74
+ ];
75
+ const isHttpMethod = (input) => {
76
+ if (typeof input !== "string") {
77
+ return false;
78
+ }
79
+ return HttpMethodValues.includes(input);
80
+ };
81
+
82
+ function normalizeWhitespace(input) {
83
+ if (input.includes("\n\n")) {
84
+ return normalizeWhitespace(input.split("\n\n").join("\n"));
85
+ }
86
+ const lines = [];
87
+ for (const line of input.split("\n")) {
88
+ lines.push(line.trim());
89
+ }
90
+ const result = lines.join("\n").trim();
91
+ if (result.includes("\n\n")) {
92
+ return normalizeWhitespace(result.split("\n\n").join("\n"));
93
+ }
94
+ return result;
95
+ }
96
+ function isProcedureDef(input) {
97
+ if (typeof input !== "object") {
98
+ return false;
99
+ }
100
+ const expectedKeys = ["path", "method"];
101
+ const existingKeys = Object.keys(input);
102
+ for (const key of expectedKeys) {
103
+ if (!existingKeys.includes(key)) {
104
+ return false;
105
+ }
106
+ }
107
+ return isHttpMethod(input.method) && typeof input.path === "string" && (typeof input.params === "string" || typeof input.params === "undefined") && (typeof input.response === "string" || typeof input.response === "undefined");
108
+ }
109
+ function isServiceDef(input) {
110
+ if (typeof input !== "object") {
111
+ return false;
112
+ }
113
+ for (const key of Object.keys(input)) {
114
+ if (typeof input[key] !== "object") {
115
+ return false;
116
+ }
117
+ }
118
+ return true;
119
+ }
120
+ function isApplicationDef(input) {
121
+ if (typeof input !== "object") {
122
+ return false;
123
+ }
124
+ if (!("procedures" in input) || typeof input.procedures !== "object") {
125
+ return false;
126
+ }
127
+ if (!("models" in input) || typeof input.models !== "object") {
128
+ return false;
129
+ }
130
+ if (!("errors" in input) || typeof input.errors !== "object") {
131
+ return false;
132
+ }
133
+ return true;
134
+ }
135
+ function unflattenObject(data) {
136
+ if (Object(data) !== data || Array.isArray(data))
137
+ return data;
138
+ const regex = /\.?([^.[\]]+)|\[(\d+)\]/g;
139
+ const result = {};
140
+ for (const p in data) {
141
+ let cur = result;
142
+ let prop = "";
143
+ let m;
144
+ while (m = regex.exec(p)) {
145
+ cur = cur[prop] || (cur[prop] = m[2] ? [] : {});
146
+ prop = m[2] || m[1];
147
+ }
148
+ cur[prop] = data[p];
149
+ }
150
+ return result[""] || result;
151
+ }
152
+ function unflattenProcedures(procedures) {
153
+ return unflattenObject(procedures);
154
+ }
155
+ function setNestedObjectProperty(targetProp, value, object) {
156
+ const parts = targetProp.split(".");
157
+ let current = object;
158
+ for (let i = 0; i < parts.length; i++) {
159
+ const key = parts[i];
160
+ if (i === parts.length - 1) {
161
+ current[key] = value;
162
+ } else {
163
+ if (!current[key]) {
164
+ current[key] = {};
165
+ }
166
+ current = current[key];
167
+ }
168
+ }
169
+ return object;
170
+ }
171
+ const removeDisallowedChars = (input, disallowedChars) => {
172
+ let result = input;
173
+ for (const char of disallowedChars) {
174
+ if (result.includes(char)) {
175
+ result = result.split(char).join("");
176
+ }
177
+ }
178
+ return result;
179
+ };
180
+
181
+ exports.camelCase = camelCase;
182
+ exports.isApplicationDef = isApplicationDef;
183
+ exports.isHttpMethod = isHttpMethod;
184
+ exports.isProcedureDef = isProcedureDef;
185
+ exports.isServiceDef = isServiceDef;
186
+ exports.kebabCase = kebabCase;
187
+ exports.normalizeWhitespace = normalizeWhitespace;
188
+ exports.pascalCase = pascalCase;
189
+ exports.removeDisallowedChars = removeDisallowedChars;
190
+ exports.setNestedObjectProperty = setNestedObjectProperty;
191
+ exports.unflattenObject = unflattenObject;
192
+ exports.unflattenProcedures = unflattenProcedures;
@@ -1,11 +1,83 @@
1
1
  import { execSync } from 'child_process';
2
2
  import { writeFileSync } from 'fs';
3
- import { h as unflattenProcedures, i as isServiceDef, p as pascalCase, j as camelCase, a as isProcedureDef, d as isJsonSchemaObject, f as isJsonSchemaEnum, c as isJsonSchemaNullType, b as isJsonSchemaScalarType, e as isJsonSchemaRecord, g as isJsonSchemaArray } from './arri.f1c922a6.mjs';
3
+ import { b as unflattenProcedures, i as isServiceDef, p as pascalCase, c as camelCase, a as isProcedureDef } from './arri.ebf86912.mjs';
4
4
 
5
5
  function defineClientGeneratorPlugin(plugin) {
6
6
  return plugin;
7
7
  }
8
8
 
9
+ const JsonSchemaScalarTypeValues = [
10
+ "integer",
11
+ "number",
12
+ "bigint",
13
+ "string",
14
+ "boolean",
15
+ "Date"
16
+ ];
17
+ const JsonSchemaNullTypeValues = ["null", "undefined"];
18
+ function isJsonSchemaScalarType(input) {
19
+ if (typeof input !== "object") {
20
+ return false;
21
+ }
22
+ if (!("type" in input)) {
23
+ return false;
24
+ }
25
+ return JsonSchemaScalarTypeValues.includes(input.type);
26
+ }
27
+ function isJsonSchemaNullType(input) {
28
+ if (typeof input !== "object") {
29
+ return false;
30
+ }
31
+ if (!("type" in input)) {
32
+ return false;
33
+ }
34
+ return JsonSchemaNullTypeValues.includes(input.type);
35
+ }
36
+ const isJsonSchemaObject = (input) => {
37
+ if (typeof input !== "object") {
38
+ return false;
39
+ }
40
+ return "type" in input && input.type === "object" && "properties" in input && typeof input.properties === "object";
41
+ };
42
+ const isJsonSchemaRecord = (input) => {
43
+ if (typeof input !== "object") {
44
+ return false;
45
+ }
46
+ return "type" in input && input.type === "object" && "patternProperties" in input && typeof input.patternProperties === "object";
47
+ };
48
+ function isJsonSchemaArray(input) {
49
+ if (typeof input !== "object") {
50
+ return false;
51
+ }
52
+ if ("type" in input && input.type === "array") {
53
+ return true;
54
+ }
55
+ return false;
56
+ }
57
+ function isJsonSchemaEnum(input) {
58
+ if (typeof input !== "object") {
59
+ return false;
60
+ }
61
+ if (!("anyOf" in input) || !Array.isArray(input.anyOf)) {
62
+ return false;
63
+ }
64
+ let prevType;
65
+ for (const item of input.anyOf) {
66
+ if (!isJsonSchemaScalarType(item)) {
67
+ return false;
68
+ }
69
+ if (item.type !== "string" && item.type !== "integer" && item.type !== "number") {
70
+ return false;
71
+ }
72
+ if (!prevType) {
73
+ prevType = item.type;
74
+ } else if (prevType !== item.type) {
75
+ return false;
76
+ }
77
+ }
78
+ return true;
79
+ }
80
+
9
81
  const dartClientGenerator = defineClientGeneratorPlugin(
10
82
  (options) => {
11
83
  return {
@@ -679,4 +751,4 @@ function isDartTypeWithNullables(input) {
679
751
  return false;
680
752
  }
681
753
 
682
- export { dartClientGenerator as a, dartServiceFromServiceDefinition as b, createDartClient as c, defineClientGeneratorPlugin as d, dartProcedureFromServiceDefinition as e, dartModelFromJsonSchema as f, dartPropertyTypeFromSchema as g, dartParsedJsonField as h, classTransformer as i, classListTransformer as j, isDartType as k, isDartTypeWithNullables as l, transformers as t };
754
+ export { isJsonSchemaNullType as a, isJsonSchemaObject as b, isJsonSchemaRecord as c, defineClientGeneratorPlugin as d, isJsonSchemaEnum as e, isJsonSchemaArray as f, dartClientGenerator as g, createDartClient as h, isJsonSchemaScalarType as i, dartServiceFromServiceDefinition as j, dartProcedureFromServiceDefinition as k, dartModelFromJsonSchema as l, dartPropertyTypeFromSchema as m, dartParsedJsonField as n, classTransformer as o, classListTransformer as p, isDartType as q, isDartTypeWithNullables as r, transformers as t };
@@ -0,0 +1,77 @@
1
+ import { TObject } from '@sinclair/typebox';
2
+
3
+ declare const HttpMethodValues: readonly ["get", "post", "put", "patch", "delete", "head"];
4
+ type HttpMethod = (typeof HttpMethodValues)[number];
5
+
6
+ declare const JsonSchemaScalarTypeValues: readonly ["integer", "number", "bigint", "string", "boolean", "Date"];
7
+ declare const JsonSchemaNullTypeValues: readonly ["null", "undefined"];
8
+ type JsonSchemaType = JsonSchemaScalarType | JsonSchemaNullType | JsonSchemaComplexType;
9
+ interface JsonSchemaTypeBase {
10
+ $id?: string;
11
+ title?: string;
12
+ description?: string;
13
+ }
14
+ interface JsonSchemaScalarType extends JsonSchemaTypeBase {
15
+ type: (typeof JsonSchemaScalarTypeValues)[number];
16
+ }
17
+ interface JsonSchemaNullType extends JsonSchemaTypeBase {
18
+ type: (typeof JsonSchemaNullTypeValues)[number];
19
+ }
20
+ type JsonSchemaComplexType = JsonSchemaObject | JsonSchemaArray | JsonSchemaRecord;
21
+ interface JsonSchemaObject extends JsonSchemaTypeBase {
22
+ type: "object";
23
+ properties: Record<string, JsonSchemaType>;
24
+ required?: string[];
25
+ additionalProperties?: boolean;
26
+ }
27
+ interface JsonSchemaRecord extends JsonSchemaTypeBase {
28
+ type: "object";
29
+ patternProperties: Record<string, JsonSchemaType>;
30
+ }
31
+ interface JsonSchemaArray extends JsonSchemaTypeBase {
32
+ type: "array";
33
+ items: JsonSchemaType;
34
+ }
35
+
36
+ interface ApplicationDef {
37
+ arriSchemaVersion: "0.0.1";
38
+ info?: {
39
+ title?: string;
40
+ description?: string;
41
+ version?: string;
42
+ };
43
+ externalDocs?: {
44
+ description?: string;
45
+ url: string;
46
+ };
47
+ procedures: Record<string, ProcedureDef>;
48
+ models: Record<string, JsonSchemaObject>;
49
+ errors: Omit<TObject, symbol>;
50
+ }
51
+ declare function normalizeWhitespace(input: string): string;
52
+ interface ProcedureDef {
53
+ path: string;
54
+ description?: string;
55
+ method: HttpMethod;
56
+ params: string | undefined;
57
+ response: string | undefined;
58
+ }
59
+ declare function isProcedureDef(input: any): input is ProcedureDef;
60
+ interface ServiceDef {
61
+ [key: string]: ProcedureDef | ServiceDef;
62
+ }
63
+ declare function isServiceDef(input: any): input is ServiceDef;
64
+ declare function isApplicationDef(input: any): input is ApplicationDef;
65
+ declare function unflattenObject(data: Record<string, any>): any;
66
+ declare function unflattenProcedures(procedures: ApplicationDef["procedures"]): Record<string, ProcedureDef | ServiceDef>;
67
+ declare function setNestedObjectProperty<T>(targetProp: string, value: T, object: Record<any, any>): Record<any, any>;
68
+ declare const removeDisallowedChars: (input: string, disallowedChars: string) => string;
69
+
70
+ interface ClientGenerator<TOptions extends Record<string, any> | undefined> {
71
+ generator: (def: ApplicationDef) => any;
72
+ options: TOptions;
73
+ }
74
+ type ClientGeneratorPlugin<TOptions extends Record<string, any> | undefined> = (options: TOptions) => ClientGenerator<TOptions>;
75
+ declare function defineClientGeneratorPlugin<TOptions extends Record<string, any> | undefined>(plugin: ClientGeneratorPlugin<TOptions>): ClientGeneratorPlugin<TOptions>;
76
+
77
+ export { type ApplicationDef as A, type ClientGeneratorPlugin as C, type HttpMethod as H, type JsonSchemaObject as J, type ProcedureDef as P, type ServiceDef as S, type ClientGenerator as a, isServiceDef as b, isApplicationDef as c, defineClientGeneratorPlugin as d, unflattenProcedures as e, isProcedureDef as i, normalizeWhitespace as n, removeDisallowedChars as r, setNestedObjectProperty as s, unflattenObject as u };
@@ -0,0 +1,77 @@
1
+ import { TObject } from '@sinclair/typebox';
2
+
3
+ declare const HttpMethodValues: readonly ["get", "post", "put", "patch", "delete", "head"];
4
+ type HttpMethod = (typeof HttpMethodValues)[number];
5
+
6
+ declare const JsonSchemaScalarTypeValues: readonly ["integer", "number", "bigint", "string", "boolean", "Date"];
7
+ declare const JsonSchemaNullTypeValues: readonly ["null", "undefined"];
8
+ type JsonSchemaType = JsonSchemaScalarType | JsonSchemaNullType | JsonSchemaComplexType;
9
+ interface JsonSchemaTypeBase {
10
+ $id?: string;
11
+ title?: string;
12
+ description?: string;
13
+ }
14
+ interface JsonSchemaScalarType extends JsonSchemaTypeBase {
15
+ type: (typeof JsonSchemaScalarTypeValues)[number];
16
+ }
17
+ interface JsonSchemaNullType extends JsonSchemaTypeBase {
18
+ type: (typeof JsonSchemaNullTypeValues)[number];
19
+ }
20
+ type JsonSchemaComplexType = JsonSchemaObject | JsonSchemaArray | JsonSchemaRecord;
21
+ interface JsonSchemaObject extends JsonSchemaTypeBase {
22
+ type: "object";
23
+ properties: Record<string, JsonSchemaType>;
24
+ required?: string[];
25
+ additionalProperties?: boolean;
26
+ }
27
+ interface JsonSchemaRecord extends JsonSchemaTypeBase {
28
+ type: "object";
29
+ patternProperties: Record<string, JsonSchemaType>;
30
+ }
31
+ interface JsonSchemaArray extends JsonSchemaTypeBase {
32
+ type: "array";
33
+ items: JsonSchemaType;
34
+ }
35
+
36
+ interface ApplicationDef {
37
+ arriSchemaVersion: "0.0.1";
38
+ info?: {
39
+ title?: string;
40
+ description?: string;
41
+ version?: string;
42
+ };
43
+ externalDocs?: {
44
+ description?: string;
45
+ url: string;
46
+ };
47
+ procedures: Record<string, ProcedureDef>;
48
+ models: Record<string, JsonSchemaObject>;
49
+ errors: Omit<TObject, symbol>;
50
+ }
51
+ declare function normalizeWhitespace(input: string): string;
52
+ interface ProcedureDef {
53
+ path: string;
54
+ description?: string;
55
+ method: HttpMethod;
56
+ params: string | undefined;
57
+ response: string | undefined;
58
+ }
59
+ declare function isProcedureDef(input: any): input is ProcedureDef;
60
+ interface ServiceDef {
61
+ [key: string]: ProcedureDef | ServiceDef;
62
+ }
63
+ declare function isServiceDef(input: any): input is ServiceDef;
64
+ declare function isApplicationDef(input: any): input is ApplicationDef;
65
+ declare function unflattenObject(data: Record<string, any>): any;
66
+ declare function unflattenProcedures(procedures: ApplicationDef["procedures"]): Record<string, ProcedureDef | ServiceDef>;
67
+ declare function setNestedObjectProperty<T>(targetProp: string, value: T, object: Record<any, any>): Record<any, any>;
68
+ declare const removeDisallowedChars: (input: string, disallowedChars: string) => string;
69
+
70
+ interface ClientGenerator<TOptions extends Record<string, any> | undefined> {
71
+ generator: (def: ApplicationDef) => any;
72
+ options: TOptions;
73
+ }
74
+ type ClientGeneratorPlugin<TOptions extends Record<string, any> | undefined> = (options: TOptions) => ClientGenerator<TOptions>;
75
+ declare function defineClientGeneratorPlugin<TOptions extends Record<string, any> | undefined>(plugin: ClientGeneratorPlugin<TOptions>): ClientGeneratorPlugin<TOptions>;
76
+
77
+ export { type ApplicationDef as A, type ClientGeneratorPlugin as C, type HttpMethod as H, type JsonSchemaObject as J, type ProcedureDef as P, type ServiceDef as S, type ClientGenerator as a, isServiceDef as b, isApplicationDef as c, defineClientGeneratorPlugin as d, unflattenProcedures as e, isProcedureDef as i, normalizeWhitespace as n, removeDisallowedChars as r, setNestedObjectProperty as s, unflattenObject as u };
@@ -0,0 +1,77 @@
1
+ import { TObject } from '@sinclair/typebox';
2
+
3
+ declare const HttpMethodValues: readonly ["get", "post", "put", "patch", "delete", "head"];
4
+ type HttpMethod = (typeof HttpMethodValues)[number];
5
+
6
+ declare const JsonSchemaScalarTypeValues: readonly ["integer", "number", "bigint", "string", "boolean", "Date"];
7
+ declare const JsonSchemaNullTypeValues: readonly ["null", "undefined"];
8
+ type JsonSchemaType = JsonSchemaScalarType | JsonSchemaNullType | JsonSchemaComplexType;
9
+ interface JsonSchemaTypeBase {
10
+ $id?: string;
11
+ title?: string;
12
+ description?: string;
13
+ }
14
+ interface JsonSchemaScalarType extends JsonSchemaTypeBase {
15
+ type: (typeof JsonSchemaScalarTypeValues)[number];
16
+ }
17
+ interface JsonSchemaNullType extends JsonSchemaTypeBase {
18
+ type: (typeof JsonSchemaNullTypeValues)[number];
19
+ }
20
+ type JsonSchemaComplexType = JsonSchemaObject | JsonSchemaArray | JsonSchemaRecord;
21
+ interface JsonSchemaObject extends JsonSchemaTypeBase {
22
+ type: "object";
23
+ properties: Record<string, JsonSchemaType>;
24
+ required?: string[];
25
+ additionalProperties?: boolean;
26
+ }
27
+ interface JsonSchemaRecord extends JsonSchemaTypeBase {
28
+ type: "object";
29
+ patternProperties: Record<string, JsonSchemaType>;
30
+ }
31
+ interface JsonSchemaArray extends JsonSchemaTypeBase {
32
+ type: "array";
33
+ items: JsonSchemaType;
34
+ }
35
+
36
+ interface ApplicationDef {
37
+ arriSchemaVersion: "0.0.1";
38
+ info?: {
39
+ title?: string;
40
+ description?: string;
41
+ version?: string;
42
+ };
43
+ externalDocs?: {
44
+ description?: string;
45
+ url: string;
46
+ };
47
+ procedures: Record<string, ProcedureDef>;
48
+ models: Record<string, JsonSchemaObject>;
49
+ errors: Omit<TObject, symbol>;
50
+ }
51
+ declare function normalizeWhitespace(input: string): string;
52
+ interface ProcedureDef {
53
+ path: string;
54
+ description?: string;
55
+ method: HttpMethod;
56
+ params: string | undefined;
57
+ response: string | undefined;
58
+ }
59
+ declare function isProcedureDef(input: any): input is ProcedureDef;
60
+ interface ServiceDef {
61
+ [key: string]: ProcedureDef | ServiceDef;
62
+ }
63
+ declare function isServiceDef(input: any): input is ServiceDef;
64
+ declare function isApplicationDef(input: any): input is ApplicationDef;
65
+ declare function unflattenObject(data: Record<string, any>): any;
66
+ declare function unflattenProcedures(procedures: ApplicationDef["procedures"]): Record<string, ProcedureDef | ServiceDef>;
67
+ declare function setNestedObjectProperty<T>(targetProp: string, value: T, object: Record<any, any>): Record<any, any>;
68
+ declare const removeDisallowedChars: (input: string, disallowedChars: string) => string;
69
+
70
+ interface ClientGenerator<TOptions extends Record<string, any> | undefined> {
71
+ generator: (def: ApplicationDef) => any;
72
+ options: TOptions;
73
+ }
74
+ type ClientGeneratorPlugin<TOptions extends Record<string, any> | undefined> = (options: TOptions) => ClientGenerator<TOptions>;
75
+ declare function defineClientGeneratorPlugin<TOptions extends Record<string, any> | undefined>(plugin: ClientGeneratorPlugin<TOptions>): ClientGeneratorPlugin<TOptions>;
76
+
77
+ export { type ApplicationDef as A, type ClientGeneratorPlugin as C, type HttpMethod as H, type JsonSchemaObject as J, type ProcedureDef as P, type ServiceDef as S, type ClientGenerator as a, isServiceDef as b, isApplicationDef as c, defineClientGeneratorPlugin as d, unflattenProcedures as e, isProcedureDef as i, normalizeWhitespace as n, removeDisallowedChars as r, setNestedObjectProperty as s, unflattenObject as u };