@skmtc/core 0.0.333 → 0.0.334

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.
Files changed (37) hide show
  1. package/esm/context/GenerateContext.d.ts +12 -4
  2. package/esm/context/GenerateContext.d.ts.map +1 -1
  3. package/esm/context/GenerateContext.js +57 -31
  4. package/esm/dsl/ModelDriver.d.ts +1 -2
  5. package/esm/dsl/ModelDriver.d.ts.map +1 -1
  6. package/esm/dsl/ModelDriver.js +2 -19
  7. package/esm/dsl/OperationDriver.d.ts +1 -2
  8. package/esm/dsl/OperationDriver.d.ts.map +1 -1
  9. package/esm/dsl/OperationDriver.js +2 -20
  10. package/esm/dsl/ValueBase.d.ts +2 -2
  11. package/esm/dsl/ValueBase.d.ts.map +1 -1
  12. package/esm/dsl/ValueBase.js +2 -3
  13. package/esm/dsl/withConfig.d.ts +2 -2
  14. package/esm/types/GeneratedValue.d.ts +1 -1
  15. package/esm/types/GeneratedValue.d.ts.map +1 -1
  16. package/esm/typescript/List.d.ts +70 -3
  17. package/esm/typescript/List.d.ts.map +1 -1
  18. package/esm/typescript/List.js +94 -6
  19. package/package.json +1 -1
  20. package/script/context/GenerateContext.d.ts +12 -4
  21. package/script/context/GenerateContext.d.ts.map +1 -1
  22. package/script/context/GenerateContext.js +57 -31
  23. package/script/dsl/ModelDriver.d.ts +1 -2
  24. package/script/dsl/ModelDriver.d.ts.map +1 -1
  25. package/script/dsl/ModelDriver.js +2 -19
  26. package/script/dsl/OperationDriver.d.ts +1 -2
  27. package/script/dsl/OperationDriver.d.ts.map +1 -1
  28. package/script/dsl/OperationDriver.js +2 -20
  29. package/script/dsl/ValueBase.d.ts +2 -2
  30. package/script/dsl/ValueBase.d.ts.map +1 -1
  31. package/script/dsl/ValueBase.js +2 -3
  32. package/script/dsl/withConfig.d.ts +2 -2
  33. package/script/types/GeneratedValue.d.ts +1 -1
  34. package/script/types/GeneratedValue.d.ts.map +1 -1
  35. package/script/typescript/List.d.ts +70 -3
  36. package/script/typescript/List.d.ts.map +1 -1
  37. package/script/typescript/List.js +94 -6
@@ -32,29 +32,75 @@ class List {
32
32
  .with('square', () => `[${joined}]`)
33
33
  .with('curly', () => `{${joined}}`)
34
34
  .with('round', () => `(${joined})`)
35
+ .with('angle', () => `<${joined}>`)
35
36
  .with('none', () => joined)
36
37
  .exhaustive();
37
38
  }
38
39
  }
39
40
  exports.List = List;
41
+ /**
42
+ * Create an empty List that will render as an empty string ''
43
+ * @returns List
44
+ */
40
45
  Object.defineProperty(List, "toEmpty", {
41
46
  enumerable: true,
42
47
  configurable: true,
43
48
  writable: true,
44
49
  value: () => new List([], { bookends: 'none' })
45
50
  });
51
+ /**
52
+ * Create a List with a single value that will render as `value`
53
+ * @param value
54
+ * @returns List
55
+ */
46
56
  Object.defineProperty(List, "toSingle", {
47
57
  enumerable: true,
48
58
  configurable: true,
49
59
  writable: true,
50
- value: (value) => new List([value], { bookends: 'none' })
60
+ value: (value) => {
61
+ return new List([value], { bookends: 'none' });
62
+ }
51
63
  });
