@joystick.js/node-canary 0.0.0-canary.375 → 0.0.0-canary.377
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.
package/dist/app/api/get.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import p from"./format_api_error.js";import f from"./get_output.js";import h from"../../lib/get_sanitized_context.js";import z from"./sanitize_api_response.js";import d from"../../test/track_function_call.js";import n from"../../lib/types.js";import m from"./validate_input.js";const _=async(o="",t={},r=null,s=null,a={},u={})=>{const l=t?.sanitize===!1,i=(t?.sanitize||u?.sanitize)===!0;d(`node.api.getters.${o}`,[r,h(a)]);const e=await t?.get(r,a),c=s?f(e,s):e;return!l&&i?z(c):c},w=async(o="",t={},r={},s={})=>{d(`node.api.getters.${o}.authorized`,[r,h(s)]);const a=await t?.authorized(r,s);if(typeof a=="boolean")return a;if(n.is_object(a)&&!n.is_array(a)&&!n.is_undefined(a?.authorized))return a?.authorized?!0:a?.message},y=(o=[],t="")=>{console.log(`Input validation for getter "${t}" failed with the following errors:
|
|
2
|
-
`);for(let r=0;r<o?.length;r+=1){const s=o[r];console.log(`${r+1}. ${s}`)}},$=(o={},t={})=>m(o,t),v=async({get_name:o,get_options:t,getter_definition:r,request_context:s,api_schema_options:a})=>{const u=r?.input&&Object.keys(r?.input)?.length>0,l=n.is_function(r?.authorized);if(u){const i=await $(t?.input,r?.input);if(i?.length>0)return y(i,o),Promise.reject({errors:i.map(e=>p(new Error(e),`getters.${o}.input`,
|
|
2
|
+
`);for(let r=0;r<o?.length;r+=1){const s=o[r];console.log(`${r+1}. ${s}`)}},$=(o={},t={})=>m(o,t),v=async({get_name:o,get_options:t,getter_definition:r,request_context:s,api_schema_options:a})=>{const u=r?.input&&Object.keys(r?.input)?.length>0,l=n.is_function(r?.authorized);if(u){const i=await $(t?.input,r?.input);if(i?.length>0)return y(i,o),Promise.reject({errors:i.map(e=>p(new Error(e),`getters.${o}.input`,400))})}if(l){const i=await w(o,r,t?.input,s);if(!i||n.is_string(i))return Promise.reject({errors:[p(new Error(typeof i=="string"?i:`Not authorized to access ${o}.`),`getters.${o}.authorized`,403)]})}if(n.is_function(r?.get)){const i=await _(o,r,t?.input,t?.output,s,a);return Promise.resolve(i)}};var N=v;export{N as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import i from"../../lib/types.js";import
|
|
1
|
+
import i from"../../lib/types.js";import m from"./validate_type.js";import v from"./is_array_path.js";const l=(r,e,t)=>r.includes(e)?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} only allows the following values: ${r.join(", ")}.`]},n=(r,e,t)=>i.is_array(e)&&e?.length<=r?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} length must be less than or equal to ${r}.`]},d=(r,e,t)=>i.is_array(e)&&e?.length>=r?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} length must be greater than or equal to ${r}.`]},g={types:["any","array","boolean","float","integer","number","object","string"],rules:{allowed_values:l,allowedValues:l,element:async(r,e,t,s)=>{if(e&&(i.is_object(r)||i.is_string(r))&&i.is_array(e)){const a=await Promise.all(e.flatMap(async(o,f)=>(await s(o,i.is_string(r)?{type:r}:r,`${t}.${f}`)).flatMap(c=>c)));return{valid:a.length===0,errors:a.flatMap(o=>o)}}return{valid:!0,errors:[]}},fields:async(r,e,t,s)=>{if(i.is_object(r)&&i.is_object(e)){const a=v(t)?e:{[t]:e},o=await s(a,r,t);return{valid:o.length===0,errors:[...o]}}return{valid:!1,errors:[`Field ${t} must be of type object.`]}},max:(r,e,t)=>e<=r?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} must be less than or equal to ${r}.`]},max_length:n,maxLength:n,min:(r,e,t)=>e>=r?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} must be greater than or equal to ${r}.`]},min_length:d,minLength:d,optional:(r,e,t)=>(r===!1?!!e:!0)?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} is required.`]},regex:(r,e,t)=>new RegExp(r).test(e)?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} must conform to regex: ${r}.`]},required:(r,e,t)=>(r===!1?!0:!!e)?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} is required.`]},type:(r,e,t)=>{const s=m(r,e);return e&&!s?{valid:!1,errors:[`Field ${t} must be of type ${r}.`]}:{valid:!0,errors:[]}}}};var h=g;export{h as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var i=null,c=0,l=(t={},e=null)=>{let o=new WebSocket(`ws://localhost:${window.__joystick_hmr_port__}/_joystick/hmr?${new URLSearchParams(t.query).toString()}`);i&&(clearInterval(i),i=null);let _={client:o,send:(n={})=>(t.queryParams&&(n={...n,...t.queryParams}),o.send(JSON.stringify(n)))};return o.addEventListener("open",()=>{console.log("[hmr] Listening for changes..."),c=0,e&&e(_)}),o.addEventListener("message",n=>{n?.data&&t.onMessage&&t.onMessage(JSON.parse(n.data),_)}),o.addEventListener("close",()=>{console.log("[hmr] Disconnected from server."),o=null,t.autoReconnect&&!i&&(i=setInterval(()=>{o=null,c<12?(l(t,e),console.log(`[hmr] Attempting to reconnect (${c+1}/12)...`),c+=1):(console.log("[hmr] Reconnection attempts exhausted. Server is unavailable."),clearInterval(i))},5e3))}),_},u=async()=>{let t=await d();window.joystick.mount(t,Object.assign({},window.__joystick_ssr_props__),document.getElementById("app"))},d=async()=>(await import(`${window.__joystick_page_url__}?v=${new Date().getTime()}`).catch(e=>{location.reload()}))?.default,p=async()=>(await import(`${window.__joystick_layout_url__}?v=${new Date().getTime()}`).catch(e=>{location.reload()}))?.default,y=async()=>{let t=await p(),e=await d();window.joystick.mount(t,Object.assign({page:e},window.__joystick_ssr_props__),document.getElementById("app"))},w=t=>{let e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("href","/_joystick/index.css"),document.head.replaceChild(e,t)},g=(t={})=>{let e=document.createElement("script");e.setAttribute("type","text/javascript"),e.setAttribute("src","/_joystick/index.client.js"),t.parentNode.replaceChild(e,t)},
|
|
1
|
+
var i=null,c=0,l=(t={},e=null)=>{let o=new WebSocket(`ws://localhost:${window.__joystick_hmr_port__}/_joystick/hmr?${new URLSearchParams(t.query).toString()}`);i&&(clearInterval(i),i=null);let _={client:o,send:(n={})=>(t.queryParams&&(n={...n,...t.queryParams}),o.send(JSON.stringify(n)))};return o.addEventListener("open",()=>{console.log("[hmr] Listening for changes..."),c=0,e&&e(_)}),o.addEventListener("message",n=>{n?.data&&t.onMessage&&t.onMessage(JSON.parse(n.data),_)}),o.addEventListener("close",()=>{console.log("[hmr] Disconnected from server."),o=null,t.autoReconnect&&!i&&(i=setInterval(()=>{o=null,c<12?(l(t,e),console.log(`[hmr] Attempting to reconnect (${c+1}/12)...`),c+=1):(console.log("[hmr] Reconnection attempts exhausted. Server is unavailable."),clearInterval(i))},5e3))}),_},u=async()=>{let t=await d();window.joystick.mount(t,Object.assign({},window.__joystick_ssr_props__),document.getElementById("app"))},d=async()=>(await import(`${window.__joystick_page_url__}?v=${new Date().getTime()}`).catch(e=>{location.reload()}))?.default,p=async()=>(await import(`${window.__joystick_layout_url__}?v=${new Date().getTime()}`).catch(e=>{location.reload()}))?.default,y=async()=>{let t=await p(),e=await d();window.joystick.mount(t,Object.assign({page:e},window.__joystick_ssr_props__),document.getElementById("app"))},w=t=>{let e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("href","/_joystick/index.css"),document.head.replaceChild(e,t)},g=(t={})=>{let e=document.createElement("script");e.setAttribute("type","text/javascript"),e.setAttribute("src","/_joystick/index.client.js"),t.parentNode.replaceChild(e,t)},j=l({autoReconnect:!0,query:{user_language:window?.__joystick_user__?.language||"",browser_language:navigator?.language||"",page_component_path:window.__joystick_page_url__?.replace("/_joystick/","")},onMessage:async(t={},e={})=>{if(console.log("HMR",t),t&&t.type&&t.type==="BUILD_ERROR")return location.reload();window.__joystick_hmr_update__=!0,window.__joystick_hmr_previous_tree__=[...window.joystick._internal.tree||[]],window.__joystick_hmr_previous_websockets__=[...window.joystick._internal.websockets||[]];let _=Object.assign({},{scrollTop:window.scrollY}),n=t&&t.type&&t.type==="FILE_CHANGE",r=!!window.__joystick_layout_url__&&!!window.__joystick_page_url__,s=document.head.querySelector('link[href="/_joystick/index.css"]'),a=document.body.querySelector('script[src="/_joystick/index.client.js"]');t?.index_html_changed&&location.reload(),t?.i18n&&(window.__joystick_i18n__=t?.i18n),t?.settings&&(window.__joystick_settings__=t?.settings,window.joystick.settings=t?.settings),a&&t?.index_client_changed&&g(a),s&&t?.index_css_changed&&w(s),n&&r&&y(e),n&&!r&&u(e),window.scrollTo(0,_.scrollTop),e.send&&e.send({type:"HMR_UPDATE_COMPLETE"})}}),m=j;export{m as default};
|
package/package.json
CHANGED
package/src/app/api/get.js
CHANGED
|
@@ -80,7 +80,7 @@ const get = async ({
|
|
|
80
80
|
|
|
81
81
|
return Promise.reject({
|
|
82
82
|
errors: validation_errors.map((error) => {
|
|
83
|
-
return format_api_error(new Error(error), `getters.${get_name}.input`,
|
|
83
|
+
return format_api_error(new Error(error), `getters.${get_name}.input`, 400);
|
|
84
84
|
}),
|
|
85
85
|
});
|
|
86
86
|
}
|
|
@@ -2,6 +2,62 @@ import types from '../../lib/types.js';
|
|
|
2
2
|
import validate_type from "./validate_type.js";
|
|
3
3
|
import is_array_path from "./is_array_path.js";
|
|
4
4
|
|
|
5
|
+
const allowed_values = (rule_value, input_value, parent_path) => {
|
|
6
|
+
const isValid = rule_value.includes(input_value);
|
|
7
|
+
|
|
8
|
+
if (!isValid) {
|
|
9
|
+
return {
|
|
10
|
+
valid: false,
|
|
11
|
+
errors: [
|
|
12
|
+
`Field ${parent_path} only allows the following values: ${rule_value.join(
|
|
13
|
+
", "
|
|
14
|
+
)}.`,
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
valid: true,
|
|
21
|
+
errors: [],
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const max_length = (rule_value, input_value, parent_path) => {
|
|
26
|
+
const valid = types.is_array(input_value) && input_value?.length <= rule_value;
|
|
27
|
+
|
|
28
|
+
if (!valid) {
|
|
29
|
+
return {
|
|
30
|
+
valid: false,
|
|
31
|
+
errors: [
|
|
32
|
+
`Field ${parent_path} length must be less than or equal to ${rule_value}.`,
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
valid: true,
|
|
39
|
+
errors: [],
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const min_length = (rule_value, input_value, parent_path) => {
|
|
44
|
+
const valid = types.is_array(input_value) && input_value?.length >= rule_value;
|
|
45
|
+
|
|
46
|
+
if (!valid) {
|
|
47
|
+
return {
|
|
48
|
+
valid: false,
|
|
49
|
+
errors: [
|
|
50
|
+
`Field ${parent_path} length must be greater than or equal to ${rule_value}.`,
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
valid: true,
|
|
57
|
+
errors: [],
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
5
61
|
const input_validators = {
|
|
6
62
|
types: [
|
|
7
63
|
"any",
|
|
@@ -14,25 +70,8 @@ const input_validators = {
|
|
|
14
70
|
"string",
|
|
15
71
|
],
|
|
16
72
|
rules: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!isValid) {
|
|
21
|
-
return {
|
|
22
|
-
valid: false,
|
|
23
|
-
errors: [
|
|
24
|
-
`Field ${parent_path} only allows the following values: ${rule_value.join(
|
|
25
|
-
", "
|
|
26
|
-
)}.`,
|
|
27
|
-
],
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
valid: true,
|
|
33
|
-
errors: [],
|
|
34
|
-
};
|
|
35
|
-
},
|
|
73
|
+
allowed_values,
|
|
74
|
+
allowedValues: allowed_values,
|
|
36
75
|
element: async (rule_value, input_value, parent_path, validate_input) => {
|
|
37
76
|
// NOTE: Allow for element to be passed as a type string so you can do arrays of single
|
|
38
77
|
// primitive elements (e.g., ['a', 'b', 'c'] or [1, 2, 3]).
|
|
@@ -110,23 +149,8 @@ const input_validators = {
|
|
|
110
149
|
errors: [],
|
|
111
150
|
};
|
|
112
151
|
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (!valid) {
|
|
117
|
-
return {
|
|
118
|
-
valid: false,
|
|
119
|
-
errors: [
|
|
120
|
-
`Field ${parent_path} length must be less than or equal to ${rule_value}.`,
|
|
121
|
-
],
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
valid: true,
|
|
127
|
-
errors: [],
|
|
128
|
-
};
|
|
129
|
-
},
|
|
152
|
+
max_length,
|
|
153
|
+
maxLength: max_length,
|
|
130
154
|
min: (rule_value, input_value, parent_path) => {
|
|
131
155
|
const valid = input_value >= rule_value;
|
|
132
156
|
|
|
@@ -144,23 +168,8 @@ const input_validators = {
|
|
|
144
168
|
errors: [],
|
|
145
169
|
};
|
|
146
170
|
},
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (!valid) {
|
|
151
|
-
return {
|
|
152
|
-
valid: false,
|
|
153
|
-
errors: [
|
|
154
|
-
`Field ${parent_path} length must be greater than or equal to ${rule_value}.`,
|
|
155
|
-
],
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return {
|
|
160
|
-
valid: true,
|
|
161
|
-
errors: [],
|
|
162
|
-
};
|
|
163
|
-
},
|
|
171
|
+
min_length,
|
|
172
|
+
minLength: min_length,
|
|
164
173
|
optional: (rule_value, input_value, parent_path) => {
|
|
165
174
|
const valid = rule_value === false ? !!input_value : true;
|
|
166
175
|
|
|
@@ -136,6 +136,7 @@ const hmr_client = (() =>
|
|
|
136
136
|
page_component_path: window.__joystick_page_url__?.replace('/_joystick/', ''),
|
|
137
137
|
},
|
|
138
138
|
onMessage: async (message = {}, websocket_client_connection = {}) => {
|
|
139
|
+
console.log('HMR', message);
|
|
139
140
|
const is_build_error = message && message.type && message.type === "BUILD_ERROR";
|
|
140
141
|
|
|
141
142
|
if (is_build_error) {
|