@chrismo/superkit 1.0.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.
Files changed (74) hide show
  1. package/LICENSE.txt +29 -0
  2. package/README.md +26 -0
  3. package/dist/cli/pager.d.ts +6 -0
  4. package/dist/cli/pager.d.ts.map +1 -0
  5. package/dist/cli/pager.js +21 -0
  6. package/dist/cli/pager.js.map +1 -0
  7. package/dist/cli/skdoc.d.ts +3 -0
  8. package/dist/cli/skdoc.d.ts.map +1 -0
  9. package/dist/cli/skdoc.js +42 -0
  10. package/dist/cli/skdoc.js.map +1 -0
  11. package/dist/cli/skgrok.d.ts +3 -0
  12. package/dist/cli/skgrok.d.ts.map +1 -0
  13. package/dist/cli/skgrok.js +21 -0
  14. package/dist/cli/skgrok.js.map +1 -0
  15. package/dist/cli/skops.d.ts +3 -0
  16. package/dist/cli/skops.d.ts.map +1 -0
  17. package/dist/cli/skops.js +32 -0
  18. package/dist/cli/skops.js.map +1 -0
  19. package/dist/index.d.ts +10 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +11 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/lib/docs.d.ts +11 -0
  24. package/dist/lib/docs.d.ts.map +1 -0
  25. package/dist/lib/docs.js +29 -0
  26. package/dist/lib/docs.js.map +1 -0
  27. package/dist/lib/expert-sections.d.ts +32 -0
  28. package/dist/lib/expert-sections.d.ts.map +1 -0
  29. package/dist/lib/expert-sections.js +130 -0
  30. package/dist/lib/expert-sections.js.map +1 -0
  31. package/dist/lib/grok.d.ts +15 -0
  32. package/dist/lib/grok.d.ts.map +1 -0
  33. package/dist/lib/grok.js +57 -0
  34. package/dist/lib/grok.js.map +1 -0
  35. package/dist/lib/help.d.ts +20 -0
  36. package/dist/lib/help.d.ts.map +1 -0
  37. package/dist/lib/help.js +163 -0
  38. package/dist/lib/help.js.map +1 -0
  39. package/dist/lib/recipes.d.ts +29 -0
  40. package/dist/lib/recipes.d.ts.map +1 -0
  41. package/dist/lib/recipes.js +133 -0
  42. package/dist/lib/recipes.js.map +1 -0
  43. package/dist/superkit.tar.gz +0 -0
  44. package/docs/grok-patterns.sup +89 -0
  45. package/docs/recipes/array.md +66 -0
  46. package/docs/recipes/array.spq +31 -0
  47. package/docs/recipes/character.md +110 -0
  48. package/docs/recipes/character.spq +57 -0
  49. package/docs/recipes/escape.md +159 -0
  50. package/docs/recipes/escape.spq +102 -0
  51. package/docs/recipes/format.md +51 -0
  52. package/docs/recipes/format.spq +24 -0
  53. package/docs/recipes/index.md +23 -0
  54. package/docs/recipes/integer.md +101 -0
  55. package/docs/recipes/integer.spq +53 -0
  56. package/docs/recipes/records.md +84 -0
  57. package/docs/recipes/records.spq +61 -0
  58. package/docs/recipes/string.md +177 -0
  59. package/docs/recipes/string.spq +105 -0
  60. package/docs/superdb-expert.md +929 -0
  61. package/docs/tutorials/bash_to_sup.md +123 -0
  62. package/docs/tutorials/chess-tiebreaks.md +233 -0
  63. package/docs/tutorials/debug.md +439 -0
  64. package/docs/tutorials/fork_for_window.md +296 -0
  65. package/docs/tutorials/grok.md +166 -0
  66. package/docs/tutorials/index.md +10 -0
  67. package/docs/tutorials/joins.md +79 -0
  68. package/docs/tutorials/moar_subqueries.md +35 -0
  69. package/docs/tutorials/subqueries.md +236 -0
  70. package/docs/tutorials/sup_to_bash.md +164 -0
  71. package/docs/tutorials/super_db_update.md +34 -0
  72. package/docs/tutorials/unnest.md +113 -0
  73. package/docs/zq-to-super-upgrades.md +549 -0
  74. package/package.json +46 -0
