@sealcode/jdd 0.8.0 → 0.8.2

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.
@@ -1,111 +0,0 @@
1
- import { is, predicates } from "@sealcode/ts-predicates";
2
- import { ContainerArgument } from "./container-argument.js";
3
- import { Enum } from "./enum.js";
4
- export class Component extends ContainerArgument {
5
- constructor(registry) {
6
- super();
7
- this.registry = registry;
8
- }
9
- getTypeName() {
10
- return "structured";
11
- }
12
- getStructure(component_name) {
13
- return this.registry.get(component_name)?.getArguments() || {};
14
- }
15
- getSubArgument([key, ...rest], value
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- ) {
18
- if (key == "component_name") {
19
- const dropdown = new Enum(Object.keys(this.registry.getAll()));
20
- dropdown.parent_argument = this;
21
- return [dropdown, rest, {}];
22
- }
23
- // the other key in the path can only be the component name + a colon:
24
- if (key.endsWith(":values")) {
25
- const component_name = key.replace(":values", "");
26
- return [
27
- this.getStructure(component_name)[key] || null,
28
- rest,
29
- value[key],
30
- ];
31
- }
32
- // invalid argument
33
- console.error("Invalid argument for component jdd arg:", key, rest, value);
34
- return [null, [], {}];
35
- }
36
- countWords(value) {
37
- const component_name = value.component_name;
38
- const component_values = value[`${component_name}:values`];
39
- return Object.entries(component_values).reduce((acc, [key, val]) => {
40
- if (!this.getStructure(component_name)[key]) {
41
- console.warn(`Key ${key} doesn't exist in structured argument`);
42
- return acc + 0;
43
- }
44
- return acc + this.getStructure(component_name)[key].countWords(val);
45
- }, 0);
46
- }
47
- async getEmptyValue(context) {
48
- const component_name = Object.keys(this.registry.getAll())[0];
49
- return Object.fromEntries(await Promise.all(Object.entries(this.getStructure(component_name)).map(async ([name, arg]) => [
50
- name,
51
- await arg.getEmptyValue(context),
52
- ])));
53
- }
54
- async getExampleValue(context) {
55
- const component_name = Object.keys(this.registry.getAll())[0];
56
- if (this.example_values.length) {
57
- return super.getExampleValue(context);
58
- }
59
- return Object.fromEntries(await Promise.all(Object.entries(this.getStructure(component_name)).map(async ([name, arg]) => [
60
- name,
61
- await arg.getExampleValue(context),
62
- ])));
63
- }
64
- async processAllSubarguments(_context, input, processing_function) {
65
- if (!is(input, predicates.object)) {
66
- throw new Error(`Not an object: ${input}`);
67
- }
68
- const component_name = input.component_name;
69
- const result = {};
70
- await Promise.all(Object.entries(input).map(async ([obj_key, obj_value]) => {
71
- const nested_arg_type = this.getStructure(component_name)[obj_key];
72
- if (!nested_arg_type) {
73
- return [obj_key, null];
74
- }
75
- const new_value = await processing_function(nested_arg_type, obj_value);
76
- result[obj_key] = new_value;
77
- }));
78
- // if we're in a list and any of the values return an array, we will multiply the object
79
- if (this.hasParent("list")) {
80
- const keys_with_unexpected_arrays = Object.entries(result)
81
- .filter(([key, value]) => {
82
- const nested_arg_type = this.getStructure(component_name)[key];
83
- return (nested_arg_type.getTypeName() !== "list" &&
84
- Array.isArray(value));
85
- })
86
- .map(([key]) => key);
87
- if (keys_with_unexpected_arrays.length > 1) {
88
- throw new Error("Multiplying on more than one field at the same time is not implemented yet");
89
- }
90
- if (keys_with_unexpected_arrays.length == 1) {
91
- const key = keys_with_unexpected_arrays[0];
92
- const old_result = result;
93
- const array = old_result[key];
94
- if (!Array.isArray(array)) {
95
- throw new Error("expected an array");
96
- }
97
- return array.map((value) => ({
98
- ...old_result,
99
- [key]: value,
100
- }));
101
- }
102
- else {
103
- return result;
104
- }
105
- }
106
- else {
107
- return result;
108
- }
109
- }
110
- }
111
- //# sourceMappingURL=component.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/component-arguments/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,MAAM,OAAO,SAAU,SAAQ,iBAG9B;I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;gBACxB,MAAM,eAAe,GACpB,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC;gBACxC,OAAO,CACN,eAAe,CAAC,WAAW,EAAE,KAAK,MAAM;oBACxC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CACpB,CAAC;YACH,CAAC,CAAC;iBACD,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;YAEtB,IAAI,2BAA2B,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC3C,MAAM,IAAI,KAAK,CACd,4EAA4E,CAC5E,CAAC;aACF;YACD,IAAI,2BAA2B,CAAC,MAAM,IAAI,CAAC,EAAE;gBAC5C,MAAM,GAAG,GAAG,2BAA2B,CAAC,CAAC,CAAC,CAAC;gBAC3C,MAAM,UAAU,GAAG,MAAM,CAAC;gBAC1B,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;gBAC9B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;oBAC1B,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;iBACrC;gBAED,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,KAAc,EAAE,EAAE,CAAC,CAAC;oBACrC,GAAG,UAAU;oBACb,CAAC,GAAG,CAAC,EAAE,KAAK;iBACZ,CAAC,CAAC,CAAC;aACJ;iBAAM;gBACN,OAAO,MAAM,CAAC;aACd;SACD;aAAM;YACN,OAAO,MAAM,CAAC;SACd;IACF,CAAC;CACD"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=newFile.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"newFile.js","sourceRoot":"","sources":["../../src/component-arguments/newFile.ts"],"names":[],"mappings":""}
package/lib/h-test.js DELETED
@@ -1,13 +0,0 @@
1
- import hyphenopoly from "hyphenopoly";
2
- import { resolve } from "node:path";
3
- import { readFile } from "node:fs/promises";
4
- import { fileURLToPath } from "node:url";
5
- const hyphenate = await hyphenopoly.config({
6
- require: ["en-us"],
7
- sync: false,
8
- loader: async (file, module_path) => {
9
- return readFile(resolve(fileURLToPath(module_path), `../patterns/${file}`));
10
- },
11
- });
12
- console.log(hyphenate("hyphenation **enhances** justification"));
13
- //# sourceMappingURL=h-test.js.map
package/lib/h-test.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"h-test.js","sourceRoot":"","sources":["../src/h-test.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC;IAC1C,OAAO,EAAE,CAAC,OAAO,CAAC;IAClB,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,KAAK,EAAE,IAAY,EAAE,WAAgB,EAAE,EAAE;QAChD,OAAO,QAAQ,CACd,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,eAAe,IAAI,EAAE,CAAC,CAC1D,CAAC;IACH,CAAC;CACD,CAAC,CAAC;AAEH,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,wCAAwC,CAAC,CAAC,CAAC"}