52
- Object.defineProperty(List, "toOptional", {
64
+ /**
65
+ * If condition is true, return a List with a single value that will render as `value`.
66
+ * Otherwise, return an empty List that will render as an empty string ''.
67
+ *
68
+ * Useful for conditional rendering. For example, rendering a function arg object when
69
+ * it has at least one property.
70
+ * @param value
71
+ * @param condition
72
+ * @returns List
73
+ */
74
+ Object.defineProperty(List, "toConditional", {
53
75
  enumerable: true,
54
76
  configurable: true,
55
77
  writable: true,
56
- value: (value, condition) => new List([condition ? value : undefined])
78
+ value: (value, condition) => {
79
+ return new List([condition ? value : undefined], { bookends: 'none' });
80
+ }
57
81
  });
82
+ /**
83
+ * Create a record with Stringable values. KeyValue pairs will be joined with `: ` as separator
84
+ * and the resulting List will be wrapped with `{}`
85
+ * @param record
86
+ * @returns `record` with `Stringable` values
87
+ */
88
+ Object.defineProperty(List, "toRecord", {
89
+ enumerable: true,
90
+ configurable: true,
91
+ writable: true,
92
+ value: (record) => {
93
+ const entries = Object.entries(record).map(([key, value]) => {
94
+ return List.toKeyValue(key, value);
95
+ });
96
+ return List.toObject(entries);
97
+ }
98
+ });
99
+ /**
100
+ * Create a record with `undefined` or empty array or List values filtered out.
101
+ * @param record
102
+ * @returns `record` with `undefined` values filtered out
103
+ */
58
104
  Object.defineProperty(List, "toFilteredRecord", {
59
105
  enumerable: true,
60
106
  configurable: true,
@@ -66,24 +112,52 @@ Object.defineProperty(List, "toFilteredRecord", {
66
112
  return List.toObject(entries);
67
113
  }
68
114
  });
115
+ /**
116
+ * Join `key` and `value` using `: ` as separator
117
+ * @param key
118
+ * @param value
119
+ * @returns `key` and `value` joined with `: ` as separator
120
+ */
69
121
  Object.defineProperty(List, "toKeyValue", {
70
122
  enumerable: true,
71
123
  configurable: true,
72
124
  writable: true,
73
- value: (key, value) => new List([key, value], { separator: ': ' })
125
+ value: (key, value) => {
126
+ return new List([key, value], { separator: ': ' });
127
+ }
74
128
  });
129
+ /**
130
+ * Join `key` and `value` using `.` as separator
131
+ * @param key
132
+ * @param value
133
+ * @returns `key` and `value` joined with `.` as separator
134
+ */
75
135
  Object.defineProperty(List, "toObjectKey", {
76
136
  enumerable: true,
77
137
  configurable: true,
78
138
  writable: true,
79
- value: (key, value) => new List([key, value], { separator: '.' })
139
+ value: (key, value) => {
140
+ return new List([key, value], { separator: '.' });
141
+ }
80
142
  });
143
+ /**
144
+ * Join `values` using `, ` as separator and wrap in `{` and `}`
145
+ * @param values
146
+ * @returns `values` joined with `, ` as separator and wrapped in `{` and `}`
147
+ */
81
148
  Object.defineProperty(List, "toObject", {
82
149
  enumerable: true,
83
150
  configurable: true,
84
151
  writable: true,
85
- value: (values) => new List(values, { bookends: 'curly' })
152
+ value: (values) => {
153
+ return new List(values, { bookends: 'curly' });
154
+ }
86
155
  });
156
+ /**
157
+ * Create a List using the keys of a record
158
+ * @param record
159
+ * @returns List of record keys
160
+ */
87
161
  Object.defineProperty(List, "fromRecord", {
88
162
  enumerable: true,
89
163
  configurable: true,
@@ -92,6 +166,15 @@ Object.defineProperty(List, "fromRecord", {
92
166
  return new List(Object.keys(record ?? {}));
93
167
  }
94
168
  });
169
+ /**
170
+ * Create a keyValue pair if `value` is not undefined and is not an empty array or List.
171
+ * Return `undefined` otherwise.
172
+ *
173
+ * Useful for filtering out `undefined values from a record.
174
+ * @param key
175
+ * @param value
176
+ * @returns `key` and `value` joined with `: ` as separator if `value` is not undefined and is not an empty array or List. `undefined` otherwise.
177
+ */
95
178
  Object.defineProperty(List, "toFilteredKeyValue", {
96
179
  enumerable: true,
97
180
  configurable: true,
@@ -100,6 +183,11 @@ Object.defineProperty(List, "toFilteredKeyValue", {
100
183
  return List.hasValue(value) ? List.toKeyValue(key, value) : undefined;
101
184
  }
102
185
  });
186
+ /**
187
+ * Check if `value` is not undefined and is not an empty array or List.
188
+ * @param value
189
+ * @returns `true` if `value` is not undefined and is not an empty array or List. `false` otherwise.
190
+ */
103
191
  Object.defineProperty(List, "hasValue", {
104
192
  enumerable: true,
105
193
  configurable: true,