@sanity/runtime-cli 16.0.3 → 17.1.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 (41) hide show
  1. package/README.md +27 -22
  2. package/dist/actions/functions/test.js +1 -1
  3. package/dist/baseCommands.js +13 -2
  4. package/dist/commands/blueprints/init.js +5 -2
  5. package/dist/config.d.ts +1 -0
  6. package/dist/config.js +7 -1
  7. package/dist/constants.d.ts +1 -0
  8. package/dist/constants.js +1 -0
  9. package/dist/cores/blueprints/init.js +16 -2
  10. package/dist/cores/functions/test.js +44 -0
  11. package/dist/server/app.js +31 -3
  12. package/dist/server/handlers/invoke.d.ts +2 -2
  13. package/dist/server/handlers/invoke.js +7 -4
  14. package/dist/server/static/components/console-panel.js +59 -8
  15. package/dist/server/static/components/rule-panel.js +11 -8
  16. package/dist/server/static/components/shared-styles.js +24 -21
  17. package/dist/server/static/index.html +1 -1
  18. package/dist/server/static/vendor/design-tokens/color.css +48 -48
  19. package/dist/server/static/vendor/design-tokens/index.css +0 -1
  20. package/dist/server/static/vendor/vendor.bundle.js +3807 -3259
  21. package/dist/server/static/web-socket.js +41 -0
  22. package/dist/utils/functions/child-process-wrapper.js +62 -7
  23. package/dist/utils/functions/{invoke-local.d.ts → invoke/local.d.ts} +1 -1
  24. package/dist/utils/functions/invoke/local.js +306 -0
  25. package/dist/utils/functions/invoke/nested.d.ts +25 -0
  26. package/dist/utils/functions/invoke/nested.js +41 -0
  27. package/dist/utils/functions/invoke/prepare.d.ts +20 -0
  28. package/dist/utils/functions/invoke/prepare.js +90 -0
  29. package/dist/utils/interactive.d.ts +1 -0
  30. package/dist/utils/interactive.js +4 -0
  31. package/dist/utils/isTrueish.d.ts +6 -0
  32. package/dist/utils/isTrueish.js +9 -0
  33. package/dist/utils/logger.d.ts +1 -0
  34. package/dist/utils/logger.js +1 -0
  35. package/dist/utils/style-text.js +4 -5
  36. package/dist/utils/traced-fetch.js +2 -0
  37. package/dist/utils/types.d.ts +62 -4
  38. package/oclif.manifest.json +928 -927
  39. package/package.json +18 -14
  40. package/dist/server/static/hot-reload.js +0 -16
  41. package/dist/utils/functions/invoke-local.js +0 -185
@@ -1,4 +1,4 @@
1
- /* globals customElements document */
1
+ /* globals customElements document window */
2
2
  import {ApiBaseElement} from './api-base.js'
3
3
  import {getSharedStyleSheets} from './shared-styles.js'
4
4
 
@@ -36,6 +36,16 @@ template.innerHTML = `
36
36
  `
37
37
 
