@sanity/runtime-cli 1.3.1 → 1.4.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 (59) hide show
  1. package/README.md +11 -14
  2. package/dist/actions/blueprints/logs.d.ts +1 -0
  3. package/dist/actions/blueprints/logs.js +3 -2
  4. package/dist/actions/blueprints/operations.d.ts +1 -0
  5. package/dist/actions/blueprints/operations.js +3 -2
  6. package/dist/actions/blueprints/read-blueprint.d.ts +16 -7
  7. package/dist/actions/blueprints/read-blueprint.js +56 -10
  8. package/dist/actions/blueprints/stacks.d.ts +6 -6
  9. package/dist/actions/blueprints/stacks.js +10 -14
  10. package/dist/actions/blueprints/stash-asset.d.ts +1 -0
  11. package/dist/actions/blueprints/stash-asset.js +2 -5
  12. package/dist/actions/functions/invoke.d.ts +6 -2
  13. package/dist/actions/functions/invoke.js +9 -11
  14. package/dist/actions/functions/logs.d.ts +6 -1
  15. package/dist/actions/functions/logs.js +10 -10
  16. package/dist/commands/blueprints/deploy.js +19 -18
  17. package/dist/commands/blueprints/info.js +18 -38
  18. package/dist/commands/blueprints/logs.d.ts +0 -1
  19. package/dist/commands/blueprints/logs.js +12 -41
  20. package/dist/commands/blueprints/plan.js +14 -4
  21. package/dist/commands/functions/invoke.js +19 -2
  22. package/dist/commands/functions/logs.js +26 -2
  23. package/dist/config.js +6 -5
  24. package/dist/server/static/api.d.ts +10 -0
  25. package/dist/server/static/api.js +38 -43
  26. package/dist/server/static/components/api-base.d.ts +9 -0
  27. package/dist/server/static/components/api-base.js +6 -7
  28. package/dist/server/static/components/function-list.d.ts +1 -0
  29. package/dist/server/static/components/function-list.js +44 -48
  30. package/dist/server/static/components/network-spinner.d.ts +1 -0
  31. package/dist/server/static/components/network-spinner.js +6 -7
  32. package/dist/server/static/components/payload-panel.d.ts +1 -0
  33. package/dist/server/static/components/payload-panel.js +32 -36
  34. package/dist/server/static/components/response-panel.d.ts +1 -0
  35. package/dist/server/static/components/response-panel.js +50 -64
  36. package/dist/server/static/static/api.js +53 -0
  37. package/dist/server/static/static/components/api-base.js +10 -0
  38. package/dist/server/static/static/components/function-list.js +54 -0
  39. package/dist/server/static/static/components/network-spinner.js +71 -0
  40. package/dist/server/static/static/components/payload-panel.js +45 -0
  41. package/dist/server/static/static/components/response-panel.js +83 -0
  42. package/dist/server/static/static/vendor/vendor.bundle.js +26879 -0
  43. package/dist/server/static/vendor/vendor.bundle.d.ts +1815 -0
  44. package/dist/server/static/vendor/vendor.bundle.js +913 -1029
  45. package/dist/utils/child-process-wrapper.d.ts +1 -0
  46. package/dist/utils/display/blueprints-formatting.js +2 -2
  47. package/dist/utils/get-headers.d.ts +8 -0
  48. package/dist/utils/get-headers.js +9 -0
  49. package/dist/utils/get-token.d.ts +3 -1
  50. package/dist/utils/get-token.js +2 -2
  51. package/dist/utils/types.d.ts +44 -30
  52. package/dist/utils/types.js +8 -1
  53. package/dist/utils/vendor/parser-validator.d.ts +8 -0
  54. package/dist/utils/vendor/parser-validator.js +514 -0
  55. package/oclif.manifest.json +1 -11
  56. package/package.json +10 -11
  57. /package/dist/server/static/{components → static/components}/app.css +0 -0
  58. /package/dist/server/static/{index.html → static/index.html} +0 -0
  59. /package/dist/server/static/{sanity-logo-sm.svg → static/sanity-logo-sm.svg} +0 -0
@@ -1,45 +1,41 @@
1
1
  /* globals customElements */
