@taekwondo-db/database 0.9.0 → 0.10.0

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/README.md CHANGED
@@ -21,6 +21,7 @@ db/poomsae/ one file per Poomsae, referencing the techniques; the file
21
21
  db/terms.json Korean terms the technique names are built from
22
22
  db/sources.json books and other sources
23
23
  db/schemas/ JSON Schemas of all of the above, and of apps' own files
24
+ (include list, patches, grades, basics)
24
25
  img/<group>/ illustrations (CC BY 4.0, see License)
25
26
  audio/<group>/ spoken technique names (CC BY 4.0)
26
27
  audio/terms/ spoken terms (CC BY 4.0)
@@ -128,7 +129,11 @@ be a point; an `eyeDir` may also be a bare direction such as `Ga`.
128
129
  A stance or technique the database does not have is given by `name` instead of
129
130
  `$ref`. A technique given by `$ref` and `name` is a variant the referenced
130
131
  technique covers, shown under the name the Poomsae uses — e.g. Ttwieo
131
- Yeopchagi, which refers to Ttwieochagi.
132
+ Yeopchagi, which refers to Ttwieochagi. A `name` may
133
+ [reference](#references-in-descriptions) techniques and terms, so that each
134
+ word links on its own: `"#[apbal|Apbal] #[Yeopchagi]"`; `stripRefs` gives the
135
+ plain name. A technique's `note` says what is special about it there, per
136
+ language and with references, e.g. how a Seokkeochagi is kicked.
132
137
 
133
138
  Loaded techniques carry the reverse, the Poomsae that use them, as `poomsae`.
134
139
 
@@ -196,6 +201,7 @@ loader that strips types; Node does not strip types below `node_modules`.
196
201
  | `customTechniques` | own techniques that carry their own `group` |
197
202
  | `terms`, `sources`, `poomsae` | own terms, sources and Poomsae; replace bundled ones of the same key |
198
203
  | `grades` | from which grade on a technique or Poomsae is taught, see below |
204
+ | `basics` | the basics (Grundschule) of each grade, see below |
199
205
 
200
206
  An own technique must not have the name of a bundled one — patch that instead.
201
207
  Group names are not a closed set.
@@ -248,6 +254,40 @@ a technique or Poomsae is taught. Keys are `10-kup` … `1-kup`, `1-poom` …
248
254
  first grade, and must be loaded. Unknown grades, techniques or Poomsae and
249
255
  duplicates are errors.
250
256
 
257
+ #### `basics`
258
+
259
+ ```js
260
+ {
261
+ "8-kup": [
262
+ { steps: [{ stance: { $ref: "./seogi.json#/Moaseogi" } }] },
263
+ {
264
+ direction: "forward",
265
+ start: { $ref: "./seogi.json#/Apgubi" },
266
+ steps: [{
267
+ stance: { $ref: "./seogi.json#/Apgubi" },
268
+ action: [{ $ref: "./chagi.json#/Apchagi" }],
269
+ nameOfPoom: [{ $ref: "./makgi.json#/Momtong Makgi" }],
270
+ }],
271
+ },
272
+ ],
273
+ }
274
+ ```
275
+
276
+ The basics a club practises for a grade, one course per grade; the bundled
277
+ data has none. A course is a list of lanes. A lane's `steps` are repeated along
278
+ the hall, `forward` or `backward`; a lane without `direction` stays on the
279
+ spot; `start` is the stance each repetition starts in, e.g. Apgubi before
280
+ Apchagi. A step is a Poomsae movement without order, eye direction and position:
281
+ the `stance` it ends in, the techniques on the way (`action`) and those it
282
+ ends with (`nameOfPoom`), all optional but one; a technique with `inPlace`
283
+ takes no step of its own, and `note` says what is special, on a step or a lane.
284
+ A `side` describes the first repetition; the next one mirrors it.
285
+
286
+ Whether and where to turn is left to the club. Keys are those of
287
+ [`grades`](#grades).
288
+ Techniques left out by `include` stay as plain names, unknown ones are errors.
289
+ Loaded techniques carry the grades whose basics use them as `basics`.
290
+
251
291
  ### Methods
252
292
 
253
293
  | Method | Returns |
@@ -257,6 +297,7 @@ duplicates are errors.
257
297
  | `getAllTechniques()`, `getAllTerms()`, `getAllSources()` | iterators of `[key, entry]` |
258
298
  | `getGroups()`, `getTechniquesByGroup(group)` | the group names; the techniques of one group in order |
259
299
  | `getGrades()`, `getTechniquesByGrade(key)`, `getPoomsaeByGrade(key)` | the grades in use, lowest first; the techniques or Poomsae of one grade |
300
+ | `getBasics(key)` | the basics of one grade with their techniques resolved, or `undefined` |
260
301
  | `searchTechniques(input, lang)` | fuzzy search over name, `supplementaryName`, Hangeul and `translation` |
261
302
  | `searchTerms(input, lang)` | fuzzy search over name, `hangeul` and `description` |
262
303
  | `resolveDescription(text)` | the text split into plain text and resolved references; references to what is not loaded become text |
@@ -305,7 +346,7 @@ Bundlers can drop the bundled data altogether by aliasing
305
346
  ### Schemas for apps
306
347
 
307
348
  Own files can point their `$schema` at `db/schemas/include.json`,
308
- `patches.json`, `grades.json`, `techniques.json`, `terms.json`,
349
+ `patches.json`, `grades.json`, `basics.json`, `techniques.json`, `terms.json`,
309
350
  `sources.json` or `poomsae.json`. The include and patch schemas describe only the shape: patched
310
351
  results are checked against the technique and term schemas, names when the
311
352
  database is built.
package/db/jireugi.json CHANGED
@@ -455,7 +455,7 @@
455
455
  "sources": [
456
456
  { "$ref": "./sources.json#/kukkiwon_2022_book_2", "page": "165" }
457
457
  ],
458
- "supplementaryName": "(Momtong) Jireugi",
458
+ "supplementaryName": "Jireugi",
459
459
  "terms": [
460
460
  { "$ref": "./terms.json#/momtong" },
461
461
  { "$ref": "./terms.json#/$space" },
package/db/makgi.json CHANGED
@@ -622,7 +622,7 @@
622
622
  { "$ref": "./sources.json#/kukkiwon_2022_book_2", "page": "154" }
623
623
  ],
624
624
  "terms": [
625
- { "$ref": "./terms.json#/balnal" },
625
+ { "$ref": "./terms.json#/ballal" },
626
626
  { "$ref": "./terms.json#/$space" },
627
627
  { "$ref": "./terms.json#/bada" },
628
628
  { "$ref": "./terms.json#/makgi" }
@@ -1239,7 +1239,7 @@
1239
1239
  "sources": [
1240
1240
  { "$ref": "./sources.json#/kukkiwon_2022_book_2", "page": "123" }
1241
1241
  ],
1242
- "supplementaryName": "(Momtong) Bakkanmakgi",
1242
+ "supplementaryName": "Bakkanmakgi",
1243
1243
  "terms": [
1244
1244
  { "$ref": "./terms.json#/momtong" },
1245
1245
  { "$ref": "./terms.json#/$space" },
@@ -1363,7 +1363,7 @@
1363
1363
  "sources": [
1364
1364
  { "$ref": "./sources.json#/kukkiwon_2022_book_2", "page": "134" }
1365
1365
  ],
1366
- "supplementaryName": "(Palmok) Oesanmakgi",
1366
+ "supplementaryName": "Oesanmakgi",
1367
1367
  "terms": [
1368
1368
  { "$ref": "./terms.json#/palmok" },
1369
1369
  { "$ref": "./terms.json#/$space" },
@@ -0,0 +1,82 @@
1
+ {
2
+ "$id": "schemas/basics.json",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "additionalProperties": {
5
+ "description": "The basics of this grade: its lanes in order.",
6
+ "items": { "$ref": "#/definitions/lane" },
7
+ "minItems": 1,
8
+ "type": "array"
9
+ },
10
+ "definitions": {
11
+ "lane": {
12
+ "additionalProperties": false,
13
+ "description": "One lane: its steps are repeated along the hall, in one direction.",
14
+ "properties": {
15
+ "direction": {
16
+ "description": "Where the lane goes. Omitted: it stays on the spot, e.g. Moaseogi.",
17
+ "enum": ["forward", "backward"]
18
+ },
19
+ "note": {
20
+ "$ref": "./localized-string.json",
21
+ "description": "What is special about the lane; may reference techniques and terms."
22
+ },
23
+ "start": {
24
+ "$ref": "./poomsae.json#/definitions/stance",
25
+ "description": "The stance each repetition starts in, e.g. Apgubi before Apchagi. Omitted where nothing comes before the stance of the first step."
26
+ },
27
+ "steps": {
28
+ "description": "The steps of one repetition, in order.",
29
+ "items": { "$ref": "#/definitions/step" },
30
+ "minItems": 1,
31
+ "type": "array"
32
+ }
33
+ },
34
+ "required": ["steps"],
35
+ "type": "object"
36
+ },
37
+ "step": {
38
+ "additionalProperties": false,
39
+ "anyOf": [
40
+ { "required": ["stance"] },
41
+ { "required": ["action"] },
42
+ { "required": ["nameOfPoom"] }
43
+ ],
44
+ "description": "One step, like a movement of a Poomsae. A technique with inPlace takes no step of its own, e.g. Momtong Jireugi after Araemakgi without a step.",
45
+ "properties": {
46
+ "action": {
47
+ "description": "The techniques executed on the way, in order, e.g. a kick before landing.",
48
+ "items": { "$ref": "./poomsae.json#/definitions/technique" },
49
+ "minItems": 1,
50
+ "type": "array"
51
+ },
52
+ "nameOfPoom": {
53
+ "description": "The techniques the step ends with, e.g. a block on landing.",
54
+ "items": { "$ref": "./poomsae.json#/definitions/technique" },
55
+ "minItems": 1,
56
+ "type": "array"
57
+ },
58
+ "note": {
59
+ "$ref": "./localized-string.json",
60
+ "description": "What is special about the step; may reference techniques and terms."
61
+ },
62
+ "stance": {
63
+ "$ref": "./poomsae.json#/definitions/stance",
64
+ "description": "The stance the step ends in."
65
+ }
66
+ },
67
+ "type": "object"
68
+ }
69
+ },
70
+ "description": "The basics (Grundschule) of a club, keyed by grade: one course of lanes per grade, executed forward or backward. Sides are optional; given, they describe the first repetition, which the next one mirrors. Keyed by grade: \"10-kup\" … \"1-kup\", \"1-poom\" … \"4-poom\", \"1-dan\" … \"9-dan\".",
71
+ "properties": { "$schema": { "type": "string" } },
72
+ "propertyNames": {
73
+ "anyOf": [
74
+ { "const": "$schema" },
75
+ { "pattern": "^([1-9]|10)-kup$" },
76
+ { "pattern": "^[1-4]-poom$" },
77
+ { "pattern": "^[1-9]-dan$" }
78
+ ]
79
+ },
80
+ "title": "Basics",
81
+ "type": "object"
82
+ }
@@ -83,10 +83,14 @@
83
83
  "type": "boolean"
84
84
  },
85
85
  "name": {
86
- "description": "The name used in the Poomsae. Without $ref: a technique the database does not have; with $ref: a variant the referenced technique covers, e.g. Ttwieo Yeopchagi for Ttwieochagi.",
86
+ "description": "The name used in the Poomsae. Without $ref: a technique the database does not have; with $ref: a variant the referenced technique covers, e.g. Ttwieo Yeopchagi for Ttwieochagi. May reference techniques and terms like a description, e.g. \"#[apbal|Apbal] #[Yeopchagi]\".",
87
87
  "minLength": 1,
88
88
  "type": "string"
89
89
  },
90
+ "note": {
91
+ "$ref": "./localized-string.json",
92
+ "description": "What is special about the technique here; may reference techniques and terms."
93
+ },
90
94
  "side": {
91
95
  "$ref": "#/definitions/side",
92
96
  "description": "The side that executes the technique, or of the stance. Omitted if there is no such side."
@@ -171,26 +175,8 @@
171
175
  "description": "Where the movement ends."
172
176
  },
173
177
  "stance": {
174
- "additionalProperties": false,
175
- "description": "The stance the movement ends in.",
176
- "oneOf": [{ "required": ["$ref"] }, { "required": ["name"] }],
177
- "properties": {
178
- "$ref": {
179
- "description": "A technique of the database",
180
- "minLength": 1,
181
- "type": "string"
182
- },
183
- "name": {
184
- "description": "The name of a stance the database does not have",
185
- "minLength": 1,
186
- "type": "string"
187
- },
188
- "side": {
189
- "$ref": "#/definitions/side",
190
- "description": "As the Kukkiwon names the stance: the foot in front or crossing, but the supporting leg of Dwitgubi and of stances on one leg. Omitted if it names none."
191
- }
192
- },
193
- "type": "object"
178
+ "$ref": "#/definitions/stance",
179
+ "description": "The stance the movement ends in."
194
180
  }
195
181
  },
196
182
  "required": ["order", "eyeDir", "position", "nameOfPoom"],
@@ -200,6 +186,28 @@
200
186
  "description": "Apps may show it in Korean: Wen (left), Oreun (right).",
201
187
  "enum": ["left", "right"]
202
188
  },
189
+ "stance": {
190
+ "additionalProperties": false,
191
+ "description": "A stance; with name only, one the database does not have.",
192
+ "oneOf": [{ "required": ["$ref"] }, { "required": ["name"] }],
193
+ "properties": {
194
+ "$ref": {
195
+ "description": "A technique of the database",
196
+ "minLength": 1,
197
+ "type": "string"
198
+ },
199
+ "name": {
200
+ "description": "The name of a stance the database does not have",
201
+ "minLength": 1,
202
+ "type": "string"
203
+ },
204
+ "side": {
205
+ "$ref": "#/definitions/side",
206
+ "description": "As the Kukkiwon names the stance: the foot in front or crossing, but the supporting leg of Dwitgubi and of stances on one leg. Omitted if it names none."
207
+ }
208
+ },
209
+ "type": "object"
210
+ },
203
211
  "technique": {
204
212
  "additionalProperties": false,
205
213
  "anyOf": [{ "required": ["$ref"] }, { "required": ["name"] }],
@@ -214,10 +222,14 @@
214
222
  "type": "boolean"
215
223
  },
216
224
  "name": {
217
- "description": "The name used in the Poomsae. Without $ref: a technique the database does not have; with $ref: a variant the referenced technique covers, e.g. Ttwieo Yeopchagi for Ttwieochagi.",
225
+ "description": "The name used in the Poomsae. Without $ref: a technique the database does not have; with $ref: a variant the referenced technique covers, e.g. Ttwieo Yeopchagi for Ttwieochagi. May reference techniques and terms like a description, e.g. \"#[apbal|Apbal] #[Yeopchagi]\".",
218
226
  "minLength": 1,
219
227
  "type": "string"
220
228
  },
229
+ "note": {
230
+ "$ref": "./localized-string.json",
231
+ "description": "What is special about the technique here, e.g. how a Seokkeochagi is kicked; may reference techniques and terms."
232
+ },
221
233
  "side": {
222
234
  "$ref": "#/definitions/side",
223
235
  "description": "The side that executes the technique. Omitted if there is no such side."
package/db/terms.json CHANGED
@@ -58,6 +58,13 @@
58
58
  "hangeul": "앞",
59
59
  "pronunciation": { "ai": true, "src": "terms/ap.mp3" }
60
60
  },
61
+ "apbal": {
62
+ "bodyPart": "foot",
63
+ "description": { "de": "vorderer Fuß", "en": "front foot" },
64
+ "hangeul": "앞발",
65
+ "terms": [{ "$ref": "#/ap" }, { "$ref": "#/bal" }],
66
+ "type": "noun"
67
+ },
61
68
  "apchuk": {
62
69
  "bodyPart": "foot",
63
70
  "description": { "de": "Fußballen", "en": "ball of the foot" },
@@ -164,15 +171,7 @@
164
171
  "terms": [{ "$ref": "#/bal" }, { "$ref": "#/kkeut" }],
165
172
  "type": "noun"
166
173
  },
167
- "balmok": {
168
- "bodyPart": "foot",
169
- "description": { "de": "Fußgelenk", "en": "ankle" },
170
- "hangeul": "발목",
171
- "pronunciation": { "ai": true, "src": "terms/balmok.mp3" },
172
- "terms": [{ "$ref": "#/bal" }, { "$ref": "#/mok" }],
173
- "type": "noun"
174
- },
175
- "balnal": {
174
+ "ballal": {
176
175
  "bodyPart": "foot",
177
176
  "description": { "de": "Fußaußenkante", "en": "foot blade" },
178
177
  "hangeul": "발날",
@@ -186,15 +185,23 @@
186
185
  ]
187
186
  }
188
187
  ],
189
- "pronunciation": { "ai": true, "src": "terms/balnal.mp3" },
188
+ "pronunciation": { "ai": true, "src": "terms/ballal.mp3" },
190
189
  "type": "noun"
191
190
  },
