@hostlink/light 1.0.0 → 1.0.1
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/light.js +2 -0
- package/dist/light.umd.cjs +1 -1
- package/dist/model.d.ts +3 -1
- package/package.json +1 -1
package/dist/light.js
CHANGED
|
@@ -30,6 +30,8 @@ const $ = (e) => {
|
|
|
30
30
|
for (const r of Object.entries(t)) {
|
|
31
31
|
const [n, s] = r;
|
|
32
32
|
g[e][n] = () => ({
|
|
33
|
+
name: s.name ? s.name : n,
|
|
34
|
+
raw: s,
|
|
33
35
|
getName: () => s.name ? s.name : n,
|
|
34
36
|
getGQLField: () => s.gqlField !== void 0 ? s.gqlField : s.name || n,
|
|
35
37
|
getRaw() {
|
package/dist/light.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(i,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("axios"),require("json-to-graphql-query")):typeof define=="function"&&define.amd?define(["exports","axios","json-to-graphql-query"],w):(i=typeof globalThis<"u"?globalThis:i||self,w(i.light={},i.axios,i.jsonToGraphqlQuery))})(this,function(i,w,h){"use strict";const E=(e,t,r="")=>l("login",{username:e,password:t,code:r}),N=()=>l("logout"),P=(e,t)=>l("updatePassword",{old_password:e,new_password:t}),J=(e,t,r)=>l("resetPassword",{email:e,password:t,code:r}),D=e=>l("forgetPassword",{email:e});let y;const M=e=>{y=e},F=()=>(y||(y=w.create({withCredentials:!0})),y),T=async e=>(await g({granted:{__args:{rights:e}}})).granted,m={},Q=(e,t)=>{m[e]={};for(const r of Object.entries(t)){const[n,s]=r;m[e][n]=()=>({name:s.name?s.name:n,raw:s,getName:()=>s.name?s.name:n,getGQLField:()=>s.gqlField!==void 0?s.gqlField:s.name||n,getRaw(){return s},getValue(c){return s.field&&typeof s.field=="function"?s.field(c):s.field&&typeof s.field=="string"?c[s.field]:c[this.getName()]},getFormattedValue(c){const d=this.getValue(c);return s.format?s.format(d):d}})}},O=(e,t)=>!m[e]||!m[e][t]?null:m[e][t](),U=(e,t)=>{const r=[];for(const n of t)if(typeof n=="string"){const s=O(e,n);s&&r.push(s.getGQLField())}else typeof n=="object"&&r.push(n);return r},_=e=>{let t={};return typeof e=="string"?(t[e]=!0,t):e instanceof Array?(e.forEach(r=>{Object.entries(_(r)).forEach(([n,s])=>{t[n]=s})}),t):(Object.entries(e).forEach(([r,n])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){t[r]=n;return}if(typeof n=="boolean"){t[r]=n;return}t[r]=_(n)}),t)},v=e=>_(e),g=async e=>{let t=h.jsonToGraphQLQuery(v(e));const r=await F().post(b(),{query:`{ ${t} }`});if(r.data.errors)throw new Error(r.data.errors[0].message);return r.data.data},l=async(e,t=null,r=[])=>{const n={mutation:{}};n.mutation[e]=!0,r instanceof Array&&r.length!=0&&(n.mutation[e]={}),t&&(n.mutation[e]={},n.mutation[e].__args=t),Object.entries(v(r)).forEach(([c,d])=>{n.mutation[e][c]=d});const s=await F().post(b(),{query:h.jsonToGraphQLQuery(n)});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data[e]};let C="/api/";const V=e=>{C=e},b=()=>C;async function K(e){const t={__variables:{file:"Upload!"},fsUploadTempFile:{__args:{file:new h.VariableType("file")},name:!0,path:!0,size:!0,mime:!0}},r=new FormData;r.append("operations",JSON.stringify({query:h.jsonToGraphQLQuery({mutation:t})})),r.append("map",JSON.stringify({0:["variables.file"]})),r.append("0",e);const n=await F().post(b(),r);if(n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data.fsUploadTempFile}const G=(e,t,r)=>l("sendMail",{email:e,subject:t,message:r}),W=async e=>(await g({config:{__args:{name:e}}})).config;function R(e){const t="==".slice(0,(4-e.length%4)%4),r=e.replace(/-/g,"+").replace(/_/g,"/")+t,n=atob(r),s=new ArrayBuffer(n.length),c=new Uint8Array(s);for(let d=0;d<n.length;d++)c[d]=n.charCodeAt(d);return s}function S(e){const t=new Uint8Array(e);let r="";for(const c of t)r+=String.fromCharCode(c);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var a="copy",f="convert";function p(e,t,r){if(t===a)return r;if(t===f)return e(r);if(t instanceof Array)return r.map(n=>p(e,t[0],n));if(t instanceof Object){const n={};for(const[s,c]of Object.entries(t)){if(c.derive){const d=c.derive(r);d!==void 0&&(r[s]=d)}if(!(s in r)){if(c.required)throw new Error(`Missing key: ${s}`);continue}if(r[s]==null){n[s]=null;continue}n[s]=p(e,c.schema,r[s])}return n}}function A(e,t){return{required:!0,schema:e,derive:t}}function o(e){return{required:!0,schema:e}}function u(e){return{required:!1,schema:e}}var q={type:o(a),id:o(f),transports:u(a)},L={appid:u(a),appidExclude:u(a),credProps:u(a)},j={appid:u(a),appidExclude:u(a),credProps:u(a)},B={publicKey:o({rp:o(a),user:o({id:o(f),name:o(a),displayName:o(a)}),challenge:o(f),pubKeyCredParams:o(a),timeout:u(a),excludeCredentials:u([q]),authenticatorSelection:u(a),attestation:u(a),extensions:u(L)}),signal:u(a)},I={type:o(a),id:o(a),rawId:o(f),authenticatorAttachment:u(a),response:o({clientDataJSON:o(f),attestationObject:o(f),transports:A(a,e=>{var t;return((t=e.getTransports)==null?void 0:t.call(e))||[]})}),clientExtensionResults:A(j,e=>e.getClientExtensionResults())},z={mediation:u(a),publicKey:o({challenge:o(f),timeout:u(a),rpId:u(a),allowCredentials:u([q]),userVerification:u(a),extensions:u(L)}),signal:u(a)},$={type:o(a),id:o(a),rawId:o(f),authenticatorAttachment:u(a),response:o({clientDataJSON:o(f),authenticatorData:o(f),signature:o(f),userHandle:o(f)}),clientExtensionResults:A(j,e=>e.getClientExtensionResults())};function H(e){return p(R,B,e)}function X(e){return p(S,I,e)}function Y(e){return p(R,z,e)}function Z(e){return p(S,$,e)}async function k(e){const t=await navigator.credentials.create(e);return t.toJSON=()=>X(t),t}async function x(e){const t=await navigator.credentials.get(e);return t.toJSON=()=>Z(t),t}async function ee(e){const r=(await g({webAuthnRequestOptions:{__args:{username:e}}})).webAuthnRequestOptions,n=Y({publicKey:r}),s=await x(n);await l("webAuthnAssertion",{username:e,assertion:s.toJSON()})}async function te(){const e=await g({webAuthnCreationOptions:!0}),t=H({publicKey:e.webAuthnCreationOptions}),r=await k(t);await l("webAuthnRegister",{registration:r.toJSON()})}const re=async e=>(await g({fsListFiles:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}})).fsListFiles,ne=async e=>(await g({fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,se=async e=>{let t=await g({fsFile:{__args:{path:e},base64Content:!0}});return window.atob(t.fsFile.base64Content)},ie=(e,t)=>l("fsWriteFile",{path:e,content:t}),ae=e=>l("fsDeleteFile",{path:e}),oe=e=>l("fsCreateFolder",{path:e}),ue=e=>l("fsDeleteFolder",{path:e}),le=(e,t)=>l("fsRenameFile",{path:e,name:t}),ce=(e,t)=>l("fsRenameFolder",{path:e,name:t}),fe=(e,t)=>l("fsMoveFile",{source:e,target:t});i.defineModel=Q,i.forgetPassword=D,i.fsCreateFolder=oe,i.fsDeleteFile=ae,i.fsDeleteFolder=ue,i.fsListFiles=re,i.fsListFolders=ne,i.fsMoveFile=fe,i.fsReadFile=se,i.fsRenameFile=le,i.fsRenameFolder=ce,i.fsWriteFile=ie,i.getApiUrl=b,i.getAxios=F,i.getConfig=W,i.getGQLFields=U,i.getModelField=O,i.granted=T,i.login=E,i.logout=N,i.mutation=l,i.query=g,i.resetPassword=J,i.sendMail=G,i.setApiUrl=V,i.setAxios=M,i.toQuery=v,i.updatePassword=P,i.uploadFile=K,i.webauthnLogin=ee,i.webauthnRegister=te,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
package/dist/model.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export type ModelField = {
|
|
2
|
+
name: string;
|
|
3
|
+
raw: FieldOption;
|
|
2
4
|
getName: () => string;
|
|
3
5
|
getGQLField: () => string | object;
|
|
4
6
|
getRaw: () => FieldOption;
|
|
@@ -20,4 +22,4 @@ export declare const defineModel: (name: string, fields: {
|
|
|
20
22
|
[key: string]: FieldOption;
|
|
21
23
|
}) => void;
|
|
22
24
|
export declare const getModelField: (name: string, field: string) => ModelField | null;
|
|
23
|
-
export declare const getGQLFields: (model: string, fields: (string | object)[]) => any;
|
|
25
|
+
export declare const getGQLFields: (model: string, fields: (string | object)[]) => any[];
|