@cododel/alto 0.1.4 → 0.1.6
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/default/default/extensions/filters/comment.ts +9 -0
- package/dist/default/default/extensions/filters/contains.ts +8 -0
- package/dist/default/default/extensions/filters/directus.ts +336 -0
- package/dist/default/default/extensions/filters/drop_first.ts +8 -0
- package/dist/default/default/extensions/filters/entries.ts +13 -0
- package/dist/default/default/extensions/filters/falsey.ts +17 -0
- package/dist/default/default/extensions/filters/indent.ts +6 -0
- package/dist/default/default/extensions/filters/inflections.ts +25 -0
- package/dist/default/default/extensions/filters/json.ts +10 -0
- package/dist/default/default/extensions/filters/log.ts +5 -0
- package/dist/default/default/extensions/filters/object_set.ts +11 -0
- package/dist/default/default/extensions/filters/push.ts +10 -0
- package/dist/default/default/extensions/filters/quote.ts +19 -0
- package/dist/default/default/extensions/filters/regex_replace.ts +10 -0
- package/dist/default/default/extensions/filters/splice.ts +13 -0
- package/dist/default/default/extensions/filters/split.ts +9 -0
- package/dist/default/default/extensions/filters/string_cases.ts +72 -0
- package/dist/default/default/extensions/filters/truthy.ts +17 -0
- package/dist/default/default/extensions/filters/typescript.ts +10 -0
- package/dist/default/default/extensions/filters/unshift.ts +10 -0
- package/dist/default/default/extensions/filters/wrap.ts +10 -0
- package/dist/default/default/extensions/tags/.gitkeep +0 -0
- package/dist/default/default/includes/typescript/get-field-jsdoc.liquid +11 -0
- package/dist/default/default/includes/typescript/get-field-type.liquid +121 -0
- package/dist/default/default/macros/typescript/types.njk +1 -0
- package/dist/default/default/templates/default/client.ts.njk +518 -0
- package/dist/default/default/templates/default/types.ts.njk +134 -0
- package/dist/default/extensions/filters/comment.ts +9 -0
- package/dist/default/extensions/filters/contains.ts +8 -0
- package/dist/default/extensions/filters/directus.ts +336 -0
- package/dist/default/extensions/filters/drop_first.ts +8 -0
- package/dist/default/extensions/filters/entries.ts +13 -0
- package/dist/default/extensions/filters/falsey.ts +17 -0
- package/dist/default/extensions/filters/indent.ts +6 -0
- package/dist/default/extensions/filters/inflections.ts +25 -0
- package/dist/default/extensions/filters/json.ts +10 -0
- package/dist/default/extensions/filters/log.ts +5 -0
- package/dist/default/extensions/filters/object_set.ts +11 -0
- package/dist/default/extensions/filters/push.ts +10 -0
- package/dist/default/extensions/filters/quote.ts +19 -0
- package/dist/default/extensions/filters/regex_replace.ts +10 -0
- package/dist/default/extensions/filters/splice.ts +13 -0
- package/dist/default/extensions/filters/split.ts +9 -0
- package/dist/default/extensions/filters/string_cases.ts +72 -0
- package/dist/default/extensions/filters/truthy.ts +17 -0
- package/dist/default/extensions/filters/typescript.ts +10 -0
- package/dist/default/extensions/filters/unshift.ts +10 -0
- package/dist/default/extensions/filters/wrap.ts +10 -0
- package/dist/default/extensions/tags/.gitkeep +0 -0
- package/dist/default/includes/typescript/get-field-jsdoc.liquid +11 -0
- package/dist/default/includes/typescript/get-field-type.liquid +121 -0
- package/dist/default/macros/typescript/types.njk +1 -0
- package/dist/default/templates/default/client.ts.njk +518 -0
- package/dist/default/templates/default/types.ts.njk +134 -0
- package/dist/index.js +757 -740
- package/package.json +13 -9
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { TemplateContext } from "../../../types/template";
|
|
2
|
+
|
|
3
|
+
function stringifyFirst(fn: (...args: any[]) => any) {
|
|
4
|
+
return (_context: TemplateContext, first: any, ...args: any[]) => {
|
|
5
|
+
return fn(`${first}`, ...args).toString();
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const lower_case = stringifyFirst(toLower);
|
|
10
|
+
export const pascal_case = stringifyFirst(toPascal);
|
|
11
|
+
export const space_case = stringifyFirst(toSpace);
|
|
12
|
+
export const camel_case = stringifyFirst(toCamel);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Converts a string to lower case.
|
|
16
|
+
* Example: "HelloWorld" -> "hello world"
|
|
17
|
+
* @param {string} str - The input string.
|
|
18
|
+
* @returns {string} The lowercased string.
|
|
19
|
+
* @throws {Error} If the argument is not a string.
|
|
20
|
+
*/
|
|
21
|
+
export function toLower(str: string) {
|
|
22
|
+
if (typeof str !== "string") {
|
|
23
|
+
throw new Error("Argument must be a string");
|
|
24
|
+
}
|
|
25
|
+
return str.toLowerCase();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Converts a string to space case.
|
|
30
|
+
* Example: "HelloWorld" -> "hello world"
|
|
31
|
+
* @param {string} str - The input string.
|
|
32
|
+
* @returns {string} The spacecased string.
|
|
33
|
+
* @throws {Error} If the argument is not a string.
|
|
34
|
+
*/
|
|
35
|
+
export function toSpace(str: string) {
|
|
36
|
+
if (typeof str !== "string") {
|
|
37
|
+
throw new Error("Argument must be a string");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return str
|
|
41
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
42
|
+
.replace(/[\-_]+/g, " ")
|
|
43
|
+
.replace(/\s+/g, " ")
|
|
44
|
+
.trim()
|
|
45
|
+
.toLowerCase();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Converts a string to PascalCase.
|
|
50
|
+
* Example: "hello world" -> "HelloWorld"
|
|
51
|
+
* @param {string} str - The input string.
|
|
52
|
+
* @returns {string} The Pascalcased string.
|
|
53
|
+
* @throws {Error} If the argument is not a string.
|
|
54
|
+
*/
|
|
55
|
+
export function toPascal(str: string): string {
|
|
56
|
+
return str
|
|
57
|
+
.split(/[-_\s]+/)
|
|
58
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
59
|
+
.join("");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Converts a string to camelCase.
|
|
64
|
+
* Example: "HelloWorld" -> "helloWorld"
|
|
65
|
+
* @param {string} str - The input string.
|
|
66
|
+
* @returns {string} The camelcased string.
|
|
67
|
+
* @throws {Error} If the argument is not a string.
|
|
68
|
+
*/
|
|
69
|
+
export function toCamel(str: string): string {
|
|
70
|
+
const pascal = toPascal(str);
|
|
71
|
+
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
72
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TemplateContext } from "../../../types/template";
|
|
2
|
+
|
|
3
|
+
export function truthy(
|
|
4
|
+
context: TemplateContext,
|
|
5
|
+
condition: boolean,
|
|
6
|
+
truthy: any,
|
|
7
|
+
falsey: any,
|
|
8
|
+
) {
|
|
9
|
+
if (condition) {
|
|
10
|
+
return truthy;
|
|
11
|
+
} else {
|
|
12
|
+
if (typeof falsey != "undefined") {
|
|
13
|
+
return falsey;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return condition;
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TemplateContext } from "../../../types/template";
|
|
2
|
+
|
|
3
|
+
export function to_ts_identifier(context: TemplateContext, identifier: string) {
|
|
4
|
+
identifier = `${identifier}`;
|
|
5
|
+
if (/^[_a-z]\w*$/i.test(identifier)) {
|
|
6
|
+
return identifier;
|
|
7
|
+
} else {
|
|
8
|
+
return `["${identifier.replace('"', '\\"')}"]`;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{%- capture output %}
|
|
2
|
+
/**
|
|
3
|
+
* The `{{ field.name }}` field.
|
|
4
|
+
{%- if field.type.default_value != null %}
|
|
5
|
+
* @default {{ '{' -}}
|
|
6
|
+
{{- field.type.default_value | json -}}
|
|
7
|
+
{{- '}' }}
|
|
8
|
+
{%- endif %}
|
|
9
|
+
*/
|
|
10
|
+
{%- endcapture %}
|
|
11
|
+
{{- output | indent: prefix }}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
{%- liquid
|
|
2
|
+
assign types = []
|
|
3
|
+
assign schema = field.type.raw.schema
|
|
4
|
+
assign meta = field.type.raw.meta
|
|
5
|
+
assign nullable = false
|
|
6
|
+
|
|
7
|
+
assign is_json = false
|
|
8
|
+
case schema.data_type
|
|
9
|
+
when 'uuid'
|
|
10
|
+
assign types = types | array_unshift: 'UUID'
|
|
11
|
+
when 'json'
|
|
12
|
+
assign is_json = true
|
|
13
|
+
when 'text'
|
|
14
|
+
assign types = types | array_unshift: 'string'
|
|
15
|
+
when 'integer'
|
|
16
|
+
assign types = types | array_unshift: 'number'
|
|
17
|
+
when 'bigint'
|
|
18
|
+
assign types = types | array_unshift: 'BigInt'
|
|
19
|
+
when 'boolean'
|
|
20
|
+
assign types = types | array_unshift: 'boolean'
|
|
21
|
+
when 'character varying'
|
|
22
|
+
assign types = types | array_unshift: 'string'
|
|
23
|
+
when 'timestamp':
|
|
24
|
+
assign types = types | array_unshift: 'Date'
|
|
25
|
+
when 'timestamp with time zone':
|
|
26
|
+
assign types = types | array_unshift: 'Date'
|
|
27
|
+
when 'timestamp without time zone':
|
|
28
|
+
assign types = types | array_unshift: 'Date'
|
|
29
|
+
endcase
|
|
30
|
+
|
|
31
|
+
assign json_type = false
|
|
32
|
+
assign is_cast_json = meta.special | array_contains: "cast-json"
|
|
33
|
+
if is_cast_json or is_json
|
|
34
|
+
if schema.json_schema != null
|
|
35
|
+
assign json_type = '"json_schema"'
|
|
36
|
+
else
|
|
37
|
+
assign json_type = 'any'
|
|
38
|
+
endif
|
|
39
|
+
endif
|
|
40
|
+
|
|
41
|
+
case meta.interface
|
|
42
|
+
when 'tags'
|
|
43
|
+
assign types = types | array_unshift: 'string[]'
|
|
44
|
+
when 'select-dropdown'
|
|
45
|
+
assign values = meta.options.choices | map: 'value' | quote
|
|
46
|
+
for value in values
|
|
47
|
+
if value == null
|
|
48
|
+
# assign types = types | array_unshift: 'null'
|
|
49
|
+
assign nullable = true
|
|
50
|
+
else
|
|
51
|
+
assign types = types | array_unshift: value
|
|
52
|
+
endif
|
|
53
|
+
endfor
|
|
54
|
+
assign json_type = false
|
|
55
|
+
endcase
|
|
56
|
+
|
|
57
|
+
if schema.is_nullable
|
|
58
|
+
# assign types = types | array_push: 'null'
|
|
59
|
+
assign nullable = true
|
|
60
|
+
endif
|
|
61
|
+
if json_type != false
|
|
62
|
+
assign types = types | array_unshift: json_type
|
|
63
|
+
endif
|
|
64
|
+
|
|
65
|
+
assign is_user = meta.special | array_contains: "user-created"
|
|
66
|
+
if is_user
|
|
67
|
+
assign types = types | array_push: "Directus.DirectusUser<Schema>"
|
|
68
|
+
endif
|
|
69
|
+
|
|
70
|
+
assign is_user = meta.special | array_contains: "user-updated"
|
|
71
|
+
if is_user
|
|
72
|
+
assign types = types | array_push: "Directus.DirectusUser<Schema>"
|
|
73
|
+
endif
|
|
74
|
+
|
|
75
|
+
assign is_file = meta.special | array_contains: "file"
|
|
76
|
+
if is_file
|
|
77
|
+
assign types = types | array_push: "Directus.DirectusFile<Schema>"
|
|
78
|
+
endif
|
|
79
|
+
|
|
80
|
+
assign is_files = meta.special | array_contains: "files"
|
|
81
|
+
if is_files
|
|
82
|
+
assign types = types | array_push: "Directus.DirectusFile<Schema>[]"
|
|
83
|
+
endif
|
|
84
|
+
|
|
85
|
+
if field.is_translations
|
|
86
|
+
assign types = types | array_push: field.translations_collection
|
|
87
|
+
endif
|
|
88
|
+
|
|
89
|
+
if field.type.is_relationship
|
|
90
|
+
if field.type.relationship.type == 'o2m'
|
|
91
|
+
assign types = types | array_push: "CARALHO1"
|
|
92
|
+
endif
|
|
93
|
+
if field.type.relationship.type == 'm2o'
|
|
94
|
+
assign types = types | array_push: "CARALHO2"
|
|
95
|
+
endif
|
|
96
|
+
if field.type.relationship.type == 'a2o'
|
|
97
|
+
assign types = types | array_push: "CARALHO3"
|
|
98
|
+
endif
|
|
99
|
+
endif
|
|
100
|
+
|
|
101
|
+
assign type_count = types | array_length
|
|
102
|
+
if type_count <= 0
|
|
103
|
+
assign schemaStr = schema | json
|
|
104
|
+
assign metaStr = meta | json
|
|
105
|
+
assign unknown = "UnknownType<{ schema: " | append: schemaStr | append: ", meta: " | append: metaStr | append: " }>"
|
|
106
|
+
assign types = types | array_unshift: unknown
|
|
107
|
+
endif
|
|
108
|
+
|
|
109
|
+
assign output = ""
|
|
110
|
+
assign is_no_data = meta.special | array_contains: "no-data"
|
|
111
|
+
if is_no_data
|
|
112
|
+
assign output = "never"
|
|
113
|
+
else
|
|
114
|
+
assign output = types | join: ' | '
|
|
115
|
+
if nullable
|
|
116
|
+
assign output = output | wrap: 'Optional<', '>'
|
|
117
|
+
endif
|
|
118
|
+
endif
|
|
119
|
+
|
|
120
|
+
echo output
|
|
121
|
+
-%}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|