2
- import {EditorView, basicSetup, json} from '../vendor/vendor.bundle.js'
3
- import {ApiBaseElement} from './api-base.js'
4
-
2
+ import { EditorView, basicSetup, json } from '../vendor/vendor.bundle.js';
3
+ import { ApiBaseElement } from './api-base.js';
5
4
  const template = `<m-box>
6
5
  <h2 class="mar-t-0">Payload</h2>
7
6
  <div id="payload" name="payload"></div>
8
7
  <button ord="primary" class="mar-t-sm sanity-button">Invoke</button>
9
8
  </m-box>
10
- `
9
+ `;
11
10
  class PayloadPanel extends ApiBaseElement {
12
- invoke = () => {
13
- const payloadText = this.api.store.payload.state.doc.text.join('') || '{}'
14
- this.api.invoke(payloadText)
15
- }
16
- updateButtonText = ({inprogress}) => {
17
- if (inprogress) {
18
- this.button.setAttribute('disabled', '')
19
- this.button.innerHTML = '<network-spinner></network-spinner>'
20
- } else {
21
- this.button.removeAttribute('disabled')
22
- this.button.innerText = 'Invoke'
11
+ invoke = () => {
12
+ const payloadText = this.api.store.payload.state.doc.text.join('') || '{}';
13
+ this.api.invoke(payloadText);
14
+ };
15
+ updateButtonText = ({ inprogress }) => {
16
+ if (inprogress) {
17
+ this.button.setAttribute('disabled', '');
18
+ this.button.innerHTML = '<network-spinner></network-spinner>';
19
+ }
20
+ else {
21
+ this.button.removeAttribute('disabled');
22
+ this.button.innerText = 'Invoke';
23
+ }
24
+ };
25
+ connectedCallback() {
26
+ this.innerHTML = template;
27
+ this.payload = this.querySelector('#payload');
28
+ this.button = this.querySelector('button');
29
+ this.button.addEventListener('click', this.invoke);
30
+ this.api.subscribe(this.updateButtonText, ['inprogress']);
31
+ this.api.store.payload = new EditorView({
32
+ doc: '\n\n\n\n',
33
+ extensions: [basicSetup, json()],
34
+ parent: this.payload,
35
+ });
36
+ }
37
+ disconnectedCallback() {
38
+ this.button.removeEventListener('click', this.invoke);
23
39
  }
24
- }
25
-
26
- connectedCallback() {
27
- this.innerHTML = template
28
- this.payload = this.querySelector('#payload')
29
- this.button = this.querySelector('button')
30
- this.button.addEventListener('click', this.invoke)
31
- this.api.subscribe(this.updateButtonText, ['inprogress'])
32
-
33
- this.api.store.payload = new EditorView({
34
- doc: '\n\n\n\n',
35
- extensions: [basicSetup, json()],
36
- parent: this.payload,
37
- })
38
- }
39
-
40
- disconnectedCallback() {
41
- this.button.removeEventListener('click', this.invoke)
42
- }
43
40
  }
44
-
45
- customElements.define('payload-panel', PayloadPanel)
41
+ customElements.define('payload-panel', PayloadPanel);
@@ -0,0 +1 @@
1
+ export {};
@@ -1,15 +1,7 @@
1
1
  /* eslint-disable unicorn/prefer-dom-node-text-content */
2
2
  /* globals customElements document */
3
- import {
4
- EditorState,
5
- EditorView,
6
- basicSetup,
7
- json,
8
- prettyBytes,
9
- prettyMilliseconds,
10
- } from '../vendor/vendor.bundle.js'
11
- import {ApiBaseElement} from './api-base.js'
12
-
3
+ import { EditorState, EditorView, basicSetup, json, prettyBytes, prettyMilliseconds, } from '../vendor/vendor.bundle.js';
4
+ import { ApiBaseElement } from './api-base.js';
13
5
  const template = `<m-box>
14
6
  <m-tabs role="tablist">
15
7
  <button id="a" role="tab" aria-selected="true">Response</button>
