@jondotsoy/don 0.0.2 → 0.0.5
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/LICENSE +21 -0
- package/README.md +72 -373
- package/lib/esm/don.d.ts +10 -0
- package/lib/esm/don.d.ts.map +1 -0
- package/lib/esm/don.js +27 -0
- package/lib/esm/don.js.map +1 -0
- package/lib/esm/index.d.ts +1 -2
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +2 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/v1/__utils__/key-syntax-kind.d.ts +2 -0
- package/lib/esm/v1/__utils__/key-syntax-kind.d.ts.map +1 -0
- package/lib/esm/v1/__utils__/key-syntax-kind.js +23 -0
- package/lib/esm/v1/__utils__/key-syntax-kind.js.map +1 -0
- package/lib/esm/v1/__utils__/normalize.d.ts +3 -0
- package/lib/esm/v1/__utils__/normalize.d.ts.map +1 -0
- package/lib/esm/v1/__utils__/normalize.js +10 -0
- package/lib/esm/v1/__utils__/normalize.js.map +1 -0
- package/lib/esm/v1/__utils__/t.d.ts +15 -0
- package/lib/esm/v1/__utils__/t.d.ts.map +1 -0
- package/lib/esm/v1/__utils__/t.js +32 -0
- package/lib/esm/v1/__utils__/t.js.map +1 -0
- package/lib/esm/v1/__utils__/to-token-snapshot.d.ts +7 -0
- package/lib/esm/v1/__utils__/to-token-snapshot.d.ts.map +1 -0
- package/lib/esm/v1/__utils__/to-token-snapshot.js +162 -0
- package/lib/esm/v1/__utils__/to-token-snapshot.js.map +1 -0
- package/lib/esm/v1/compiler/directive-node.d.ts +26 -0
- package/lib/esm/v1/compiler/directive-node.d.ts.map +1 -0
- package/lib/esm/v1/compiler/directive-node.js +48 -0
- package/lib/esm/v1/compiler/directive-node.js.map +1 -0
- package/lib/esm/v1/compiler/lexema-encode.d.ts +15 -0
- package/lib/esm/v1/compiler/lexema-encode.d.ts.map +1 -0
- package/lib/esm/v1/compiler/lexema-encode.js +22 -0
- package/lib/esm/v1/compiler/lexema-encode.js.map +1 -0
- package/lib/esm/v1/compiler/lexema.d.ts +10 -0
- package/lib/esm/v1/compiler/lexema.d.ts.map +1 -0
- package/lib/esm/v1/compiler/lexema.js +26 -0
- package/lib/esm/v1/compiler/lexema.js.map +1 -0
- package/lib/esm/v1/compiler/part-set-encode.d.ts +6 -0
- package/lib/esm/v1/compiler/part-set-encode.d.ts.map +1 -0
- package/lib/esm/v1/compiler/part-set-encode.js +15 -0
- package/lib/esm/v1/compiler/part-set-encode.js.map +1 -0
- package/lib/esm/v1/compiler/part-set.d.ts +6 -0
- package/lib/esm/v1/compiler/part-set.d.ts.map +1 -0
- package/lib/esm/v1/compiler/part-set.js +7 -0
- package/lib/esm/v1/compiler/part-set.js.map +1 -0
- package/lib/esm/v1/compiler/part.d.ts +31 -0
- package/lib/esm/v1/compiler/part.d.ts.map +1 -0
- package/lib/esm/v1/compiler/part.js +109 -0
- package/lib/esm/v1/compiler/part.js.map +1 -0
- package/lib/esm/v1/compiler/partial-span.d.ts +6 -0
- package/lib/esm/v1/compiler/partial-span.d.ts.map +1 -0
- package/lib/esm/v1/compiler/partial-span.js +9 -0
- package/lib/esm/v1/compiler/partial-span.js.map +1 -0
- package/lib/esm/v1/compiler/span.d.ts +9 -0
- package/lib/esm/v1/compiler/span.d.ts.map +1 -0
- package/lib/esm/v1/compiler/span.js +13 -0
- package/lib/esm/v1/compiler/span.js.map +1 -0
- package/lib/esm/v1/compiler/syntax-encode.d.ts +9 -0
- package/lib/esm/v1/compiler/syntax-encode.d.ts.map +1 -0
- package/lib/esm/v1/compiler/syntax-encode.js +160 -0
- package/lib/esm/v1/compiler/syntax-encode.js.map +1 -0
- package/lib/esm/v1/compiler/token.d.ts +59 -0
- package/lib/esm/v1/compiler/token.d.ts.map +1 -0
- package/lib/esm/v1/compiler/token.js +320 -0
- package/lib/esm/v1/compiler/token.js.map +1 -0
- package/lib/esm/v1/types/location.d.ts +6 -0
- package/lib/esm/v1/types/location.d.ts.map +1 -0
- package/lib/esm/v1/types/location.js +2 -0
- package/lib/esm/v1/types/location.js.map +1 -0
- package/lib/esm/v1/types/u8.d.ts +2 -0
- package/lib/esm/v1/types/u8.d.ts.map +1 -0
- package/lib/esm/v1/types/u8.js +2 -0
- package/lib/esm/v1/types/u8.js.map +1 -0
- package/lib/esm/v1/utils/build-logger.d.ts +11 -0
- package/lib/esm/v1/utils/build-logger.d.ts.map +1 -0
- package/lib/esm/v1/utils/build-logger.js +20 -0
- package/lib/esm/v1/utils/build-logger.js.map +1 -0
- package/lib/esm/v1/utils/charset-tools.d.ts +15 -0
- package/lib/esm/v1/utils/charset-tools.d.ts.map +1 -0
- package/lib/esm/v1/utils/charset-tools.js +37 -0
- package/lib/esm/v1/utils/charset-tools.js.map +1 -0
- package/lib/esm/v1/utils/charset.d.ts +34 -0
- package/lib/esm/v1/utils/charset.d.ts.map +1 -0
- package/lib/esm/v1/utils/charset.js +52 -0
- package/lib/esm/v1/utils/charset.js.map +1 -0
- package/lib/esm/v1/utils/parts-match.d.ts +12 -0
- package/lib/esm/v1/utils/parts-match.d.ts.map +1 -0
- package/lib/esm/v1/utils/parts-match.js +30 -0
- package/lib/esm/v1/utils/parts-match.js.map +1 -0
- package/lib/esm/v1/utils/syntax-kind.d.ts +22 -0
- package/lib/esm/v1/utils/syntax-kind.d.ts.map +1 -0
- package/lib/esm/v1/utils/syntax-kind.js +28 -0
- package/lib/esm/v1/utils/syntax-kind.js.map +1 -0
- package/lib/esm/v1/utils/take-while.d.ts +53 -0
- package/lib/esm/v1/utils/take-while.d.ts.map +1 -0
- package/lib/esm/v1/utils/take-while.js +69 -0
- package/lib/esm/v1/utils/take-while.js.map +1 -0
- package/package.json +5 -1
- package/lib/esm/chunk.d.ts +0 -28
- package/lib/esm/chunk.d.ts.map +0 -1
- package/lib/esm/chunk.js +0 -84
- package/lib/esm/chunk.js.map +0 -1
- package/lib/esm/document.d.ts +0 -20
- package/lib/esm/document.d.ts.map +0 -1
- package/lib/esm/document.js +0 -138
- package/lib/esm/document.js.map +0 -1
- package/lib/esm/lexer.d.ts +0 -38
- package/lib/esm/lexer.d.ts.map +0 -1
- package/lib/esm/lexer.js +0 -600
- package/lib/esm/lexer.js.map +0 -1
- package/lib/esm/utils/inspect.d.ts +0 -7
- package/lib/esm/utils/inspect.d.ts.map +0 -1
- package/lib/esm/utils/inspect.js +0 -39
- package/lib/esm/utils/inspect.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jonathan Delgado <hi@jon.soy> (https://jon.soy)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,416 +1,115 @@
|
|
|
1
1
|
# DON: Directive Object Notation
|
|
2
2
|
|
|
3
|
-
DON
|
|
3
|
+
DON is a human-readable data serialization format designed around the concept of directives and subdirectives. It combines the simplicity of declarative syntax with the flexibility of nested structures, allowing you to define hierarchical configurations using intuitive directive blocks. Each directive can accept arguments and contain nested subdirectives, making it ideal for configuration files, infrastructure definitions, and structured data representation where readability and expressiveness are priorities.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
- **
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
7
|
+
- **Minimal Syntax**: Fewer special characters, more readability
|
|
8
|
+
- **Sequential Processing**: Directives are processed as a pipeline, allowing overwriting and incremental composition
|
|
9
|
+
- **Flexible Nesting**: Supports hierarchies of any depth
|
|
10
|
+
- **Multiple Data Types**: Keywords, strings, numbers, booleans, and null
|
|
11
|
+
- **Heredoc Support**: Multi-line content blocks for embedded scripts and text
|
|
12
|
+
- **Comments**: Supports line comments (`//`, `#`) and multi-line comments (`/* */`)
|
|
13
|
+
- **Unambiguous**: Clear parsing rules and delimitation
|
|
13
14
|
|
|
14
|
-
##
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
### Using npm
|
|
15
18
|
|
|
16
19
|
```bash
|
|
17
20
|
npm install @jondotsoy/don
|
|
18
21
|
```
|
|
19
22
|
|
|
23
|
+
### Using Bun
|
|
24
|
+
|
|
20
25
|
```bash
|
|
21
26
|
bun add @jondotsoy/don
|
|
22
27
|
```
|
|
23
28
|
|
|
24
|
-
##
|
|
25
|
-
|
|
26
|
-
```typescript
|
|
27
|
-
import { DocumentEncoder, LexerEncoder } from "@jondotsoy/don";
|
|
28
|
-
|
|
29
|
-
// Parsear un documento DON
|
|
30
|
-
const source = `
|
|
31
|
-
name "my-app"
|
|
32
|
-
version 1.0.0
|
|
33
|
-
container {
|
|
34
|
-
image "nginx"
|
|
35
|
-
port 8080
|
|
36
|
-
}
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
const lexer = new LexerEncoder();
|
|
40
|
-
const tokens = lexer.encode(source);
|
|
41
|
-
|
|
42
|
-
const document = new DocumentEncoder();
|
|
43
|
-
const directives = document.encode(tokens);
|
|
44
|
-
|
|
45
|
-
console.log(directives);
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Sintaxis Básica
|
|
49
|
-
|
|
50
|
-
### Estructura de una Directiva
|
|
51
|
-
|
|
52
|
-
Una directiva tiene la siguiente estructura:
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
<nombre> [argumentos...] [{ subdirectivas }]
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
**Componentes:**
|
|
59
|
-
|
|
60
|
-
- **Nombre**: Identificador de la directiva (keyword, string, number o boolean)
|
|
61
|
-
- **Argumentos**: Cero o más valores separados por espacios
|
|
62
|
-
- **Bloque**: Opcional, contiene subdirectivas entre llaves `{ }`
|
|
63
|
-
|
|
64
|
-
### Ejemplos
|
|
65
|
-
|
|
66
|
-
**Directivas simples:**
|
|
67
|
-
|
|
68
|
-
```don
|
|
69
|
-
name "my-app"
|
|
70
|
-
version 1.0.0
|
|
71
|
-
enabled true
|
|
72
|
-
port 8080
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
**Directivas con bloques:**
|
|
76
|
-
|
|
77
|
-
```don
|
|
78
|
-
container {
|
|
79
|
-
image "nginx"
|
|
80
|
-
port 8080
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
**Directivas con argumentos y bloques:**
|
|
85
|
-
|
|
86
|
-
```don
|
|
87
|
-
service "web" replicas 3 {
|
|
88
|
-
container "nginx" {
|
|
89
|
-
port 80
|
|
90
|
-
image "nginx:latest"
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
**Directivas repetidas:**
|
|
96
|
-
|
|
97
|
-
```don
|
|
98
|
-
container {
|
|
99
|
-
image "nginx"
|
|
100
|
-
port 80
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
container {
|
|
104
|
-
image "redis"
|
|
105
|
-
port 6379
|
|
106
|
-
}
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
## Tipos de Datos
|
|
110
|
-
|
|
111
|
-
DON reconoce los siguientes tipos de tokens:
|
|
29
|
+
## Usage
|
|
112
30
|
|
|
113
|
-
|
|
114
|
-
- **Strings**: Cadenas de texto entre comillas dobles o simples (`"texto"`, `'texto'`)
|
|
115
|
-
- Soportan caracteres escapados: `\"`, `\'`, `\\`
|
|
116
|
-
- **Numbers**: Enteros o decimales (`123`, `45.67`)
|
|
117
|
-
- Pueden incluir guiones bajos como separadores: `1_000_000`
|
|
118
|
-
- **Booleans**: Valores `true` o `false`
|
|
119
|
-
- **Null**: Valor nulo `null`
|
|
120
|
-
- **Punctuators**: Símbolos delimitadores: `{`, `}`, `[`, `]`, `,`, `+`, `-`, `/`, `*`, `<`, `>`
|
|
121
|
-
- **Comments**:
|
|
122
|
-
- Línea: `// comentario` o `# comentario`
|
|
123
|
-
- Multilínea: `/* comentario */`
|
|
31
|
+
### Deserialization (DON → JavaScript)
|
|
124
32
|
|
|
125
|
-
|
|
33
|
+
Parse DON format strings into JavaScript objects using `DocumentDecoder`:
|
|
126
34
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
3. **Bloque de subdirectivas**: Opcional, delimitado por llaves `{ }`
|
|
130
|
-
4. **Delimitación**: Las directivas se separan por saltos de línea
|
|
131
|
-
5. **Anidación**: Las subdirectivas siguen las mismas reglas
|
|
132
|
-
6. **Restricción**: No puede haber tokens después de un bloque en la misma línea
|
|
133
|
-
|
|
134
|
-
**Sintaxis válida:**
|
|
35
|
+
```typescript
|
|
36
|
+
import { DocumentDecoder } from "@jondotsoy/don";
|
|
135
37
|
|
|
136
|
-
|
|
137
|
-
// Directiva simple
|
|
38
|
+
const donPayload = `
|
|
138
39
|
name "my-app"
|
|
139
|
-
version 1.0.0
|
|
140
|
-
|
|
141
|
-
// Directiva con bloque
|
|
40
|
+
version "1.0.0"
|
|
142
41
|
container {
|
|
143
42
|
image "nginx"
|
|
144
43
|
port 8080
|
|
145
44
|
}
|
|
45
|
+
`;
|
|
146
46
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
/* Comentario multilínea */
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
**Sintaxis inválida:**
|
|
153
|
-
|
|
154
|
-
```don
|
|
155
|
-
// ❌ Tokens después del bloque
|
|
156
|
-
container { image "nginx" } extra
|
|
157
|
-
|
|
158
|
-
// ❌ String sin cerrar
|
|
159
|
-
name "unclosed
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
## Casos de Uso
|
|
163
|
-
|
|
164
|
-
### Archivos de Configuración
|
|
165
|
-
|
|
166
|
-
```don
|
|
167
|
-
app "my-service" {
|
|
168
|
-
version 2.1.0
|
|
169
|
-
environment "production"
|
|
170
|
-
|
|
171
|
-
database {
|
|
172
|
-
host "localhost"
|
|
173
|
-
port 5432
|
|
174
|
-
name "mydb"
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
cache {
|
|
178
|
-
enabled true
|
|
179
|
-
ttl 3600
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
### Definiciones de Infraestructura (Kubernetes)
|
|
185
|
-
|
|
186
|
-
```yaml
|
|
187
|
-
apiVersion: v1
|
|
188
|
-
kind: Pod
|
|
189
|
-
metadata:
|
|
190
|
-
name: command-demo
|
|
191
|
-
labels:
|
|
192
|
-
purpose: demonstrate-command
|
|
193
|
-
spec:
|
|
194
|
-
containers:
|
|
195
|
-
- name: command-demo-container
|
|
196
|
-
image: debian
|
|
197
|
-
command: ["printenv"]
|
|
198
|
-
args: ["HOSTNAME", "KUBERNETES_PORT"]
|
|
199
|
-
restartPolicy: OnFailure
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
```don
|
|
203
|
-
apiVersion v1 {
|
|
204
|
-
pod {
|
|
205
|
-
metadata {
|
|
206
|
-
name "command-demo"
|
|
207
|
-
labels {
|
|
208
|
-
purpose "demonstrate-command"
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
spec {
|
|
212
|
-
restartPolicy "OnFailure"
|
|
213
|
-
container debian "command-demo-container" {
|
|
214
|
-
command printenv HOSTNAME KUBERNETES_PORT
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
### Schemas de Datos
|
|
222
|
-
|
|
223
|
-
```don
|
|
224
|
-
schema "user" {
|
|
225
|
-
id integer primaryKey autoIncrement
|
|
226
|
-
email string unique required
|
|
227
|
-
name string required
|
|
228
|
-
createdAt timestamp default now
|
|
229
|
-
}
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
### Reglas de Seguridad (Firebase)
|
|
233
|
-
|
|
234
|
-
```don
|
|
235
|
-
service "firebase.storage" {
|
|
236
|
-
match "/b/{bucket}/o" {
|
|
237
|
-
match "/someFolder/{fileName}" {
|
|
238
|
-
allow read write {
|
|
239
|
-
if "request.auth" "!=" null
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### Servicios con Múltiples Contenedores
|
|
247
|
-
|
|
248
|
-
```don
|
|
249
|
-
service "my-service" {
|
|
250
|
-
replicas 2
|
|
251
|
-
container {
|
|
252
|
-
image "my-image"
|
|
253
|
-
port 8080
|
|
254
|
-
}
|
|
255
|
-
container {
|
|
256
|
-
image "my-other-image"
|
|
257
|
-
port 8081
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
## Equivalencias con JSON
|
|
263
|
-
|
|
264
|
-
DON ofrece una sintaxis más limpia y legible para representar estructuras de datos comunes en JSON:
|
|
265
|
-
|
|
266
|
-
**Propiedades simples:**
|
|
267
|
-
|
|
268
|
-
- `{"name":"foo"}` → `name "foo"`
|
|
269
|
-
- `{"version":1}` → `version 1`
|
|
270
|
-
- `{"private": true}` → `private true`
|
|
271
|
-
|
|
272
|
-
**Objetos anidados:**
|
|
273
|
-
|
|
274
|
-
```json
|
|
275
|
-
{ "name": "foo", "meta": { "format": "json", "version": 1 } }
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
```don
|
|
279
|
-
name "foo"
|
|
280
|
-
meta {
|
|
281
|
-
format "json"
|
|
282
|
-
version 1
|
|
283
|
-
}
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
**Arrays o Listas:**
|
|
287
|
-
|
|
288
|
-
```json
|
|
289
|
-
{ "icons": ["foo", "taz"] }
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
```don
|
|
293
|
-
icons {
|
|
294
|
-
icon "foo"
|
|
295
|
-
icon "taz"
|
|
296
|
-
}
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
## Equivalencias con YAML
|
|
300
|
-
|
|
301
|
-
DON puede representar estructuras YAML de manera más concisa. Los tags de YAML (como `!!date`, `!!str`, `!!int`) se convierten en nombres de directivas en DON:
|
|
302
|
-
|
|
303
|
-
**Tags de tipo:**
|
|
304
|
-
|
|
305
|
-
```yaml
|
|
306
|
-
---
|
|
307
|
-
createdAt: !!date 2002-04-28
|
|
308
|
-
count: !!int 42
|
|
309
|
-
description: !!str "Hello World"
|
|
310
|
-
enabled: !!bool true
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
```don
|
|
314
|
-
createdAt date "2002-04-28"
|
|
315
|
-
count int 42
|
|
316
|
-
description str "Hello World"
|
|
317
|
-
enabled bool true
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
**Objetos anidados con tags:**
|
|
321
|
-
|
|
322
|
-
```yaml
|
|
323
|
-
---
|
|
324
|
-
metadata:
|
|
325
|
-
createdAt: !!date 2002-04-28
|
|
326
|
-
version: !!int 1
|
|
327
|
-
```
|
|
47
|
+
const decoder = new DocumentDecoder();
|
|
48
|
+
const result = decoder.decode(donPayload);
|
|
328
49
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
createdAt date "2002-04-28"
|
|
332
|
-
version int 1
|
|
333
|
-
}
|
|
50
|
+
console.log(result);
|
|
51
|
+
// Output: { name: "my-app", version: "1.0.0", container: { image: "nginx", port: 8080 } }
|
|
334
52
|
```
|
|
335
53
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
DON toma inspiración de la sintaxis de Python para el paso de argumentos, permitiendo tanto argumentos posicionales como argumentos con nombre:
|
|
54
|
+
### Serialization (JavaScript → DON)
|
|
339
55
|
|
|
340
|
-
|
|
341
|
-
# Python - Argumentos posicionales
|
|
342
|
-
print("foo")
|
|
56
|
+
Convert JavaScript objects into DON format strings using `DocumentEncoder`:
|
|
343
57
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
# Python - Combinación
|
|
348
|
-
Container("nginx", replicas=3, port=80)
|
|
349
|
-
```
|
|
58
|
+
```typescript
|
|
59
|
+
import { DocumentEncoder } from "@jondotsoy/don";
|
|
350
60
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
61
|
+
const data = {
|
|
62
|
+
name: "my-app",
|
|
63
|
+
version: "1.0.0",
|
|
64
|
+
container: {
|
|
65
|
+
image: "nginx",
|
|
66
|
+
port: 8080,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
354
69
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
name "foo"
|
|
358
|
-
}
|
|
70
|
+
const encoder = new DocumentEncoder();
|
|
71
|
+
const donString = encoder.encode(data);
|
|
359
72
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
73
|
+
console.log(donString);
|
|
74
|
+
// Output:
|
|
75
|
+
// name "my-app"
|
|
76
|
+
// version "1.0.0"
|
|
77
|
+
// container {
|
|
78
|
+
// image "nginx"
|
|
79
|
+
// port 8080
|
|
80
|
+
// }
|
|
365
81
|
```
|
|
366
82
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
### Scripts Disponibles
|
|
370
|
-
|
|
371
|
-
```bash
|
|
372
|
-
# Compilar el proyecto
|
|
373
|
-
npm run build
|
|
374
|
-
|
|
375
|
-
# Limpiar archivos compilados
|
|
376
|
-
npm run clean
|
|
377
|
-
|
|
378
|
-
# Formatear código
|
|
379
|
-
npm run fmt
|
|
83
|
+
### Working with Heredocs
|
|
380
84
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
85
|
+
```typescript
|
|
86
|
+
import { DocumentDecoder } from "@jondotsoy/don";
|
|
87
|
+
|
|
88
|
+
const donPayload = `
|
|
89
|
+
name "deployment-script"
|
|
90
|
+
script <<<
|
|
91
|
+
#!/bin/bash
|
|
92
|
+
echo "Deploying application..."
|
|
93
|
+
npm run build
|
|
94
|
+
`;
|
|
384
95
|
|
|
385
|
-
|
|
96
|
+
const result = new DocumentDecoder().decode(donPayload);
|
|
386
97
|
|
|
98
|
+
console.log(result.script);
|
|
99
|
+
// Output: "#!/bin/bash\necho \"Deploying application...\"\nnpm run build"
|
|
387
100
|
```
|
|
388
|
-
.
|
|
389
|
-
├── src/ # Código fuente TypeScript
|
|
390
|
-
│ ├── lexer.ts # Analizador léxico
|
|
391
|
-
│ ├── document.ts # Parser de documentos
|
|
392
|
-
│ ├── chunk.ts # Manejo de chunks
|
|
393
|
-
│ └── utils/ # Utilidades
|
|
394
|
-
├── lib/ # Código compilado
|
|
395
|
-
│ └── esm/ # Módulos ES
|
|
396
|
-
├── docs/ # Documentación
|
|
397
|
-
└── index.ts # Punto de entrada
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
## Documentación
|
|
401
|
-
|
|
402
|
-
Para más información sobre DON, consulta la [documentación completa](./docs/index.md):
|
|
403
101
|
|
|
404
|
-
|
|
405
|
-
- [Directivas](./docs/concepts/directive.md): Anatomía y uso de directivas
|
|
406
|
-
- [Heredocs](./docs/concepts/heredoc.md): Contenido multilínea
|
|
407
|
-
- [Tipos de Datos](./docs/concepts/types/): Especificación de tipos soportados
|
|
408
|
-
- [Inspiración](./docs/inspiration.md): Objetivos y visión del proyecto
|
|
102
|
+
## Documentation
|
|
409
103
|
|
|
410
|
-
|
|
104
|
+
For more information about DON, check out the [complete documentation](./docs/index.md):
|
|
411
105
|
|
|
412
|
-
|
|
106
|
+
- [DON File Format](./docs/don-file.md): Complete format specification
|
|
107
|
+
- [Formal Specification v0](./docs/specs/v0/spec.md): Draft specification (v0)
|
|
108
|
+
- [Directives](./docs/concepts/directive.md): Anatomy and usage of directives
|
|
109
|
+
- [Heredocs](./docs/concepts/heredoc.md): Multi-line content blocks
|
|
110
|
+
- [Data Types](./docs/concepts/types/): Specification of supported types
|
|
111
|
+
- [Inspiration](./docs/inspiration.md): Project goals and vision
|
|
413
112
|
|
|
414
|
-
##
|
|
113
|
+
## License
|
|
415
114
|
|
|
416
|
-
[
|
|
115
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/lib/esm/don.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class Directive {
|
|
2
|
+
readonly name: string;
|
|
3
|
+
readonly args: (number | string | boolean)[];
|
|
4
|
+
readonly children: Directive[];
|
|
5
|
+
constructor(name: string, args: (number | string | boolean)[], children?: Directive[]);
|
|
6
|
+
}
|
|
7
|
+
export declare class DON {
|
|
8
|
+
static parse(text: string): Directive[];
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=don.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"don.d.ts","sourceRoot":"","sources":["../../src/don.ts"],"names":[],"mappings":"AAGA,qBAAa,SAAS;IAElB,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE;IAC5C,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE;gBAFrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,EACnC,QAAQ,GAAE,SAAS,EAAO;CAEtC;AAsBD,qBAAa,GAAG;IACd,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM;CAK1B"}
|
package/lib/esm/don.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SyntaxEncode } from "./v1/compiler/syntax-encode";
|
|
2
|
+
export class Directive {
|
|
3
|
+
name;
|
|
4
|
+
args;
|
|
5
|
+
children;
|
|
6
|
+
constructor(name, args, children = []) {
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.args = args;
|
|
9
|
+
this.children = children;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const toDirective = (node) => {
|
|
13
|
+
return new Directive(node.name.text(), node.args.map((token) => token.toJS()), node.children.map((child) => toDirective(child)).flat());
|
|
14
|
+
};
|
|
15
|
+
const docToDirective = (node) => {
|
|
16
|
+
const directives = node.children.map((node) => {
|
|
17
|
+
return new Directive(node.name.text(), node.args.map((token) => token.toJS()), node.children.map((child) => toDirective(child)).flat());
|
|
18
|
+
});
|
|
19
|
+
return directives;
|
|
20
|
+
};
|
|
21
|
+
export class DON {
|
|
22
|
+
static parse(text) {
|
|
23
|
+
const documentNode = new SyntaxEncode().encode(text);
|
|
24
|
+
return docToDirective(documentNode);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=don.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"don.js","sourceRoot":"","sources":["../../src/don.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,MAAM,OAAO,SAAS;IAET;IACA;IACA;IAHX,YACW,IAAY,EACZ,IAAmC,EACnC,WAAwB,EAAE;QAF1B,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAA+B;QACnC,aAAQ,GAAR,QAAQ,CAAkB;IAClC,CAAC;CACL;AAED,MAAM,WAAW,GAAG,CAAC,IAAmB,EAAa,EAAE;IACrD,OAAO,IAAI,SAAS,CAClB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAChB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EACtC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CACxD,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,IAAkB,EAAe,EAAE;IACzD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC5C,OAAO,IAAI,SAAS,CAClB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAChB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EACtC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CACxD,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG;IACd,MAAM,CAAC,KAAK,CAAC,IAAY;QACvB,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAErD,OAAO,cAAc,CAAC,YAAY,CAAC,CAAC;IACtC,CAAC;CACF"}
|
package/lib/esm/index.d.ts
CHANGED
package/lib/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC"}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export { SyntaxEncode } from "./v1/compiler/syntax-encode.js";
|
|
2
|
+
// TODO: preparar package.json
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE9D,8BAA8B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-syntax-kind.d.ts","sourceRoot":"","sources":["../../../../src/v1/__utils__/key-syntax-kind.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,CAoBzD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SyntaxKind } from "../utils/syntax-kind.js";
|
|
2
|
+
export const KeySyntaxKind = {
|
|
3
|
+
[SyntaxKind.unknown]: "Unknown",
|
|
4
|
+
[SyntaxKind.alphabet]: "Alphabet",
|
|
5
|
+
[SyntaxKind.integer]: "Int",
|
|
6
|
+
[SyntaxKind.whitespace]: "Whitespace",
|
|
7
|
+
[SyntaxKind.newline]: "Newline",
|
|
8
|
+
[SyntaxKind.dot]: "Dot",
|
|
9
|
+
[SyntaxKind.underscore]: "underscore",
|
|
10
|
+
[SyntaxKind.openCurlyBrace]: "OpenCurlyBrace",
|
|
11
|
+
[SyntaxKind.closeCurlyBrace]: "CloseCurlyBrace",
|
|
12
|
+
[SyntaxKind.keyword]: "Keyword",
|
|
13
|
+
[SyntaxKind.numeric]: "Numeric",
|
|
14
|
+
[SyntaxKind.boolean]: "Boolean",
|
|
15
|
+
[SyntaxKind.null]: "Null",
|
|
16
|
+
[SyntaxKind.comment]: "Comment",
|
|
17
|
+
[SyntaxKind.indent]: "Indent",
|
|
18
|
+
[SyntaxKind.heredoc]: "Heredoc",
|
|
19
|
+
[SyntaxKind.singleQuote]: "SingleQuote",
|
|
20
|
+
[SyntaxKind.doubleQuote]: "DoubleQuote",
|
|
21
|
+
[SyntaxKind.string]: "String",
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=key-syntax-kind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-syntax-kind.js","sourceRoot":"","sources":["../../../../src/v1/__utils__/key-syntax-kind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,MAAM,CAAC,MAAM,aAAa,GAAoC;IAC5D,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,SAAS;IAC/B,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,UAAU;IACjC,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK;IAC3B,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,YAAY;IACrC,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,SAAS;IAC/B,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,KAAK;IACvB,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,YAAY;IACrC,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,gBAAgB;IAC7C,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,iBAAiB;IAC/C,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,SAAS;IAC/B,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,SAAS;IAC/B,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,SAAS;IAC/B,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM;IACzB,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,SAAS;IAC/B,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,QAAQ;IAC7B,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,SAAS;IAC/B,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,aAAa;IACvC,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,aAAa;IACvC,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,QAAQ;CAC9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../../src/v1/__utils__/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEzC,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,GAAG,UAAU,GAAG,MAAM,EAAE,KAAG,EAMjE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const normalize = (input) => {
|
|
2
|
+
if (typeof input === "string")
|
|
3
|
+
return [...new TextEncoder().encode(input)];
|
|
4
|
+
if (input instanceof Uint8Array)
|
|
5
|
+
return [...input];
|
|
6
|
+
if (Array.isArray(input) && input.every((value) => typeof value === "number"))
|
|
7
|
+
return input;
|
|
8
|
+
throw new Error("not implemented");
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../../../src/v1/__utils__/normalize.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAqC,EAAM,EAAE;IACrE,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,CAAC,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3E,IAAI,KAAK,YAAY,UAAU;QAAE,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;IACnD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;QAC3E,OAAO,KAAK,CAAC;IACf,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;AACrC,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type Candidate = Result<any, any, any> | (() => any);
|
|
2
|
+
export declare class Result<O, E, V> {
|
|
3
|
+
readonly ok: O;
|
|
4
|
+
readonly error: E;
|
|
5
|
+
readonly value: V;
|
|
6
|
+
constructor(ok: O, error: E, value: V);
|
|
7
|
+
[Symbol.iterator](): Generator<O | E | V, void, unknown>;
|
|
8
|
+
static ok: <V_1>(value: V_1) => Result<true, undefined, V_1>;
|
|
9
|
+
static error: <E_1>(error: E_1) => Result<false, E_1, undefined>;
|
|
10
|
+
}
|
|
11
|
+
type ResultType<O, E, V> = Result<O, E, V> & [O, E, V];
|
|
12
|
+
type R<T> = T extends Result<infer O, infer E, infer V> ? ResultType<O, E, V> : T extends () => infer V ? ResultType<true, unknown, V> | Result<false, unknown, null> : ResultType<false, unknown, never>;
|
|
13
|
+
export declare const t: <T extends Candidate>(candidate: T) => R<T>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=t.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"t.d.ts","sourceRoot":"","sources":["../../../../src/v1/__utils__/t.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;AAErD,qBAAa,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAEvB,QAAQ,CAAC,EAAE,EAAE,CAAC;IACd,QAAQ,CAAC,KAAK,EAAE,CAAC;IACjB,QAAQ,CAAC,KAAK,EAAE,CAAC;gBAFR,EAAE,EAAE,CAAC,EACL,KAAK,EAAE,CAAC,EACR,KAAK,EAAE,CAAC;IAGlB,CAAC,MAAM,CAAC,QAAQ,CAAC;IAMlB,MAAM,CAAC,EAAE,GAAI,GAAC,EAAE,OAAO,GAAC,kCAAiD;IACzE,MAAM,CAAC,KAAK,GAAI,GAAC,EAAE,OAAO,GAAC,mCAAkD;CAC9E;AAED,KAAK,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEvD,KAAK,CAAC,CAAC,CAAC,IACN,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GACvC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GACnB,CAAC,SAAS,MAAM,MAAM,CAAC,GACrB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,GAC3D,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAE1C,eAAO,MAAM,CAAC,GAAI,CAAC,SAAS,SAAS,EAAE,WAAW,CAAC,KAAG,CAAC,CAAC,CAAC,CAYxD,CAAC"}
|