192
- "balnaldeung": {
191
+ "ballaldeung": {
193
192
  "bodyPart": "foot",
194
193
  "description": { "de": "Fußinnenkante", "en": "back of foot blade" },
195
194
  "hangeul": "발날등",
196
- "pronunciation": { "ai": true, "src": "terms/balnaldeung.mp3" },
197
- "terms": [{ "$ref": "#/balnal" }, { "$ref": "#/deung" }],
195
+ "pronunciation": { "ai": true, "src": "terms/ballaldeung.mp3" },
196
+ "terms": [{ "$ref": "#/ballal" }, { "$ref": "#/deung" }],
197
+ "type": "noun"
198
+ },
199
+ "balmok": {
200
+ "bodyPart": "foot",
201
+ "description": { "de": "Fußgelenk", "en": "ankle" },
202
+ "hangeul": "발목",
203
+ "pronunciation": { "ai": true, "src": "terms/balmok.mp3" },
204
+ "terms": [{ "$ref": "#/bal" }, { "$ref": "#/mok" }],
198
205
  "type": "noun"
199
206
  },
200
207
  "bam": {
@@ -478,6 +485,13 @@
478
485
  "pronunciation": { "ai": true, "src": "terms/dwit.mp3" },
479
486
  "type": "modifier"
480
487
  },
488
+ "dwitbal": {
489
+ "bodyPart": "foot",
490
+ "description": { "de": "hinterer Fuß", "en": "back foot" },
491
+ "hangeul": "뒷발",
492
+ "terms": [{ "$ref": "#/dwit" }, { "$ref": "#/bal" }],
493
+ "type": "noun"
494
+ },
481
495
  "eokkae": {
482
496
  "bodyPart": "arm",
483
497
  "description": { "de": "Schulter", "en": "shoulder" },
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
- "dependencies": { "fuse.js": "^7.5.0" },
3
- "devDependencies": {
4
- "ajv": "^8.20.0",
5
- "json-schema-to-typescript": "^16.0.0",
6
- "vite": "^8.3.8",
7
- "vitest": "^5.1.1"
2
+ "name": "@taekwondo-db/database",
3
+ "version": "0.10.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://gitlab.com/taekwondo-db/database.git"
8
7
  },
8
+ "license": "MIT AND CC-BY-4.0",
9
+ "type": "module",
9
10
  "exports": {
10
11
  ".": "./src/database.ts",
11
12
  "./audio/*": "./audio/*",
@@ -19,6 +20,8 @@
19
20
  "./search.browser.js": "./dist/search.browser.js",
20
21
  "./types/*": "./types/*.d.ts"
21
22
  },
23
+ "main": "./src/database.ts",
24
+ "types": "./src/database.ts",
22
25
  "files": [
23
26
  "audio",
24
27
  "db",
@@ -30,14 +33,6 @@
30
33
  "README.md",
31
34
  "LICENSE"
32
35
  ],
33
- "license": "MIT AND CC-BY-4.0",
34
- "main": "./src/database.ts",
35
- "name": "@taekwondo-db/database",
36
- "publishConfig": { "access": "public" },
37
- "repository": {
38
- "type": "git",
39
- "url": "git+https://gitlab.com/taekwondo-db/database.git"
40
- },
41
36
  "scripts": {
42
37
  "build": "vite build -c vite.search.config.js",
43
38
  "fix": "biome check . --write",
@@ -47,7 +42,12 @@
47
42
  "typecheck": "tsc -p .",
48
43
  "validate": "node script/validate-schema.js"
49
44
  },
50
- "type": "module",
51
- "types": "./src/database.ts",
52
- "version": "0.9.0"
45
+ "dependencies": { "fuse.js": "^7.5.0" },
46
+ "devDependencies": {
47
+ "ajv": "^8.20.0",
48
+ "json-schema-to-typescript": "^16.0.0",
49
+ "vite": "^8.3.8",
50
+ "vitest": "^5.1.1"
51
+ },
52
+ "publishConfig": { "access": "public" }
53
53
  }
package/src/compose.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { BasicsJson, BasicsLaneJson } from "../types/basics";
1
2
  import type { PoomsaeEntryJson, PoomsaeJson } from "../types/poomsae";
2
3
  import type { SourcesJson } from "../types/source";
3
4
  import type {
@@ -47,6 +48,12 @@ export interface ComposeOptions {
47
48
  * listed must be loaded, and listed only once.
48
49
  */
49
50
  grades?: GradesJson | null;
51
+ /**
52
+ * The basics (Grundschule) of each grade, e.g.
53
+ * `{ "8-kup": [{ direction: "forward", steps: [...] }] }`: lanes of steps
54
+ * like Poomsae movements, without a line.
55
+ */
56
+ basics?: BasicsJson | null;
50
57
  }
51
58
 
52
59
  export interface Builtins {
@@ -64,6 +71,8 @@ export interface ComposedDatabase {
64
71
  terms: Record<string, TermJson>;
65
72
  /** Validated and sorted from the lowest grade up. */
66
73
  grades: Record<string, string[]>;
74
+ /** Sorted from the lowest grade up; left-out techniques stay as plain names. */
75
+ basics: Record<string, BasicsLaneJson[]>;
67
76
  }
68
77
 
69
78
  export declare const NO_BUILTINS: Builtins;
package/src/compose.js CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * Composes the JSON a database is built from: the builtin Kukkiwon data,
3
3
  * optionally narrowed down by an `include` list, with patches applied and
4
- * own groups, terms and sources on top, and the techniques assigned to grades.
4
+ * own groups, terms and sources on top, the techniques assigned to grades and
5
+ * the basics of each grade.
5
6
  *
6
7
  * Plain JavaScript without data imports on purpose:
7
8
  * - Node can load it from node_modules (it does not strip TypeScript there),
@@ -80,6 +81,29 @@ export function applyPatch(target, patch, path = "") {
80
81
  return result;
81
82
  }
82
83
 
84
+ /**
85
+ * The entries of a JSON keyed by grade, lowest grade first.
86
+ *
87
+ * @template T
88
+ * @param {Record<string, T | string> | null | undefined} json
89
+ * @param {string} option name for error messages
90
+ * @returns {{ grade: import("./grade").Grade, value: T }[]}
91
+ */
92
+ function byGrade(json, option) {
93
+ return Object.entries(json ?? {})
94
+ .filter(([key]) => key !== "$schema")
95
+ .map(([key, value]) => {
96
+ const grade = parseGrade(key);
97
+ if (!grade) {
98
+ throw new Error(
99
+ `${option}: unknown grade "${key}" — expected e.g. "9-kup", "1-poom" or "1-dan"`,
100
+ );
101
+ }
102
+ return { grade, value };
103
+ })
104
+ .sort((a, b) => compareGrades(a.grade, b.grade));
105
+ }
106
+
83
107
  /**
84
108
  * @param {import("./compose").ComposeOptions} options
85
109
  * @param {import("./compose").Builtins} builtins
@@ -214,14 +238,15 @@ export function composeDatabase(options, builtins) {
214
238
  for (const [name, entry] of entries(options.poomsae)) {
215
239
  poomsae[name] = structuredClone(entry);
216
240
  }
241
+ /** A builtin technique left out stays as its plain name. */
242
+ const dropRef = (part) => {
243
+ if (!include || !part?.$ref) return;
244
+ const key = refKey(part);
245
+ if (groupOf.has(key) || !builtinNames.has(key)) return;
246
+ delete part.$ref;
247
+ part.name ??= key;
248
+ };
217
249
  if (include) {
218
- const dropRef = (part) => {
219
- if (!part?.$ref) return;
220
- const key = refKey(part);
221
- if (groupOf.has(key) || !builtinNames.has(key)) return;
222
- delete part.$ref;
223
- part.name ??= key;
224
- };
225
250
  for (const { movements } of Object.values(poomsae)) {
226
251
  for (const movement of movements) {
227
252
  dropRef(movement.stance);
@@ -315,20 +340,7 @@ export function composeDatabase(options, builtins) {
315
340
  const grades = {};
316
341
  /** technique name → grade it is listed at */
317
342
  const gradeOf = new Map();
318
- const listed = Object.entries(options.grades ?? {})
319
- .filter(([key]) => key !== "$schema")
320
- .map(([key, names]) => {
321
- const grade = parseGrade(key);
322
- if (!grade) {
323
- throw new Error(
324
- `grades: unknown grade "${key}" — expected e.g. "9-kup", "1-poom" or "1-dan"`,
325
- );
326
- }
327
- return { grade, names };
328
- })
329
- .sort((a, b) => compareGrades(a.grade, b.grade));
330
-
331
- for (const { grade, names } of listed) {
343
+ for (const { grade, value: names } of byGrade(options.grades, "grades")) {
332
344
  for (const name of names) {
333
345
  if (!groupOf.has(name) && !poomsae[name]) {
334
346
  throw new Error(
@@ -347,7 +359,23 @@ export function composeDatabase(options, builtins) {
347
359
  grades[grade.key] = [...names];
348
360
  }
349
361
 
362
+ // 8. Basics — one course of lanes per grade, like Poomsae without a line.
363
+ /** @type {Record<string, object[]>} */
364
+ const basics = {};
365
+ for (const { grade, value: lanes } of byGrade(options.basics, "basics")) {
366
+ basics[grade.key] = structuredClone(lanes);
367
+ for (const { start, steps } of basics[grade.key]) {
368
+ dropRef(start);
369
+ for (const step of steps) {
370
+ dropRef(step.stance);
371
+ for (const part of step.action ?? []) dropRef(part);
372
+ for (const part of step.nameOfPoom ?? []) dropRef(part);
373
+ }
374
+ }
375
+ }
376
+
350
377
  return {
378
+ basics,
351
379
  customTechniques,
352
380
  grades,
353
381
  poomsae,
package/src/database.ts CHANGED
@@ -4,12 +4,19 @@ import {
4
4
  builtinTechniqueGroups,
5
5
  builtinTerms,
6
6
  } from "@taekwondo-db/database/builtins";
7
+ import type {
8
+ Basics,
9
+ BasicsLane,
10
+ BasicsLaneJson,
11
+ BasicsStep,
12
+ } from "../types/basics";
7
13
  import type { Historic, HistoricJson } from "../types/historic";
8
14
  import type {
9
15
  Poomsae,
10
16
  PoomsaeEntryJson,
11
17
  PoomsaeJson,
12
18
  PoomsaeMovement,
19
+ PoomsaeStanceJson,
13
20
  PoomsaeTechniqueJson,
14
21
  } from "../types/poomsae";
15
22
  import type { Source, SourceJson, Sources, SourcesJson } from "../types/source";
@@ -26,10 +33,17 @@ import type { ComposeOptions } from "./compose.js";
26
33
  import { composeDatabase, NO_BUILTINS } from "./compose.js";
27
34
  import { parseDescription } from "./description.js";
28
35
  import type { Grade } from "./grade.js";
29
- import { parseGrade } from "./grade.js";
36
+ import { compareGrades, parseGrade } from "./grade.js";
30
37
  import { findHierarchyErrors } from "./hierarchy.js";
31
38
  import { createTechniqueSearch, createTermSearch } from "./search.js";
32
39
 
40
+ export type {
41
+ Basics,
42
+ BasicsDirection,
43
+ BasicsJson,
44
+ BasicsLane,
45
+ BasicsStep,
46
+ } from "../types/basics";
33
47
  export type {
34
48
  Poomsae,
35
49
  PoomsaeActionTechnique,
@@ -92,6 +106,7 @@ export class TaekwondoDatabase {
92
106
  private grades: Grade[] = [];
93
107
  private gradeTechniques = new Map<string, Technique[]>();
94
108
  private gradePoomsae = new Map<string, Poomsae[]>();
109
+ private basics = new Map<string, Basics>();
95
110
 
96
111
  constructor(options: DatabaseOptions = {}) {
97
112
  const includeBuiltins = options.includeBuiltins ?? true;
@@ -133,6 +148,15 @@ export class TaekwondoDatabase {
133
148
  this.addReferences();
134
149
  this.loadPoomsae(composed.poomsae);
135
150
  this.assignGrades(composed.grades);
151
+ this.loadBasics(composed.basics);
152
+ this.grades = [
153
+ ...new Set([
154
+ ...Object.keys(composed.grades),
155
+ ...Object.keys(composed.basics),
156
+ ]),
157
+ ]
158
+ .map((key) => parseGrade(key) as Grade)
159
+ .sort(compareGrades);
136
160
  }
137
161
 
138
162
  /**
@@ -215,7 +239,7 @@ export class TaekwondoDatabase {
215
239
  );
216
240
  }
217
241
 
218
- /** The grades given via `options.grades`, lowest first. */
242
+ /** The grades given via `options.grades` or `options.basics`, lowest first. */
219
243
  public getGrades(): Grade[] {
220
244
  return [...this.grades];
221
245
  }
@@ -230,6 +254,11 @@ export class TaekwondoDatabase {
230
254
  return [...(this.gradePoomsae.get(key) ?? [])];
231
255
  }
232
256
 
257
+ /** The basics (Grundschule) of this grade, given via `options.basics`. */
258
+ public getBasics(key: string): Basics | undefined {
259
+ return this.basics.get(key);
260
+ }
261
+
233
262
  public searchTechniques(input: string, lang: string): Technique[] {
234
263
  return createTechniqueSearch([...this.techniques.values()], lang)(input);
235
264
  }
@@ -269,7 +298,6 @@ export class TaekwondoDatabase {
269
298
  if (technique) techniques.push(technique);
270
299
  else poomsae.push(entry as Poomsae);
271
300
  }
272
- this.grades.push(grade);
273
301
  this.gradeTechniques.set(key, techniques);
274
302
  this.gradePoomsae.set(key, poomsae);
275
303
  }
@@ -296,29 +324,15 @@ export class TaekwondoDatabase {
296
324
  }
297
325
  }
298
326
 
299
- /** The technique of a `$ref`, or just the name where there is none. */
300
- const resolve = (part: Ref | { name: string }) => {
301
- if (!("$ref" in part)) return { name: part.name };
302
- const name = "name" in part ? (part.name as string) : undefined;
303
- const technique = this.deref(this.techniques, part);
304
- if (technique === undefined) {
305
- throw new Error(
306
- `Poomsae "${key}": could not find technique reference: ${part.$ref}`,
307
- );
308
- }
309
- technique.poomsae ??= [];
310
- if (!technique.poomsae.includes(poomsae)) technique.poomsae.push(poomsae);
311
- return { name: name ?? technique.name, technique };
312
- };
313
-
314
- const resolveAll = <T extends PoomsaeTechniqueJson>(parts: T[]) =>
315
- parts.map((part) => ({
316
- ...resolve(part),
317
- ...(part.side && { side: part.side }),
318
- ...("kihap" in part && { kihap: part.kihap as boolean }),
319
- ...("eyeDir" in part && { eyeDir: part.eyeDir as string }),
320
- ...("inPlace" in part && { inPlace: part.inPlace as boolean }),
321
- }));
327
+ const { resolveStance, resolveAll } = this.partResolver(
328
+ `Poomsae "${key}"`,
329
+ (technique) => {
330
+ technique.poomsae ??= [];
331
+ if (!technique.poomsae.includes(poomsae)) {
332
+ technique.poomsae.push(poomsae);
333
+ }
334
+ },
335
+ );
322
336
 
323
337
  this.checkDiagram(key, entry);
324
338
 
@@ -327,18 +341,77 @@ export class TaekwondoDatabase {
327
341
  ...rest,
328
342
  nameOfPoom: resolveAll(nameOfPoom),
329
343
  };
330
- if (stance) {
331
- movement.stance = {
332
- ...resolve(stance),
333
- ...(stance.side && { side: stance.side }),
334
- };
335
- }
344
+ if (stance) movement.stance = resolveStance(stance);
336
345
  if (action) movement.action = resolveAll(action);
337
346
  poomsae.movements.push(movement);
338
347
  }
339
348
  return poomsae;
340
349
  }
341
350
 
351
+ /**
352
+ * Resolves the stances and techniques of a Poomsae or of basics: the
353
+ * technique of a `$ref`, or just the name where there is none.
354
+ * `onTechnique` records the backlink.
355
+ */
356
+ private partResolver(where: string, onTechnique: (t: Technique) => void) {
357
+ const resolve = (part: Ref | { name: string }) => {
358
+ if (!("$ref" in part)) return { name: part.name };
359
+ const name = "name" in part ? (part.name as string) : undefined;
360
+ const technique = this.deref(this.techniques, part);
361
+ if (technique === undefined) {
362
+ throw new Error(
363
+ `${where}: could not find technique reference: ${part.$ref}`,
364
+ );
365
+ }
366
+ onTechnique(technique);
367
+ return { name: name ?? technique.name, technique };
368
+ };
369
+ return {
370
+ resolveAll: <T extends PoomsaeTechniqueJson>(parts: T[]) =>
371
+ parts.map((part) => ({
372
+ ...resolve(part),
373
+ ...(part.side && { side: part.side }),
374
+ ...("kihap" in part && { kihap: part.kihap as boolean }),
375
+ ...("eyeDir" in part && { eyeDir: part.eyeDir as string }),
376
+ ...("inPlace" in part && { inPlace: part.inPlace as boolean }),
377
+ ...(part.note && { note: part.note }),
378
+ })),
379
+ resolveStance: (stance: PoomsaeStanceJson) => ({
380
+ ...resolve(stance),
381
+ ...(stance.side && { side: stance.side }),
382
+ }),
383
+ };
384
+ }
385
+
386
+ /** Composition has sorted the grades already. */
387
+ private loadBasics(json: Record<string, BasicsLaneJson[]>) {
388
+ for (const [key, lanes] of Object.entries(json)) {
389
+ const grade = parseGrade(key) as Grade;
390
+ const { resolveStance, resolveAll } = this.partResolver(
391
+ `Basics "${key}"`,
392
+ (technique) => {
393
+ technique.basics ??= [];
394
+ if (!technique.basics.includes(grade)) technique.basics.push(grade);
395
+ },
396
+ );
397
+ const resolved = lanes.map(
398
+ ({ steps, start, ...rest }): BasicsLane => ({
399
+ ...rest,
400
+ ...(start && { start: resolveStance(start) }),
401
+ steps: steps.map(({ stance, action, nameOfPoom, note }) => {
402
+ const step: BasicsStep = {};
403
+ if (stance) step.stance = resolveStance(stance);
404
+ if (action) step.action = resolveAll(action);
405
+ if (nameOfPoom) step.nameOfPoom = resolveAll(nameOfPoom);
406
+ if (note) step.note = note;
407
+ return step;
408
+ }),
409
+ }),
410
+ );
411
+ this.basics.set(key, { grade, lanes: resolved });
412
+ }
413
+ }
414
+
342
415
  /**
343
416
  * The diagram must hold every point its lines pass through and every
344
417
  * position; an eye direction may also be a bare direction such as "Ga".
@@ -0,0 +1,63 @@
1
+ import type { Grade } from "../src/grade";
2
+ import type { LocalizedString } from "./localized-string";
3
+ import type {
4
+ PoomsaeStance,
5
+ PoomsaeStanceJson,
6
+ PoomsaeTechnique,
7
+ PoomsaeTechniqueJson,
8
+ } from "./poomsae";
9
+
10
+ /** Where a lane goes; a lane without one stays on the spot. */
11
+ export type BasicsDirection = "forward" | "backward";
12
+
13
+ /** The basics (Grundschule) of one grade: its lanes in order. */
14
+ export interface Basics {
15
+ grade: Grade;
16
+ lanes: BasicsLane[];
17
+ }
18
+
19
+ /** One lane: its steps are repeated along the hall, in one direction. */
20
+ export interface BasicsLane {
21
+ /** Omitted: the lane stays on the spot, e.g. Moaseogi. */
22
+ direction?: BasicsDirection;
23
+ /** The stance each repetition starts in, e.g. Apgubi before Apchagi. */
24
+ start?: PoomsaeStance;
25
+ /** The steps of one repetition, in order. */
26
+ steps: BasicsStep[];
27
+ /** May contain `#[...]` references. */
28
+ note?: LocalizedString;
29
+ }
30
+
31
+ /**
32
+ * One step, like a movement of a Poomsae. Sides are optional; given, they
33
+ * describe the first repetition, which the next one mirrors.
34
+ */
35
+ export interface BasicsStep {
36
+ /** The stance the step ends in. */
37
+ stance?: PoomsaeStance;
38
+ /** The techniques executed on the way, in order, e.g. a kick before landing. */
39
+ action?: PoomsaeTechnique[];
40
+ /** The techniques the step ends with, e.g. a block on landing. */
41
+ nameOfPoom?: PoomsaeTechnique[];
42
+ /** May contain `#[...]` references. */
43
+ note?: LocalizedString;
44
+ }
45
+
46
+ export interface BasicsStepJson {
47
+ stance?: PoomsaeStanceJson;
48
+ action?: PoomsaeTechniqueJson[];
49
+ nameOfPoom?: PoomsaeTechniqueJson[];
50
+ note?: LocalizedString;
51
+ }
52
+
53
+ export interface BasicsLaneJson {
54
+ direction?: BasicsDirection;
55
+ start?: PoomsaeStanceJson;
56
+ steps: BasicsStepJson[];
57
+ note?: LocalizedString;
58
+ }
59
+
60
+ /** Keyed by grade, e.g. `"8-kup"`; string values (`$schema`) are skipped. */
61
+ export interface BasicsJson {
62
+ [grade: string]: BasicsLaneJson[] | string;
63
+ }
@@ -90,7 +90,11 @@ export interface PoomsaeStance {
90
90
  }
91
91
 
92
92
  export interface PoomsaeTechnique {
93
- /** The name the Poomsae uses; may be a variant of the technique, e.g. Ttwieo Yeopchagi for Ttwieochagi. */
93
+ /**
94
+ * The name the Poomsae uses; may be a variant of the technique, e.g. Ttwieo
95
+ * Yeopchagi for Ttwieochagi. May contain `#[...]` references, e.g.
96
+ * "#[apbal|Apbal] #[Yeopchagi]" — `stripRefs` gives the plain name.
97
+ */
94
98
  name: string;
95
99
  /** Missing if the database does not have or did not load it. */
96
100
  technique?: Technique;
@@ -101,6 +105,8 @@ export interface PoomsaeTechnique {
101
105
  * ended. Not part of the Kukkiwon's table.
102
106
  */
103
107
  inPlace?: boolean;
108
+ /** What is special about the technique here; may contain `#[...]` references. */
109
+ note?: LocalizedString;
104
110
  }
105
111
 
106
112
  export interface PoomsaeActionTechnique extends PoomsaeTechnique {
@@ -115,10 +121,14 @@ export interface PoomsaeActionTechnique extends PoomsaeTechnique {
115
121
  type RefOrName = Ref | { name: string };
116
122
 
117
123
  export type PoomsaeStanceJson = RefOrName & { side?: Side };
118
- /** With `$ref`, `name` is a variant the technique covers, e.g. Ttwieo Yeopchagi. */
124
+ /**
125
+ * With `$ref`, `name` is a variant the technique covers, e.g. Ttwieo Yeopchagi.
126
+ * `name` may contain `#[...]` references.
127
+ */
119
128
  export type PoomsaeTechniqueJson = (RefOrName | (Ref & { name: string })) & {
120
129
  side?: Side;
121
130
  inPlace?: boolean;
131
+ note?: LocalizedString;
122
132
  };
123
133
  export type PoomsaeActionTechniqueJson = PoomsaeTechniqueJson & {
124
134
  kihap?: boolean;
@@ -62,6 +62,8 @@ export interface Technique {
62
62
  grade?: Grade;
63
63
  /** Poomsae that use the technique — backlink, populated while loading. */
64
64
  poomsae?: Poomsae[];
65
+ /** Grades whose basics use the technique, lowest first — backlink, populated while loading. */
66
+ basics?: Grade[];
65
67
  }
66
68
 
67
69
  export interface TechniqueReference {
@@ -90,6 +92,7 @@ export interface TechniqueJson
90
92
  | "sources"
91
93
  | "grade"
92
94
  | "poomsae"
95
+ | "basics"
93
96
  > {
94
97
  terms: Ref[];
95
98
  references?: TechniqueReferenceJson[];
File without changes