Skip to content

Commit 0b6159f

Browse files
Merge pull request #12 from relogiclabs/develop
Update Scripting Functionalities
2 parents 3c64922 + 51cc2cb commit 0b6159f

File tree

467 files changed

+11222
-9073
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

467 files changed

+11222
-9073
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ build/
4343
.vscode/
4444
.DS_Store
4545

46+
### Temporary Files ###
47+
/temp/**

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# JSchema - The New JSON Schema
1+
# JSchema - The Customizable JSON Schema
22
A JSON Schema is crucial for making communication, interoperability, validation, testing, documentation, and specification seamless. All of this combined contributes to better maintenance and evolution of data-driven applications and systems. If you are interested in a comprehensive overview of the roles and uses of JSON Schema in modern web applications, check out our in-depth post [here](https://www.relogiclabs.com/2023/01/the-roles-of-json-schema.html).
33

44
## Design Goals
55
The traditional standard JSON Schema rigorously follows the conventional JSON structure, which unfortunately comes at the expense of simplicity, conciseness, and readability. Our goal is to develop a new JSON Schema that promotes these essential aspects that were previously missing.
66

7-
This new schema is simple, lucid, easy to grasp, and doesn't require much prior knowledge to understand it. It also offers a shallow learning curve for both reading and writing. Additionally, its simplicity and conciseness allow us and machines to read-write more efficiently. Moreover, a large set of constraint data types and functions within the core schema promotes the precise definition of JSON documents, significantly reducing the potential for communication gaps among collaborators. Furthermore, its inherent extensibility not only facilitates the test automation process in API testing but also simplifies the integrations of new constraints and functionalities to meet the diverse requirements of modern web services.
7+
This new schema is simple, lucid, easy to grasp, and doesn't require much prior knowledge to get started. Additionally, its simplicity and conciseness allow us and machines to read-write more efficiently. Moreover, a large set of constraint data types and functions within the core schema promotes the precise definition of JSON documents, significantly reducing the potential for communication gaps among collaborators. Furthermore, its inherent extensibility not only facilitates the test automation process in API testing but also simplifies the integrations of new constraints and functionalities to meet the diverse requirements of modern web services.
88

99
## Basic Example
1010
Let's explore an example of our schema for a typical JSON API response containing information about a user profile or account. The schema is very self-explanatory and thus almost no prior knowledge is required to understand the schema and the JSON responses specified by this schema.
@@ -95,7 +95,7 @@ The next example represents an expanded version of the previous one, which bring
9595
%define $tags: @length(1, 10) #string*($tag) #array
9696
%define $tag: @length(3, 20) @regex("[A-Za-z_]+") #string
9797

98-
%schema:
98+
%schema:
9999
{
100100
"user": {
101101
"id": @range(1, 10000) #integer,
@@ -135,16 +135,16 @@ The next example represents an expanded version of the previous one, which bring
135135

136136
%script: {
137137
constraint function checkAccess(role) {
138-
// Receiver &role received only one value
138+
// Auto-unpacking unwraps single-value '&role' array into its value
139139
// 'target' keyword refers to the target JSON value
140-
if(role[0] == "user" && target > 5) return fail(
140+
if(role == "user" && target > 5) return fail(
141141
"ERRACCESS01", "Data access incompatible with 'user' role",
142142
expected("an access at most 5 for 'user' role"),
143143
actual("found access " + target + " which is greater than 5"));
144144
}
145145
}
146146
```
147-
The subsequent JSON sample is an illustrative example that successfully validates against the expanded schema mentioned earlier. Within this example, recurring JSON structures appear that can be validated by defining components or nested functions and data types. Besides, reusing simple component definitions, you can achieve a clear and concise schema when validating large JSON with repetitive structures instead of duplicating or referring to various structures across the schema. This improves the overall readability and maintainability of the schema.
147+
The subsequent JSON sample is an illustrative example that successfully validates against the expanded schema mentioned earlier. Within this example, recurring JSON structures appear that can be validated by defining components or nested functions and data types. Besides, reusing simple component definitions, you can achieve a clear and concise schema when validating large JSON with repetitive structures. This improves the overall readability and maintainability of the schema.
148148
```json
149149
{
150150
"user": {
@@ -218,10 +218,10 @@ The subsequent JSON sample is an illustrative example that successfully validate
218218
"id": "p2",
219219
"name": "Laptop",
220220
"brand": "SuperTech",
221-
"price": 1299.99,
221+
"price": 11.99,
222222
"inStock": false,
223223
"specs": {
224-
"cpu": "Ryzen 11",
224+
"cpu": "Ryzen",
225225
"ram": "11GB",
226226
"storage": "11GB SSD"
227227
}

doc/content/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ date = 2023-10-08T09:38:53+06:00
44
+++
55

66
# Introduction
7-
JSchema, a new JSON Schema, prioritizes simplicity, conciseness, and readability, making it intuitive and accessible without the need for extensive prior knowledge. It offers efficient read-write facilities, precise JSON document definition through various data types and functions, and extensibility to meet modern web service diverse requirements.
7+
JSchema, a customizable JSON Schema, prioritizes simplicity, conciseness, and readability, making it intuitive and accessible without the need for extensive prior knowledge. It offers efficient read-write facilities, precise JSON document definition through various data types and functions, and extensibility to meet modern web service diverse requirements.
88

99
JSON, short for JavaScript Object Notation, is one of the most widely used data exchange formats that are both user-friendly and machine-readable. JSchema is a practical tool for defining and validating the structure of JSON documents. The following guides provide comprehensive details about the JSchema.
1010
<br/>

doc/content/articles/cscript.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Here is a list of keywords (reserved words) in the CScript language. You cannot
1818
| Conditional Flow Control | `if`; `else`; (`switch`; `case`; `default`) |
1919
| Iterative Flow Control | `for`; `foreach`; `while`; (`do`) |
2020
| Jump Control | `break`; (`continue`) |
21-
| Membership Management | `in` |
21+
| Membership Management | `in`; (`not`) |
2222
| Function Declaration | `function`; `constraint`; `future`; `subroutine` |
2323
| Function Data & Control | `return`; `target`; `caller` |
2424
| Literals Value | `true`; `false`; `null`; `undefined` |
@@ -38,7 +38,7 @@ Composite types include `#array` and `#object`, while the remaining types fall u
3838
| 3 | `#double` | `10.5`; `20E-5`; `5E+5` |
3939
| 4 | `#integer` | `10`; `20`; `100`; `500` |
4040
| 5 | `#null` | `null` |
41-
| 6 | `#object` | `{ k1: "text", k2: { "k11" : 10 } }`; `{}` |
41+
| 6 | `#object` | `{ k1: "text", k2: { "k11" : 10 } }`; `{}` |
4242
| 7 | `#range` | `1..10`; `-10..-5`; `-10..`; `..100` |
4343
| 8 | `#string` | `"any text"`; `""` |
4444
| 9 | `#undefined` | `undefined` |
@@ -49,20 +49,20 @@ The `#void` type is reserved for internal operations, including initializing una
4949
## Operators & Precedences
5050
CScript operators are symbols that are used to perform operations on variables and values. The direct operation of any operator that requires a modifiable l-value including `++`, `--` or `=` will raise an exception for the readonly schema nodes. The following table lists the operators according to their precedences from the highest to the lowest:
5151

52-
| SN | Category | Operator |
53-
|----|-------------------------------|----------------------|
54-
| 1 | Property Access & Parentheses | `.`; `[]`; `()` |
55-
| 2 | Unary Minus & Logical Not | `-`; `!` |
56-
| 3 | Postfix Increment/Decrement | `i++`; `i--` |
57-
| 4 | Prefix Increment/Decrement | `++i`; `--i` |
58-
| 5 | Arithmetic Multiplicative | `*`; `/` |
59-
| 6 | Arithmetic Additive | `+`; `-` |
60-
| 7 | Sequence Range | `..` |
61-
| 8 | Relational Comparison | `>`; `<`; `>=`; `<=` |
62-
| 9 | Equality Comparison | `==`; `!=` |
63-
| 10 | Logical And (Short-Circuit) | `&&` |
64-
| 11 | Logical Or (Short-Circuit) | `\|\|` |
65-
| 12 | Assignment | `=` |
52+
| SN | Category | Operator |
53+
|----|-------------------------------|-----------------------------------|
54+
| 1 | Property Access & Parentheses | `.`; `[]`; `()` |
55+
| 2 | Unary Minus & Logical Not | `-`; `!` |
56+
| 3 | Postfix Increment/Decrement | `i++`; `i--` |
57+
| 4 | Prefix Increment/Decrement | `++i`; `--i` |
58+
| 5 | Arithmetic Multiplicative | `*`; `/`; `%` |
59+
| 6 | Arithmetic Additive | `+`; `-` |
60+
| 7 | Sequence Range | `..` |
61+
| 8 | Relational Comparison | `>`; `<`; `>=`; `<=` |
62+
| 9 | Equality Comparison | `==`; `!=` |
63+
| 10 | Logical And (Short-Circuit) | `&&` |
64+
| 11 | Logical Or (Short-Circuit) | `\|\|` |
65+
| 12 | Assignment | `=`; `+=`; `-=`; `*=`; `/=`; `%=` |
6666

6767
## Function Types
6868
Function types are essential for specifying the executable units that serve as the building-blocks of validation process within CScript. All function types can also accept variable number of arguments, specified by an ellipsis `...` after the last parameter name which is then bound to an array containing the remaining arguments.

doc/content/articles/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ weight = 1
55
+++
66

77
# Introduction
8-
JSchema, a new JSON Schema, prioritizes simplicity, conciseness, and readability, making it intuitive and accessible without the need for extensive prior knowledge. It offers efficient read-write facilities, precise JSON document definition through various data types and functions, and extensibility to meet modern web service diverse requirements.
8+
JSchema, a customizable JSON Schema, prioritizes simplicity, conciseness, and readability, making it intuitive and accessible without the need for extensive prior knowledge. It offers efficient read-write facilities, precise JSON document definition through various data types and functions, and extensibility to meet modern web service diverse requirements.
99

1010
JSON, short for JavaScript Object Notation, is one of the most widely used data exchange formats that are both user-friendly and machine-readable. JSchema is a practical tool for defining and validating the structure of JSON documents. The following guides provide comprehensive details about the JSchema.
1111
<br/>

doc/content/articles/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ weight = 2
88
This guide will walk you through the essential steps to quickly get up and running with the JSchema library. It is also assumed a modest familiarity with the Java language, Java SDK, and Java command-line interface, including basic familiarity with Maven packages.
99

1010
## Maven Library Package
11-
To get started, launch your preferred IDE (such as IntelliJ IDEA, NetBeans IDE, Eclipse IDE, or VS Code) and open the Java project where you intend to include this library package. If you are using a build tool like Maven or Gradle, adding the library to your project is straightforward. For example in Maven project, navigate to the Maven `pom.xml` file and locate the section named `<dependencies>` and add the following XML snippet within the section of the file, replacing `2.x.x` with either the latest version or your preferred version:
11+
To get started, launch your preferred IDE (such as IntelliJ IDEA, NetBeans IDE, Eclipse IDE, or VS Code) and open the Java project where you intend to include this library package. If you are using a build tool like Maven or Gradle, adding the library to your project is straightforward. For example in Maven project, navigate to the Maven `pom.xml` file and locate the section named `<dependencies>` and add the following XML snippet within the section, replacing `2.x.x` with either the latest version or your preferred version:
1212
```xml
1313
<dependency>
1414
<groupId>com.relogiclabs.json</groupId>

doc/content/articles/sourcebuild.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mvn clean install
2020
Maven will resolve the library's dependencies, compile the code, and create a jar file which will be installed in the local Maven repository.
2121

2222
## Add the Library to Your Project
23-
To integrate the library into your project, open it in your preferred IDE (such as IntelliJ IDEA, NetBeans IDE, Eclipse IDE, or VS Code). If you are using a build tool like Maven or Gradle, adding the library to your project is straightforward. For example in a Maven project, navigate to the Maven `pom.xml` file and locate the section named `<dependencies>` and add the following XML snippet within the section of the file, replacing `2.x.x` with the version you have built:
23+
To integrate the library into your project, open it in your preferred IDE (such as IntelliJ IDEA, NetBeans IDE, Eclipse IDE, or VS Code). If you are using a build tool like Maven or Gradle, adding the library to your project is straightforward. For example in a Maven project, navigate to the Maven `pom.xml` file and locate the section named `<dependencies>` and add the following XML snippet within the section, replacing `2.x.x` with the version you have built:
2424
```xml
2525
<dependency>
2626
<groupId>com.relogiclabs.json</groupId>

doc/content/articles/specification.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ schema
2020
validator
2121

2222
schema-header-opt
23-
title-opt version-opt includes-opt pragmas-opt
23+
title-opt version-opt imports-opt pragmas-opt
2424

2525
title-opt
2626
''
@@ -30,15 +30,15 @@ version-opt
3030
''
3131
'%version' ':' string
3232

33-
includes-opt
33+
imports-opt
3434
''
35-
includes
35+
imports
3636

37-
includes
38-
include includes
37+
imports
38+
import imports
3939

40-
include
41-
'%include' ':' class-identifier
40+
import
41+
'%import' ':' class-identifier
4242

4343
class-identifier
4444
identifier

doc/layouts/_default/baseof.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<!DOCTYPE html>
22
<html lang="{{ .Site.LanguageCode }}">
3-
{{- partial "head.html" . -}}
3+
{{ partial "head.html" . }}
44

55
<body>
6-
{{- partial "header.html" . -}}
7-
{{- partial "sidebar.html" . -}}
6+
{{ partial "header.html" . }}
7+
{{ partial "sidebar.html" . }}
88
<main>
9-
{{- block "main" . }}{{- end }}
9+
{{ block "main" . }}{{ end }}
1010
</main>
11-
{{- partial "footer.html" . -}}
11+
{{ partial "footer.html" . }}
1212
</body>
1313

1414
</html>

doc/layouts/partials/sidebar.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<div class="sidebar">
44
<ul>
55
{{ range .Site.Home.Sections.ByWeight }}
6-
<li class="section-header {{ if eq .File.UniqueID $CurrentPage.File.UniqueID }}active{{ end }}">
6+
<li class="section-header{{ if eq .Permalink $CurrentPage.Permalink }} active{{ end }}">
77
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
88
</li>
99
{{ range .Pages.ByWeight }}
10-
<li class="section-item {{ if eq .File.UniqueID $CurrentPage.File.UniqueID }}active{{ end }}">
10+
<li class="section-item{{ if eq .Permalink $CurrentPage.Permalink }} active{{ end }}">
1111
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
1212
</li>
1313
{{ end }}

0 commit comments

Comments
 (0)