@@ -23,61 +15,55 @@ const template = `<m-box>
23
15
  </div>
24
16
  <div role="tabpanel" data-tab-id="b" class="pad-t-sm" hidden><pre></pre></div>
25
17
  </m-box>
26
- `
18
+ `;
27
19
  class ResponsePanel extends ApiBaseElement {
28
- switchTab = (e) => {
29
- const selectedTabId = e.target.closest('[role=tab]').id
30
-
31
- // Select the tab and its panel
32
- for (const tab of e.currentTarget.querySelectorAll('[role=tab]')) {
33
- tab.ariaSelected = tab.id === selectedTabId
20
+ switchTab = (e) => {
21
+ const selectedTabId = e.target.closest('[role=tab]').id;
22
+ // Select the tab and its panel
23
+ for (const tab of e.currentTarget.querySelectorAll('[role=tab]')) {
24
+ tab.ariaSelected = tab.id === selectedTabId;
25
+ }
26
+ for (const panel of document.querySelectorAll('[role=tabpanel')) {
27
+ panel.hidden = panel.dataset.tabId !== selectedTabId;
28
+ }
29
+ };
30
+ updateResponse = ({ result }) => {
31
+ const { error, json, logs, time } = result;
32
+ if (!error) {
33
+ const transaction = this.api.store.response.state.update({
34
+ changes: {
35
+ from: 0,
36
+ insert: JSON.stringify(json, null, 2),
37
+ to: this.api.store.response.state.doc.length,
38
+ },
39
+ });
40
+ this.api.store.response.dispatch(transaction);
41
+ this.size.innerText = json ? prettyBytes(JSON.stringify(json).length) : '';
42
+ this.time.innerText = prettyMilliseconds(time);
43
+ this.consoleTab.innerText = logs;
44
+ }
45
+ else {
46
+ this.consoleTab.innerText = error?.details?.error;
47
+ }
48
+ };
49
+ connectedCallback() {
50
+ this.innerHTML = template;
51
+ this.response = this.querySelector('#response');
52
+ this.size = this.querySelector('#size');
53
+ this.time = this.querySelector('#time');
54
+ this.consoleTab = this.querySelector('pre');
55
+ this.tabs = this.querySelector('m-tabs');
56
+ this.tabs.addEventListener('click', this.switchTab);
57
+ this.api.subscribe(this.updateResponse, ['result']);
58
+ this.api.store.response = new EditorView({
59
+ doc: '\n\n\n\n',
60
+ extensions: [basicSetup, json(), EditorState.readOnly.of(true)],
61
+ parent: this.response,
62
+ });
34
63
  }
35
-
36
- for (const panel of document.querySelectorAll('[role=tabpanel')) {
37
- panel.hidden = panel.dataset.tabId !== selectedTabId
64
+ disconnectedCallback() {
65
+ this.tabs.removeEventListener('click', this.switchTab);
66
+ this.api.unsubscribe(this.updateResponse);
38
67
  }
39
- }
40
- updateResponse = ({result}) => {
41
- const {error, json, logs, time} = result
42
- if (!error) {
43
- const transaction = this.api.store.response.state.update({
44
- changes: {
45
- from: 0,
46
- insert: JSON.stringify(json, null, 2),
47
- to: this.api.store.response.state.doc.length,
48
- },
49
- })
50
- this.api.store.response.dispatch(transaction)
51
-
52
- this.size.innerText = json ? prettyBytes(JSON.stringify(json).length) : ''
53
- this.time.innerText = prettyMilliseconds(time)
54
- this.consoleTab.innerText = logs
55
- } else {
56
- this.consoleTab.innerText = error?.details?.error
57
- }
58
- }
59
-
60
- connectedCallback() {
61
- this.innerHTML = template
62
- this.response = this.querySelector('#response')
63
- this.size = this.querySelector('#size')
64
- this.time = this.querySelector('#time')
65
- this.consoleTab = this.querySelector('pre')
66
- this.tabs = this.querySelector('m-tabs')
67
- this.tabs.addEventListener('click', this.switchTab)
68
- this.api.subscribe(this.updateResponse, ['result'])
69
-
70
- this.api.store.response = new EditorView({
71
- doc: '\n\n\n\n',
72
- extensions: [basicSetup, json(), EditorState.readOnly.of(true)],
73
- parent: this.response,
74
- })
75
- }
76
-
77
- disconnectedCallback() {
78
- this.tabs.removeEventListener('click', this.switchTab)
79
- this.api.unsubscribe(this.updateResponse)
80
- }
81
68
  }
82
-
83
- customElements.define('response-panel', ResponsePanel)
69
+ customElements.define('response-panel', ResponsePanel);
@@ -0,0 +1,53 @@
1
+ /* eslint-disable n/no-unsupported-features/node-builtins */
2
+ import {Store} from './vendor/vendor.bundle.js'
3
+
4
+ // eslint-disable-next-line new-cap
5
+ const store = Store()
6
+
7
+ export default function API() {
8
+ return {
9
+ blueprint,
10
+ invoke,
11
+ store,
12
+ subscribe: store.subscribe,
13
+ unsubscribe: store.unsubscribe,
14
+ }
15
+ }
16
+
17
+ function invoke(payloadText = '{}') {
18
+ store.inprogress = true
19
+ const start = Date.now()
20
+ const payload = {
21
+ data: payloadText,
22
+ func: store.selectedIndex,
23
+ }
24
+ fetch('/invoke', {
25
+ body: JSON.stringify(payload),
26
+ headers: {
27
+ 'Content-Type': 'application/json',
28
+ },
29
+ method: 'POST',
30
+ })
31
+ .then((response) => response.json())
32
+ .then((data) => {
33
+ store.inprogress = false
34
+ store.result = {
35
+ ...data,
36
+ time: Date.now() - start,
37
+ }
38
+ })
39
+ }
40
+
41
+ function blueprint() {
42
+ fetch('/blueprint')
43
+ .then((response) => response.json())
44
+ .then((json) => {
45
+ const functions = json?.document?.resources.filter((resource) => resource.kind === 'function')
46
+
47
+ store.functions = functions
48
+ store.selectedIndex = functions[0].src
49
+ })
50
+ .catch(() => {
51
+ store.functions = []
52
+ })
53
+ }
@@ -0,0 +1,10 @@
1
+ /* globals HTMLElement */
2
+ import apiConstructor from '../api.js'
3
+ const api = apiConstructor()
4
+
5
+ export class ApiBaseElement extends HTMLElement {
6
+ constructor() {
7
+ super()
8
+ this.api = api
9
+ }
10
+ }
@@ -0,0 +1,54 @@
1
+ /* globals customElements */
2
+ import {ApiBaseElement} from './api-base.js'
3
+
4
+ const template = `<ol class="hidden-lg" type="content"></ol>
5
+ <fieldset class="pad-sm hidden block-lg"><select></select></fieldset>
6
+ `
7
+
8
+ class FunctionList extends ApiBaseElement {
9
+ functionClicked = (event) => {
10
+ // eslint-disable-next-line unicorn/prefer-dom-node-text-content
11
+ const target = this.api.store.functions.find((func) => func.name === event.srcElement.innerText)
12
+ this.api.store.selectedIndex = target.src
13
+ }
14
+ functionSelected = (event) => {
15
+ this.api.store.selectedIndex = event.srcElement.value
16
+ }
17
+ renderFunctions = () => {
18
+ if (this.api.store.functions.length > 0) {
19
+ this.list.innerHTML = this.api.store.functions
20
+ .map((func) => {
21
+ const selected = this.api.store.selectedIndex === func.src ? 'selected' : ''
22
+ return `<li class="pad-sm ${selected}">${func.name}</li>`
23
+ })
24
+ .join('')
25
+ this.select.innerHTML = this.api.store.functions
26
+ .map((func) => {
27
+ const selected = this.api.store.selectedIndex === func.src ? 'selected' : ''
28
+ return `<option value="${func.src}" ${selected}>${func.name}</option>`
29
+ })
30
+ .join('')
31
+ } else {
32
+ this.list.innerHTML = '<option class="pad-sm">No blueprint.json file found</li>'
33
+ this.select.innerHTML = '<option>No blueprint.json file found</option>'
34
+ }
35
+ }
36
+
37
+ connectedCallback() {
38
+ this.innerHTML = template
39
+ this.list = this.querySelector('ol')
40
+ this.select = this.querySelector('select')
41
+ this.list.addEventListener('click', this.functionClicked)
42
+ this.select.addEventListener('change', this.functionSelected)
43
+ this.api.subscribe(this.renderFunctions, ['functions', 'selectedIndex'])
44
+ this.api.blueprint()
45
+ }
46
+
47
+ disconnectedCallback() {
48
+ this.list.removeEventListener('click', this.functionClicked)
49
+ this.select.removeEventListener('change', this.functionSelected)
50
+ this.api.unsubscribe(this.renderFunctions)
51
+ }
52
+ }
53
+
54
+ customElements.define('function-list', FunctionList)
@@ -0,0 +1,71 @@
1
+ /* globals customElements HTMLElement */
2
+ const template = `<style>
3
+ network-spinner {
4
+ --track-width: 2px;
5
+ --track-color: var(--card-border-color);
6
+ --indicator-color: var(--text-color);
7
+ --speed: 2s;
8
+
9
+ display: inline-flex;
10
+ width: 1em;
11
+ height: 1em;
12
+ flex: none;
13
+ }
14
+
15
+ .spinner {
16
+ flex: 1 1 auto;
17
+ height: 100%;
18
+ width: 100%;
19
+ }
20
+
21
+ .spinner__track,
22
+ .spinner__indicator {
23
+ fill: none;
24
+ stroke-width: var(--track-width);
25
+ r: calc(0.5em - var(--track-width) / 2);
26
+ cx: 0.5em;
27
+ cy: 0.5em;
28
+ transform-origin: 50% 50%;
29
+ }
30
+
31
+ .spinner__track {
32
+ stroke: var(--track-color);
33
+ transform-origin: 0% 0%;
34
+ }
35
+
36
+ .spinner__indicator {
37
+ stroke: var(--indicator-color);
38
+ stroke-linecap: round;
39
+ stroke-dasharray: 150% 75%;
40
+ animation: spin var(--speed) linear infinite;
41
+ }
42
+
43
+ @keyframes spin {
44
+ 0% {
45
+ transform: rotate(0deg);
46
+ stroke-dasharray: 0.05em, 3em;
47
+ }
48
+
49
+ 50% {
50
+ transform: rotate(450deg);
51
+ stroke-dasharray: 1.375em, 1.375em;
52
+ }
53
+
54
+ 100% {
55
+ transform: rotate(1080deg);
56
+ stroke-dasharray: 0.05em, 3em;
57
+ }
58
+ }
59
+ </style>
60
+ <svg part="base" class="spinner" role="progressbar" aria-label="loading">
61
+ <circle class="spinner__track"></circle>
62
+ <circle class="spinner__indicator"></circle>
63
+ </svg>`
64
+
65
+ class NetworkSpinner extends HTMLElement {
66
+ connectedCallback() {
67
+ this.innerHTML = template
68
+ }
69
+ }
70
+
71
+ customElements.define('network-spinner', NetworkSpinner)
@@ -0,0 +1,45 @@
1
+ /* globals customElements */
2
+ import {EditorView, basicSetup, json} from '../vendor/vendor.bundle.js'
3
+ import {ApiBaseElement} from './api-base.js'
4
+
5
+ const template = `<m-box>
6
+ <h2 class="mar-t-0">Payload</h2>
7
+ <div id="payload" name="payload"></div>
8
+ <button ord="primary" class="mar-t-sm sanity-button">Invoke</button>
9
+ </m-box>
10
+ `
11
+ class PayloadPanel extends ApiBaseElement {
12
+ invoke = () => {
13
+ const payloadText = this.api.store.payload.state.doc.text.join('') || '{}'
14
+ this.api.invoke(payloadText)
15
+ }
16
+ updateButtonText = ({inprogress}) => {
17
+ if (inprogress) {
18
+ this.button.setAttribute('disabled', '')
19
+ this.button.innerHTML = '<network-spinner></network-spinner>'
20
+ } else {
21
+ this.button.removeAttribute('disabled')
22
+ this.button.innerText = 'Invoke'
23
+ }
24
+ }
25
+
26
+ connectedCallback() {
27
+ this.innerHTML = template
28
+ this.payload = this.querySelector('#payload')
29
+ this.button = this.querySelector('button')
30
+ this.button.addEventListener('click', this.invoke)
31
+ this.api.subscribe(this.updateButtonText, ['inprogress'])
32
+
33
+ this.api.store.payload = new EditorView({
34
+ doc: '\n\n\n\n',
35
+ extensions: [basicSetup, json()],
36
+ parent: this.payload,
37
+ })
38
+ }
39
+
40
+ disconnectedCallback() {
41
+ this.button.removeEventListener('click', this.invoke)
42
+ }
43
+ }
44
+
45
+ customElements.define('payload-panel', PayloadPanel)
@@ -0,0 +1,83 @@
1
+ /* eslint-disable unicorn/prefer-dom-node-text-content */
2
+ /* globals customElements document */
3
+ import {
4
+ EditorState,
5
+ EditorView,
6
+ basicSetup,
7
+ json,
8
+ prettyBytes,
9
+ prettyMilliseconds,
10
+ } from '../vendor/vendor.bundle.js'
11
+ import {ApiBaseElement} from './api-base.js'
12
+
13
+ const template = `<m-box>
14
+ <m-tabs role="tablist">
15
+ <button id="a" role="tab" aria-selected="true">Response</button>
16
+ <button id="b" role="tab">Console</button>
17
+ </m-tabs>
18
+ <div role="tabpanel" data-tab-id="a" class="pad-t-sm">
19
+ <div class="mar-b-sm">
20
+ <span id="time"></span> <span id="size"></span>
21
+ </div>
22
+ <div id="response" name="response"></div>
23
+ </div>
24
+ <div role="tabpanel" data-tab-id="b" class="pad-t-sm" hidden><pre></pre></div>
25
+ </m-box>
26
+ `
27
+ class ResponsePanel extends ApiBaseElement {
28
+ switchTab = (e) => {
29
+ const selectedTabId = e.target.closest('[role=tab]').id
30
+
31
+ // Select the tab and its panel
32
+ for (const tab of e.currentTarget.querySelectorAll('[role=tab]')) {
33
+ tab.ariaSelected = tab.id === selectedTabId
34
+ }
35
+
36
+ for (const panel of document.querySelectorAll('[role=tabpanel')) {
37
+ panel.hidden = panel.dataset.tabId !== selectedTabId
38
+ }
39
+ }
40
+ updateResponse = ({result}) => {
41
+ const {error, json, logs, time} = result
42
+ if (!error) {
43
+ const transaction = this.api.store.response.state.update({
44
+ changes: {
45
+ from: 0,
46
+ insert: JSON.stringify(json, null, 2),
47
+ to: this.api.store.response.state.doc.length,
48
+ },
49
+ })
50
+ this.api.store.response.dispatch(transaction)
51
+
52
+ this.size.innerText = json ? prettyBytes(JSON.stringify(json).length) : ''
53
+ this.time.innerText = prettyMilliseconds(time)
54
+ this.consoleTab.innerText = logs
55
+ } else {
56
+ this.consoleTab.innerText = error?.details?.error
57
+ }
58
+ }
59
+
60
+ connectedCallback() {
61
+ this.innerHTML = template
62
+ this.response = this.querySelector('#response')
63
+ this.size = this.querySelector('#size')
64
+ this.time = this.querySelector('#time')
65
+ this.consoleTab = this.querySelector('pre')
66
+ this.tabs = this.querySelector('m-tabs')
67
+ this.tabs.addEventListener('click', this.switchTab)
68
+ this.api.subscribe(this.updateResponse, ['result'])
69
+
70
+ this.api.store.response = new EditorView({
71
+ doc: '\n\n\n\n',
72
+ extensions: [basicSetup, json(), EditorState.readOnly.of(true)],
73
+ parent: this.response,
74
+ })
75
+ }
76
+
77
+ disconnectedCallback() {
78
+ this.tabs.removeEventListener('click', this.switchTab)
79
+ this.api.unsubscribe(this.updateResponse)
80
+ }
81
+ }
82
+
83
+ customElements.define('response-panel', ResponsePanel)