@@ -0,0 +1,61 @@
1
+ -- sk_include array.spq
2
+
3
+ -- the built-in `fields` function is similar, but puts each field into its own
4
+ -- nested array, though it also handles nested keys. This keys operator here
5
+ -- attempts to emulate jq's keys, which does not go deep but only lists the
6
+ -- top-level ones.
7
+
8
+ fn skdoc_keys(): (
9
+ cast(
10
+ {name:"sk_keys",
11
+ type:"op",
12
+ desc:"Returns the keys of the top-level fields in a record. This does not go deep into nested records.",
13
+ args:[],
14
+ examples:[{i:"{a:1,b:{c:333}} | sk_keys",o:"['a','b']"}
15
+ {i:"{x:10,y:20,z:30} | sk_keys",o:"['x','y','z']"}] }, <skdoc>)
16
+ )
17
+
18
+ op sk_keys: (
19
+ fields(this) | unnest this | values this[0] | uniq | collect(this)
20
+ )
21
+
22
+ fn skdoc_merge_records(): (
23
+ cast(
24
+ {name:"sk_merge_records",
25
+ type:"op",
26
+ desc:"Merges an array of records into a single record by combining the fields. If there are duplicate keys, the last one wins.",
27
+ args:[],
28
+ examples:[{i:"[{a:1},{b:{c:333}}] | sk_merge_records",o:"{a:1,b:{c:333}}"}] }, <skdoc>)
29
+ )
30
+
31
+ op sk_merge_records: (
32
+ this::string
33
+ | replace(this, "},{" ",")
34
+ | parse_sup(this[1:-1])
35
+ )
36
+
37
+ -- # this sort of approach suffers from an illegal left-hand assignment:
38
+ -- ❯ zq '[{a:1},{b:{c:333}}] | (over this with obj={} | flatten(this) | obj[key[0]]:=value )'
39
+
40
+ -- # this was a better step from Phil, but doesn't work on nested records
41
+ -- over this
42
+ -- | over flatten(this)
43
+ -- | collect_map(|{key[0]:value}|)
44
+ -- | values parse_sup(replace(this::string, "|", ""))'
45
+
46
+ fn skdoc_add_ids(): (
47
+ cast(
48
+ {name:"sk_add_ids",
49
+ type:"op",
50
+ desc:"Prepends an incrementing id field to each record. Always returns an array.",
51
+ args:[],
52
+ examples:[{i:"[{a:3},{b:4}] | sk_add_ids",o:"[{id:1,a:3},{id:2,b:4}]"}] }, <skdoc>)
53
+ )
54
+
55
+ op sk_add_ids: (
56
+ sk_in_array(this)
57
+ | unnest this
58
+ | count
59
+ | values {id:count,...that}
60
+ | collect(this)
61
+ )
@@ -0,0 +1,177 @@
1
+ ---
2
+ title: String
3
+ layout: default
4
+ nav_order: 1
5
+ parent: Recipes
6
+ ---
7
+
8
+ # String Recipes
9
+
10
+ Source: `string.spq` (includes `integer.spq`)
11
+
12
+ ---
13
+
14
+ ## sk_slice
15
+
16
+ Returns a slice of the string passed in, even if indexes are out of range.
17
+
18
+ **Type:** function
19
+
20
+ | Argument | Description |
21
+ |----------|-------------|
22
+ | `s` | The string to slice. |
23
+ | `start` | Starting index, zero-based, inclusive. |
24
+ | `end` | Ending index, exclusive. |
25
+
26
+ ```supersql
27
+ sk_slice('howdy')
28
+ -- => 'Howdy'
29
+ ```
30
+
31
+ **Implementation:**
32
+
33
+ ```supersql
34
+ fn sk_slice(s, start, end): (
35
+ s[sk_clamp(start, -len(s), len(s)):sk_clamp(end, -len(s), len(s))]
36
+ )
37
+ ```
38
+
39
+ ---
40
+
41
+ ## sk_capitalize
42
+
43
+ Upper the first character of the string, lower the remaining string.
44
+
45
+ **Type:** function
46
+
47
+ | Argument | Description |
48
+ |----------|-------------|
49
+ | `s` | The string to capitalize. |
50
+
51
+ ```supersql
52
+ sk_capitalize('hoWDy')
53
+ -- => 'Howdy'
54
+ ```
55
+
56
+ **Implementation:**
57
+
58
+ ```supersql
59
+ fn sk_capitalize(s): (
60
+ f"{upper(sk_slice(s, 0, 1))}{lower(sk_slice(s,1,len(s)))}"
61
+ )
62
+ ```
63
+
64
+ ---
65
+
66
+ ## sk_titleize
67
+
68
+ Splits string by space and capitalizes each word.
69
+
70
+ **Type:** function
71
+
72
+ | Argument | Description |
73
+ |----------|-------------|
74
+ | `s` | The string to titleize |
75
+
76
+ ```supersql
77
+ sk_titleize('once uPON A TIME')
78
+ -- => 'Once Upon A Time'
79
+ ```
80
+
81
+ **Implementation:**
82
+
83
+ ```supersql
84
+ fn sk_titleize(s): (
85
+ [unnest split(s, " ") | values sk_capitalize(this)] | join(this, " ")
86
+ )
87
+ ```
88
+
89
+ ---
90
+
91
+ ## sk_pad_left
92
+
93
+ Inserts pad_char to the left of the string until it reaches target_length.
94
+
95
+ **Type:** function
96
+
97
+ | Argument | Description |
98
+ |----------|-------------|
99
+ | `s` | The string to pad |
100
+ | `pad_char` | The character to pad with |
101
+ | `target_length` | The target length of the string |
102
+
103
+ ```supersql
104
+ values sk_pad_left('abc', ' ', 5)
105
+ -- => ' abc'
106
+ ```
107
+
108
+ **Implementation:**
109
+
110
+ ```supersql
111
+ fn sk_pad_left(s, pad_char, target_length): (
112
+ len(s) < target_length ? sk_pad_left(f'{pad_char}{s}', pad_char, target_length) : s
113
+ )
114
+ ```
115
+
116
+ ---
117
+
118
+ ## sk_pad_right
119
+
120
+ Inserts pad_char to the right of the string until it reaches target_length.
121
+
122
+ **Type:** function
123
+
124
+ | Argument | Description |
125
+ |----------|-------------|
126
+ | `s` | The string to pad |
127
+ | `pad_char` | The character to pad with |
128
+ | `target_length` | The target length of the string |
129
+
130
+ ```supersql
131
+ values sk_pad_right('abc', ' ', 5)
132
+ -- => 'abc '
133
+ ```
134
+
135
+ **Implementation:**
136
+
137
+ ```supersql
138
+ fn sk_pad_right(s, pad_char, target_length): (
139
+ len(s) < target_length ? sk_pad_right(f'{s}{pad_char}', pad_char, target_length) : s
140
+ )
141
+ ```
142
+
143
+ ---
144
+
145
+ ## sk_urldecode
146
+
147
+ URL decoder for SuperDB. Splits on `%`, decodes each hex-encoded segment, and joins back together.
148
+
149
+ **Type:** operator
150
+
151
+ | Argument | Description |
152
+ |----------|-------------|
153
+ | `url` | The URL-encoded string to decode |
154
+
155
+ ```bash
156
+ super -I string.spq -s -c 'values sk_urldecode("%2Ftavern%20test")' -
157
+ ```
158
+
159
+ **Implementation:**
160
+
161
+ ```supersql
162
+ op sk_decode_seg s: (
163
+ len(s) == 0
164
+ ? s
165
+ : (is_error(hex(s[1:3]))
166
+ ? s
167
+ : hex(s[1:3])::string + s[3:])
168
+ )
169
+
170
+ op sk_urldecode url: (
171
+ split(url, "%")
172
+ | unnest this
173
+ | decode_seg this
174
+ | collect(this)
175
+ | join(this, "")
176
+ )
177
+ ```
@@ -0,0 +1,105 @@
1
+ -- sk_include integer.spq
2
+ -- sk_include integer.spq -- to test duplicate includes
3
+
4
+ op skdoc_slice: (
5
+ cast(
6
+ {name:"sk_slice",
7
+ type:"func",
8
+ desc:"Returns a slice of the string passed in, even if indexes are out of range.",
9
+ args:[{name:"s",desc:"The string to slice."}
10
+ {name:"start",desc:"Starting index, zero-based, inclusive."}
11
+ {name:"end",desc:"Ending index, exclusive."}],
12
+ examples:[{i:"sk_slice('howdy')",o:"'Howdy'"}] }, <skdoc>)
13
+ )
14
+
15
+ -- This isn't necessary with zq, but during early releases of super, the
16
+ -- behavior of slice was changed to return an error if the indexes are out of
17
+ -- range. There was discussion of possibly returning to the old behavior.
18
+ fn sk_slice(s, start, end): (
19
+ s[sk_clamp(start, -len(s), len(s)):sk_clamp(end, -len(s), len(s))]
20
+ )
21
+
22
+ op skdoc_capitalize: (
23
+ cast(
24
+ {name:"sk_capitalize",
25
+ type:"func",
26
+ desc:"Upper the first character of the string, lower the remaining string.",
27
+ args:[{name:"s",desc:"The string to capitalize."}],
28
+ examples:[{i:"sk_capitalize('hoWDy')",o:"'Howdy'"}] }, <skdoc>)
29
+ )
30
+
31
+ fn sk_capitalize(s): (
32
+ f"{upper(sk_slice(s, 0, 1))}{lower(sk_slice(s,1,len(s)))}"
33
+ )
34
+
35
+ op skdoc_titleize: (
36
+ cast(
37
+ {name:"sk_titleize",
38
+ type:"func",
39
+ desc:"Splits string by space and capitalizes each word.",
40
+ args:[{name:"s",desc:"The string to titleize"}],
41
+ examples:[{i:"sk_titleize('once uPON A TIME')",o:"'Once Upon A Time'"}] }, <skdoc>)
42
+ )
43
+
44
+ fn sk_titleize(s): (
45
+ -- this could be smarter, ignoring insignificant words
46
+ -- and such, but that will be a lot more complex.
47
+ [unnest split(s, " ") | values sk_capitalize(this)] | join(this, " ")
48
+ )
49
+
50
+ fn skdoc_pad_left(): (
51
+ cast(
52
+ {name:"sk_pad_left",
53
+ type:"func",
54
+ desc:"Inserts pad_char to the left of the string until it reaches target_length.",
55
+ args:[{name:"s",desc:"The string to pad"}
56
+ {name:"pad_char",desc:"The character to pad with"}
57
+ {name:"target_length",desc:"The target length of the string"}],
58
+ examples:[{i:"values sk_pad_left('abc', ' ', 5)",o:"' abc'"}] }, <skdoc>)
59
+ )
60
+
61
+ fn sk_pad_left(s, pad_char, target_length): (
62
+ len(s) < target_length ? sk_pad_left(f'{pad_char}{s}', pad_char, target_length) : s
63
+ )
64
+
65
+ fn skdoc_pad_right(): (
66
+ cast(
67
+ {name:"sk_pad_right",
68
+ type:"func",
69
+ desc:"Inserts pad_char to the right of the string until it reaches target_length.",
70
+ args:[{name:"s",desc:"The string to pad"}
71
+ {name:"pad_char",desc:"The character to pad with"}
72
+ {name:"target_length",desc:"The target length of the string"}],
73
+ examples:[{i:"values sk_pad_right('abc', ' ', 5)",o:"'abc '"}] }, <skdoc>)
74
+ )
75
+
76
+ fn sk_pad_right(s, pad_char, target_length): (
77
+ len(s) < target_length ? sk_pad_right(f'{s}{pad_char}', pad_char, target_length) : s
78
+ )
79
+
80
+ -- TODO: skdoc_urldecode
81
+
82
+ -- URL Decoder for SuperDB
83
+ -- Usage: super -I urldecode.spq -s -c 'values sk_urldecode(this)' - <<< '"%%2Ftavern%%20test"'
84
+ -- Or inline the definitions in your query
85
+
86
+ -- Helper operator to decode a single segment after splitting on %%
87
+ -- If the segment starts with valid 2-char hex, converts it to the character
88
+ -- Otherwise returns the segment as-is
89
+ op sk_decode_seg s: (
90
+ len(s) == 0
91
+ ? s
92
+ : (is_error(hex(s[1:3]))
93
+ ? s
94
+ : hex(s[1:3])::string + s[3:])
95
+ )
96
+
97
+ -- Main URL decoder operator
98
+ -- Splits on %%, decodes each hex-encoded segment, and joins back together
99
+ op sk_urldecode url: (
100
+ split(url, "%%")
101
+ | unnest this
102
+ | sk_decode_seg this
103
+ | collect(this)
104
+ | join(this, "")
105
+ )