Skip to content

Commit 9c517cf

Browse files
committed
chore: sync latest doc to v0.5.4 and v0.5.5
1 parent 4f5b143 commit 9c517cf

File tree

11 files changed

+197
-9
lines changed

11 files changed

+197
-9
lines changed

docs/user_docs/guides/package-management/4-share_your_pkg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Share Your Package
1+
# Share Your Package to ghcr.io
22

33
[kpm](https://github.com/kcl-lang/kpm) is a tool for managing kcl packages. This article will guide you on how to use kpm to push your kcl package to an OCI Registry for publication. kpm uses [ghcr.io](https://ghcr.io) as the default OCI Registry, and you can change the default OCI Registry by modifying the kpm configuration file. For information on how to modify the kpm configuration file, see [kpm oci registry](https://github.com/kcl-lang/kpm/blob/main/docs/kpm_oci.md#kpm-registry)
44

i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/package-management/4-share_your_pkg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 分享您的 kcl 包
1+
# 发布 KCL 包到 ghcr.io
22

33
[kpm](https://github.com/kcl-lang/kpm) 是一个用于管理 kcl 包的工具。本文将指导您如何使用 kpm 将您的 kcl 包推送到发布到 OCI Registry 中。kpm 默认使用 [ghcr.io](https://ghcr.io) 作为 OCI Registry, 您可以通过修改 kpm 配置文件来更改默认的 OCI Registry。关于如何修改 kpm 配置文件的信息,请参阅 [kpm oci registry](https://github.com/kcl-lang/kpm/blob/main/docs/kpm_oci-zh.md#kpm-registry)
44

i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/package-management/5-share_your_pkg_docker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 分享您的包到 docker.io
1+
# 发布 KCL 包到 docker.io
22

33
[kpm](https://github.com/KusionStack/kpm) 是一个用于管理 kcl 包的工具。本文将指导您如何使用 kpm 将您的 kcl 包推送到发布到 docker.io 中。
44

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# 类型和定义
2+
3+
This section mainly covers the concepts related to types and definitions.
4+
5+
## 类型
6+
7+
KCL features a **gradual static type system**, initially designed to consider scalability. Its aim is to significantly reduce the configuration writing difficulties for users while maintaining stability. Static typing enhances code quality, acts as documentation, and helps detect errors at an early stage when needed. For instance, defining a complete static type for data like JSON/YAML can be challenging, similar to how TypeScript adds complexity in handling type gymnastics due to the lack of runtime type checks for Javascript. In contrast, KCL incorporates a similar TypeScript type system while still retaining runtime type checks. Thus, type errors will always appear at runtime. Consequently, KCL has types, but they can be selectively used when necessary, and it handles interactions between typed and untyped code elegantly and securely.
8+
9+
The configuration of attributes and types in KCL usually follows a simple pattern:
10+
11+
$$
12+
k = (T) v
13+
$$
14+
15+
where $k$ is the attribute name, $v$ is the attributes value, and $T$ is the type annotation. Since KCL has the ability of the type inference, $T$ is usually omitted.
16+
17+
By default, KCL does not require type annotations and performs type checks at runtime.
18+
19+
```python
20+
name = "ngnix" # The type of `name` is `str`
21+
port = 80 # The type of `port` is `int`
22+
```
23+
24+
As long as we operate on basic types such as integers and strings, it is generally sufficient to annotate the default type and directly write the configuration. KCL can infer the type of basic data. We recommend writing types for complex structures and function definitions, which will clearly provide a good input prompt for other users who use structures and functions.
25+
26+
```python
27+
# Types for schema
28+
schema App:
29+
name: str
30+
domainType: "Standard" | "Customized" | "Global"
31+
containerPort: int
32+
volumes: [Volume]
33+
services: [Service]
34+
35+
check:
36+
1 <= containerPort <= 65535
37+
38+
schema Service:
39+
clusterIP: str
40+
$type: str
41+
42+
check:
43+
clusterIP == "None" if $type == "ClusterIP"
44+
45+
schema Volume:
46+
container: str = "*" # The default value of `container` is "*"
47+
mountPath: str
48+
49+
check:
50+
mountPath not in ["/", "/boot", "/home", "dev", "/etc", "/root"]
51+
52+
# Types for lambda
53+
appFilterFunc = lambda apps: [App], name: str -> [App] {
54+
[a for a in apps if a.name == name]
55+
}
56+
```
57+
58+
More formal definitions and usage of types are at the [type specification document](/docs/reference/lang/types/) and the [tour document of the type system](/docs/reference/lang/tour#type-system)
59+
60+
**Schema** is the core type in KCL, just like a database schema, which defines the organization of configuration data. This includes logical constraints such as schema names, fields, data types, and the relationships between these entities. Patterns typically use visual representations to convey the architecture of a database, becoming the foundation for organizing configuration data. The process of designing schema patterns is also known as configuration modeling. KCL Schema typically serves various roles, such as application developers, DevOps platform administrators, and SRE, and provides them with a unified configuration interaction interface.
61+
62+
In addition, the ability to enforce constraints from top to bottom is crucial for any large-scale configuration setting. Therefore, KCL not only provides the ability to define static types but also provides the rich ability to define constraints, which is to some extent equivalent to assertion statements in programming languages. To prevent assertions from constantly expanding, we place structural constraints together with structural type definitions and support custom error messages.
63+
64+
In KCL, we can use schema to organize the configuration data to meet the requirements of model definition, abstraction, and templating. Schema is the core feature of KCL, which defines attributes, operations, and check-blocks. Usually, a formal form of KCL Schema can be written in the following form:
65+
66+
$$
67+
S = \Sigma_{i = 1}^{N} \{s_i, T_i, \mathcal{T}[s_i]\},
68+
$$
69+
70+
where $N$ is the total number of attributes, $\mathcal{T}$ is the attribute constraint, $s_i$ and $T_i$ denotes the $i$-th attribute name and type. Simultaneously, to improve the reusability of the code and meet the needs of hierarchical definition, KCL draws on the experience of OOP and uses single inheritance to reuse and extend the schema. Schema inheritance can be regarded as a special type of partial order relationship, and satisfies
71+
72+
$$
73+
unionof(T_1, T_2) = T_2 \Leftrightarrow T_1 \subseteq T_2,
74+
$$
75+
76+
where $T_1$ and $T_2$ are both schema types. When the above equation is not satisfied, the KCL will throw a type check error.
77+
78+
A typical schema with constraints is defined as follows:
79+
80+
```python
81+
import regex
82+
83+
schema Secret:
84+
name: str
85+
# Data defines the keys and data that will be used by secret.
86+
data?: {str:str}
87+
88+
check:
89+
all k in data {
90+
regex.match(k, r"[A-Za-z0-9_.-]*")
91+
} if data, "a valid secret data key must consist of alphanumeric characters, '-', '_' or '.'"
92+
```
93+
94+
More specifications and usage of KCL schema and constraint is [here](/docs/reference/lang/spec/schema).

i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.4/user_docs/guides/package-management/4-share_your_pkg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 分享您的 kcl 包
1+
# 发布 KCL 包到 ghcr.io
22

33
[kpm](https://github.com/kcl-lang/kpm) 是一个用于管理 kcl 包的工具。本文将指导您如何使用 kpm 将您的 kcl 包推送到发布到 OCI Registry 中。kpm 默认使用 [ghcr.io](https://ghcr.io) 作为 OCI Registry, 您可以通过修改 kpm 配置文件来更改默认的 OCI Registry。关于如何修改 kpm 配置文件的信息,请参阅 [kpm oci registry](https://github.com/kcl-lang/kpm/blob/main/docs/kpm_oci-zh.md#kpm-registry)
44

i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.4/user_docs/guides/package-management/5-share_your_pkg_docker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 分享您的包到 docker.io
1+
# 发布 KCL 包到 docker.io
22

33
[kpm](https://github.com/KusionStack/kpm) 是一个用于管理 kcl 包的工具。本文将指导您如何使用 kpm 将您的 kcl 包推送到发布到 docker.io 中。
44

i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.5/user_docs/guides/package-management/4-share_your_pkg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 分享您的 kcl 包
1+
# 发布 KCL 包到 ghcr.io
22

33
[kpm](https://github.com/kcl-lang/kpm) 是一个用于管理 kcl 包的工具。本文将指导您如何使用 kpm 将您的 kcl 包推送到发布到 OCI Registry 中。kpm 默认使用 [ghcr.io](https://ghcr.io) 作为 OCI Registry, 您可以通过修改 kpm 配置文件来更改默认的 OCI Registry。关于如何修改 kpm 配置文件的信息,请参阅 [kpm oci registry](https://github.com/kcl-lang/kpm/blob/main/docs/kpm_oci-zh.md#kpm-registry)
44

i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.5/user_docs/guides/package-management/5-share_your_pkg_docker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 分享您的包到 docker.io
1+
# 发布 KCL 包到 docker.io
22

33
[kpm](https://github.com/KusionStack/kpm) 是一个用于管理 kcl 包的工具。本文将指导您如何使用 kpm 将您的 kcl 包推送到发布到 docker.io 中。
44

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Type and Definition
2+
3+
This section mainly covers the concepts related to types and definitions.
4+
5+
## Type
6+
7+
KCL features a **gradual static type system**, initially designed to consider scalability. Its aim is to significantly reduce the configuration writing difficulties for users while maintaining stability. Static typing enhances code quality, acts as documentation, and helps detect errors at an early stage when needed. For instance, defining a complete static type for data like JSON/YAML can be challenging, similar to how TypeScript adds complexity in handling type gymnastics due to the lack of runtime type checks for Javascript. In contrast, KCL incorporates a similar TypeScript type system while still retaining runtime type checks. Thus, type errors will always appear at runtime. Consequently, KCL has types, but they can be selectively used when necessary, and it handles interactions between typed and untyped code elegantly and securely.
8+
9+
The configuration of attributes and types in KCL usually follows a simple pattern:
10+
11+
$$
12+
k = (T) v
13+
$$
14+
15+
where $k$ is the attribute name, $v$ is the attributes value, and $T$ is the type annotation. Since KCL has the ability of the type inference, $T$ is usually omitted.
16+
17+
By default, KCL does not require type annotations and performs type checks at runtime.
18+
19+
```python
20+
name = "ngnix" # The type of `name` is `str`
21+
port = 80 # The type of `port` is `int`
22+
```
23+
24+
As long as we operate on basic types such as integers and strings, it is generally sufficient to annotate the default type and directly write the configuration. KCL can infer the type of basic data. We recommend writing types for complex structures and function definitions, which will clearly provide a good input prompt for other users who use structures and functions.
25+
26+
```python
27+
# Types for schema
28+
schema App:
29+
name: str
30+
domainType: "Standard" | "Customized" | "Global"
31+
containerPort: int
32+
volumes: [Volume]
33+
services: [Service]
34+
35+
check:
36+
1 <= containerPort <= 65535
37+
38+
schema Service:
39+
clusterIP: str
40+
$type: str
41+
42+
check:
43+
clusterIP == "None" if $type == "ClusterIP"
44+
45+
schema Volume:
46+
container: str = "*" # The default value of `container` is "*"
47+
mountPath: str
48+
49+
check:
50+
mountPath not in ["/", "/boot", "/home", "dev", "/etc", "/root"]
51+
52+
# Types for lambda
53+
appFilterFunc = lambda apps: [App], name: str -> [App] {
54+
[a for a in apps if a.name == name]
55+
}
56+
```
57+
58+
More formal definitions and usage of types are at the [type specification document](/docs/reference/lang/types/) and the [tour document of the type system](/docs/reference/lang/tour#type-system)
59+
60+
**Schema** is the core type in KCL, just like a database schema, which defines the organization of configuration data. This includes logical constraints such as schema names, fields, data types, and the relationships between these entities. Patterns typically use visual representations to convey the architecture of a database, becoming the foundation for organizing configuration data. The process of designing schema patterns is also known as configuration modeling. KCL Schema typically serves various roles, such as application developers, DevOps platform administrators, and SRE, and provides them with a unified configuration interaction interface.
61+
62+
In addition, the ability to enforce constraints from top to bottom is crucial for any large-scale configuration setting. Therefore, KCL not only provides the ability to define static types but also provides the rich ability to define constraints, which is to some extent equivalent to assertion statements in programming languages. To prevent assertions from constantly expanding, we place structural constraints together with structural type definitions and support custom error messages.
63+
64+
In KCL, we can use schema to organize the configuration data to meet the requirements of model definition, abstraction, and templating. Schema is the core feature of KCL, which defines attributes, operations, and check-blocks. Usually, a formal form of KCL Schema can be written in the following form:
65+
66+
$$
67+
S = \Sigma_{i = 1}^{N} \{s_i, T_i, \mathcal{T}[s_i]\},
68+
$$
69+
70+
where $N$ is the total number of attributes, $\mathcal{T}$ is the attribute constraint, $s_i$ and $T_i$ denotes the $i$-th attribute name and type. Simultaneously, to improve the reusability of the code and meet the needs of hierarchical definition, KCL draws on the experience of OOP and uses single inheritance to reuse and extend the schema. Schema inheritance can be regarded as a special type of partial order relationship, and satisfies
71+
72+
$$
73+
unionof(T_1, T_2) = T_2 \Leftrightarrow T_1 \subseteq T_2,
74+
$$
75+
76+
where $T_1$ and $T_2$ are both schema types. When the above equation is not satisfied, the KCL will throw a type check error.
77+
78+
A typical schema with constraints is defined as follows:
79+
80+
```python
81+
import regex
82+
83+
schema Secret:
84+
name: str
85+
# Data defines the keys and data that will be used by secret.
86+
data?: {str:str}
87+
88+
check:
89+
all k in data {
90+
regex.match(k, r"[A-Za-z0-9_.-]*")
91+
} if data, "a valid secret data key must consist of alphanumeric characters, '-', '_' or '.'"
92+
```
93+
94+
More specifications and usage of KCL schema and constraint is [here](/docs/reference/lang/spec/schema).

versioned_docs/version-0.5.4/user_docs/guides/package-management/4-share_your_pkg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Share Your Package
1+
# Share Your Package to ghcr.io
22

33
[kpm](https://github.com/kcl-lang/kpm) is a tool for managing kcl packages. This article will guide you on how to use kpm to push your kcl package to an OCI Registry for publication. kpm uses [ghcr.io](https://ghcr.io) as the default OCI Registry, and you can change the default OCI Registry by modifying the kpm configuration file. For information on how to modify the kpm configuration file, see [kpm oci registry](https://github.com/kcl-lang/kpm/blob/main/docs/kpm_oci.md#kpm-registry)
44

0 commit comments

Comments
 (0)