38
38
  class ConsolePanel extends ApiBaseElement {
39
+ /**
40
+ * Nested context.invoke() output for the current run, kept as a list so the
41
+ * final render can order it by call order. Nested runs finish innermost-first
42
+ * (A → B → C resolves C then B), so each carries an `order` stamped when it was
43
+ * initiated; the final render sorts by it. Buffered separately so it survives
44
+ * the result render, which would otherwise overwrite the console when Preserve
45
+ * Log is off.
46
+ */
47
+ nestedEntries = []
48
+
39
49
  constructor() {
40
50
  super()
41
51
  this.attachShadow({mode: 'open'}).appendChild(template.content.cloneNode(true))
@@ -45,25 +55,59 @@ class ConsolePanel extends ApiBaseElement {
45
55
  if (!this.consoleOutput || !result) return
46
56
 
47
57
  const {error, logs} = result
48
- let update = ''
58
+ // Always show the logs. Then append the error, rather than replacing the logs with it.
59
+ let update = logs ?? ''
49
60
  if (error) {
50
- // Display error details in the console
51
- update = (error.stack || error.message || error.name) ?? 'An error occurred.'
52
- } else {
53
- // Display regular logs
54
- update = logs ?? '' // Handle case where logs might be null/undefined
61
+ const errText = (error.stack || error.message || error.name) ?? 'An error occurred.'
62
+ update = update.trim() ? `${update.trimEnd()}\n${errText}` : errText
55
63
  }
56
64
 
57
65
  if (this.api.store.preserveLog) {
66
+ // Nested output was already appended live during the run; keep it in place.
58
67
  this.consoleOutput.innerText = this.consoleOutput.innerText + update
59
68
  } else {
60
- this.consoleOutput.innerText = update
69
+ // Re-render so the nested output is shown in call order rather than the
70
+ // completion order it streamed in (and so it survives this overwrite).
71
+ this.consoleOutput.innerText = update + this.renderNestedEntries()
72
+ }
73
+ }
74
+
75
+ // Join the nested runs in call order (the order they were initiated).
76
+ renderNestedEntries = () =>
77
+ [...this.nestedEntries]
78
+ .sort((a, b) => a.order - b.order)
79
+ .map((e) => e.text)
80
+ .join('')
81
+
82
+ updateNested = (event) => {
83
+ const nestedInvoke = event.detail
84
+ if (!this.consoleOutput || !nestedInvoke) return
85
+
86
+ const {name, order, logs, json, error} = nestedInvoke
87
+ // Always show the logs. Then append the error, rather than replacing the logs with it.
88
+ let body = logs ?? ''
89
+ if (error) {
90
+ const errText = (error.stack || error.message || error.name) ?? 'An error occurred.'
91
+ body = body.trim() ? `${body.trimEnd()}\n${errText}` : errText
92
+ } else if (typeof json !== 'undefined') {
93
+ body += `${body && !body.endsWith('\n') ? '\n' : ''}→ returned ${JSON.stringify(json)}\n`
61
94
  }
95
+
96
+ const text = `↳ BEGIN: invoke('${name}')\n${body.trim()}\n↳ END: invoke('${name}')\n`
97
+ this.nestedEntries.push({order, text})
98
+ // Append live for immediate feedback; the final result render reorders.
99
+ this.consoleOutput.innerText = this.consoleOutput.innerText + text
100
+ }
101
+
102
+ // A new invocation is starting; drop the previous run's nested output.
103
+ resetNested = ({inprogress}) => {
104
+ if (inprogress) this.nestedEntries = []
62
105
  }
63
106
 
64
107
  clear = () => {
65
108
  const backUp = this.api.store.preserveLog
66
109
  this.api.store.result = {logs: undefined, error: undefined}
110
+ this.nestedEntries = []
67
111
  this.consoleOutput.innerText = ''
68
112
  this.api.store.preserveLog = backUp
69
113
  }
@@ -75,9 +119,14 @@ class ConsolePanel extends ApiBaseElement {
75
119
  this.consoleOutput = this.shadowRoot.querySelector('#console-output')
76
120
  this.addEventListener('clear-console', this.clear)
77
121
 
122
+ // Nested context.invoke() runs arrive as a stream of discrete DOM events
123
+ // (not state) so none are dropped when several land in one frame.
124
+ window.addEventListener('nested-invoke', this.updateNested)
125
+
78
126
  // Subscribe to changes in the result state to update the console
79
127
  if (this.api) {
80
128
  this.api.subscribe(this.updateConsole, ['result'])
129
+ this.api.subscribe(this.resetNested, ['inprogress'])
81
130
  // Initial update in case result is already populated
82
131
  if (this.api.store.result) {
83
132
  this.updateConsole({result: this.api.store.result})
@@ -90,9 +139,11 @@ class ConsolePanel extends ApiBaseElement {
90
139
 
91
140
  disconnectedCallback() {
92
141
  this.removeEventListener('clear-console', this.clear)
142
+ window.removeEventListener('nested-invoke', this.updateNested)
93
143
  // Unsubscribe when the element is removed from the DOM
94
144
  if (this.api) {
95
145
  this.api.unsubscribe(this.updateConsole)
146
+ this.api.unsubscribe(this.resetNested)
96
147
  }
97
148
  }
98
149
  }
@@ -43,14 +43,17 @@ class RulePanel extends ApiBaseElement {
43
43
  break
44
44
  }
45
45
 
46
- const transaction = rule.state.update({
47
- changes: {
48
- from: 0,
49
- insert: func.event ? JSON.stringify(func.event, null, 2) : '',
50
- to: rule.state.doc.length,
51
- },
52
- })
53
- rule.dispatch(transaction)
46
+ // Guard against the sate not being setup
47
+ if (rule?.state) {
48
+ const transaction = rule.state.update({
49
+ changes: {
50
+ from: 0,
51
+ insert: func.event ? JSON.stringify(func.event, null, 2) : '',
52
+ to: rule.state.doc.length,
53
+ },
54
+ })
55
+ rule.dispatch(transaction)
56
+ }
54
57
  }
55
58
 
56
59
  async connectedCallback() {
@@ -1,31 +1,34 @@
1
1
  /* globals fetch */
2
2
 
3
- let cachedStyleSheets = null
3
+ let sharedStyleSheetsPromise = null
4
4
 
5
- export async function getSharedStyleSheets() {
6
- if (cachedStyleSheets) {
7
- return cachedStyleSheets
8
- }
5
+ async function loadSharedStyleSheets() {
6
+ // Fetch both stylesheets
7
+ const [mCssResponse, appCssResponse] = await Promise.all([
8
+ fetch('./vendor/m-.css'),
9
+ fetch('./components/app.css'),
10
+ ])
9
11
 
10
- try {
11
- // Fetch both stylesheets
12
- const [mCssResponse, appCssResponse] = await Promise.all([
13
- fetch('./vendor/m-.css'),
14
- fetch('./components/app.css'),
15
- ])
12
+ const [mCssText, appCssText] = await Promise.all([mCssResponse.text(), appCssResponse.text()])
16
13
 
17
- const [mCssText, appCssText] = await Promise.all([mCssResponse.text(), appCssResponse.text()])
14
+ // Create CSSStyleSheet objects
15
+ const mSheet = new CSSStyleSheet()
16
+ const appSheet = new CSSStyleSheet()
18
17
 
19
- // Create CSSStyleSheet objects
20
- const mSheet = new CSSStyleSheet()
21
- const appSheet = new CSSStyleSheet()
18
+ await Promise.all([mSheet.replace(mCssText), appSheet.replace(appCssText)])
22
19
 
23
- await Promise.all([mSheet.replace(mCssText), appSheet.replace(appCssText)])
20
+ return [mSheet, appSheet]
21
+ }
24
22
 
25
- cachedStyleSheets = [mSheet, appSheet]
26
- return cachedStyleSheets
27
- } catch (error) {
28
- console.error('Failed to load shared stylesheets:', error)
29
- return []
23
+ export function getSharedStyleSheets() {
24
+ if (!sharedStyleSheetsPromise) {
25
+ sharedStyleSheetsPromise = loadSharedStyleSheets().catch((error) => {
26
+ console.error('Failed to load shared stylesheets:', error)
27
+ // Reset so a later caller can retry instead of being stuck with [].
28
+ sharedStyleSheetsPromise = null
29
+ return []
30
+ })
30
31
  }
32
+
33
+ return sharedStyleSheetsPromise
31
34
  }
@@ -64,6 +64,6 @@
64
64
  <script src="./components/clear-button.js" type="module"></script>
65
65
  <script src="./components/help-button.js" type="module"></script>
66
66
  <script src="./components/fetch-button.js" type="module"></script>
67
- <script src="./hot-reload.js" type="module"></script>
67
+ <script src="./web-socket.js" type="module"></script>
68
68
  </body>
69
69
  </html>
@@ -37,39 +37,39 @@
37
37
  --gray-800: #252837;
38
38
  --gray-900: #1b1d27;
39
39
  --gray-950: #13141b;
40
- --green-100: #dcfce7;
41
- --green-200: #bbf7d0;
42
- --green-300: #86efac;
43
- --green-400: #4ade80;
44
- --green-50: #f0fdf4;
45
- --green-500: #22c55e;
40
+ --green-100: #c5fce8;
41
+ --green-200: #a9f9dc;
42
+ --green-300: #59f3ba;
43
+ --green-400: #0ff0a1;
44
+ --green-50: #e7fef5;
45
+ --green-500: #04b97a;
46
46
  --green-600: #01794f;
47
47
  --green-700: #015133;
48
48
  --green-800: #023120;
49
49
  --green-900: #06231a;
50
50
  --green-950: #071715;
51
- --magenta-100: #fde8f1;
52
- --magenta-200: #fcd5e8;
53
- --magenta-300: #f7a5cc;
54
- --magenta-400: #f06dac;
51
+ --magenta-100: #fde8ef;
52
+ --magenta-200: #fcdee9;
53
+ --magenta-300: #f7abc5;
54
+ --magenta-400: #f0709b;
55
55
  --magenta-50: #fef6f9;
56
- --magenta-500: #e03d8d;
57
- --magenta-600: #c41e72;
58
- --magenta-700: #8c1452;
59
- --magenta-800: #560d34;
60
- --magenta-900: #380b24;
61
- --magenta-950: #230717;
62
- --orange-100: #ffecd9;
63
- --orange-200: #ffdfc0;
64
- --orange-300: #ffbe85;
65
- --orange-400: #ff9c47;
56
+ --magenta-500: #e72767;
57
+ --magenta-600: #b11651;
58
+ --magenta-700: #7c1342;
59
+ --magenta-800: #4b1130;
60
+ --magenta-900: #341325;
61
+ --magenta-950: #1f0f14;
62
+ --orange-100: #ffeadb;
63
+ --orange-200: #ffddc7;
64
+ --orange-300: #ffb685;
65
+ --orange-400: #ff8e42;
66
66
  --orange-50: #fff7f0;
67
- --orange-500: #f57c1f;
68
- --orange-600: #d95f07;
69
- --orange-700: #9e4204;
70
- --orange-800: #4f2204;
71
- --orange-900: #341803;
72
- --orange-950: #200f02;
67
+ --orange-500: #fa6400;
68
+ --orange-600: #b14802;
69
+ --orange-700: #7c3404;
70
+ --orange-800: #461e07;
71
+ --orange-900: #32160b;
72
+ --orange-950: #21120d;
73
73
  --purple-100: #f1ebff;
74
74
  --purple-200: #ece1fe;
75
75
  --purple-300: #ccb1fc;
@@ -81,27 +81,27 @@
81
81
  --purple-800: #2f1862;
82
82
  --purple-900: #23173f;
83
83
  --purple-950: #181128;
84
- --red-100: #ffe5e5;
85
- --red-200: #ffd5d5;
86
- --red-300: #ffaaaa;
87
- --red-400: #ff7b7b;
88
- --red-50: #fff5f5;
89
- --red-500: #f94f4f;
90
- --red-600: #e42f2f;
91
- --red-700: #a81e1e;
92
- --red-800: #551212;
93
- --red-900: #380d0d;
94
- --red-950: #230808;
84
+ --red-100: #ffe7e5;
85
+ --red-200: #ffdedc;
86
+ --red-300: #fdada5;
87
+ --red-400: #f77769;
88
+ --red-50: #fff6f5;
89
+ --red-500: #ef4434;
90
+ --red-600: #cc2819;
91
+ --red-700: #8b2018;
92
+ --red-800: #4d1714;
93
+ --red-900: #321615;
94
+ --red-950: #1e1011;
95
95
  --white: #ffffff;
96
- --yellow-100: #fef9c3;
97
- --yellow-200: #fef08a;
98
- --yellow-300: #fde047;
99
- --yellow-400: #facc15;
100
- --yellow-50: #fefce8;
101
- --yellow-500: #eab308;
102
- --yellow-600: #ca8a04;
103
- --yellow-700: #a16207;
104
- --yellow-800: #713f12;
105
- --yellow-900: #422006;
106
- --yellow-950: #27130a;
96
+ --yellow-100: #fcf3bb;
97
+ --yellow-200: #f9e994;
98
+ --yellow-300: #f7d455;
99
+ --yellow-400: #f9bc15;
100
+ --yellow-50: #fefae1;
101
+ --yellow-500: #d28a04;
102
+ --yellow-600: #965908;
103
+ --yellow-700: #653a0b;
104
+ --yellow-800: #3b220c;
105
+ --yellow-900: #271a11;
106
+ --yellow-950: #181410;
107
107
  }
@@ -7,7 +7,6 @@
7
7
  @import "./container.css";
8
8
  @import "./fontFamily.css";
9
9
  @import "./fontWeight.css";
10
- @import "./index.css";
11
10
  @import "./radius.css";
12
11
  @import "./shadow.css";
13
12
  @import "./space.css";