fmode-ng 0.0.208 → 0.0.209
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.
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* 保留所有权利 All Rights Reserved.
|
|
6
6
|
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/core/parse/fmode.object.mjs
|
|
7
7
|
*/
|
|
8
|
-
import{FmodeRelation}from"./datatype/relation";export class FmodeObject{static{this._instance=null}static bindInstance(
|
|
8
|
+
import{FmodeRelation}from"./datatype/relation";export class FmodeObject{static{this._instance=null}static bindInstance(e){this._instance=e}constructor(e){this.data={},this.className=e}static extend(e){const t=class extends FmodeObject{constructor(){super(e)}};return t.extend=FmodeObject.extend,t.create=FmodeObject.create,t.fetchAll=FmodeObject.fetchAll,t.fromFile=FmodeObject.fromFile,t.bindInstance=FmodeObject.bindInstance,t._instance=FmodeObject._instance,t}toPointer(){return{__type:"Pointer",className:this.className,objectId:this.id}}toJSON(){const e={__type:"Object",className:this.className,...this.data};this.id&&(e.objectId=this.id),Object.keys(e).forEach((t=>{e[t]?.getTime?.()&&(e[t]={__type:"Date",iso:e[t].toISOString()})}));try{this.createdAt&&("string"==typeof this.createdAt&&(this.createdAt=new Date(this.createdAt)),e.createdAt={__type:"Date",iso:this.createdAt.toISOString()}),this.updatedAt&&("string"==typeof this.updatedAt&&(this.updatedAt=new Date(this.updatedAt)),console.log(this.updatedAt),e.updatedAt={__type:"Date",iso:this.updatedAt.toISOString()})}catch(e){}return this.ACL&&(e.ACL=this.ACL),e}get(e){return"Date"==this.data[e]?.__type?new Date(this.data[e]?.iso):this.data[e]}isoStrToDate(e){if(e?.indexOf?.("T")>-1&&e?.indexOf?.("Z")>-1&&24==e?.length)try{return new Date(e)}catch(e){}return e}set(e,t){return"object"==typeof e?(Object.keys(e).forEach((t=>{e[t]?.indexOf?.("T")>-1&&e[t]?.indexOf?.("Z")>-1&&(e[t]=this.isoStrToDate(e[t]))})),Object.assign(this.data,e)):(t&&(t=this.isoStrToDate(t)),this.data[e]=t),this}unset(e){return delete this.data[e],this}increment(e,t=1){const s=this.get(e)||0;return this.set(e,s+t),this}add(e,t){const s=this.get(e)||[];return this.set(e,[...s,...t]),this}addUnique(e,t){const s=new Set(this.get(e)||new Set);return t.forEach((e=>s.add(e))),this.set(e,Array.from(s)),this}remove(e,t){const s=this.get(e)||[],i=new Set(t);return this.set(e,s.filter((e=>!i.has(e)))),this}async save(e){if(!FmodeObject._instance)throw new Error("Not initialized");const t=this.id?"PUT":"POST";let s=`${FmodeObject._instance.serverURL}/classes/${this.className}`;this.id&&(s+=`/${this.id}`);const i={"Content-Type":"application/json","X-Parse-Application-Id":FmodeObject._instance.appId};if(e?.useMasterKey&&FmodeObject._instance.config.masterKey)i["X-Parse-Master-Key"]=FmodeObject._instance.config.masterKey;else{const e=FmodeObject._instance.sessionToken;e&&(i["X-Parse-Session-Token"]=e)}const n=this.toJSON();delete n.createdAt,delete n.updatedAt,delete n.__type,delete n.className;for(const e in n)this.get(e)?.toPointer&&(n[e]=this.get(e).toPointer());const a=await fetch(s,{method:t,headers:i,body:JSON.stringify(n)});console.log(JSON.stringify(n));const o=await a.json();if(console.log(o),o.error)throw new Error(o.error);return this.id=o.objectId||this.id,this.createdAt=new Date(o.createdAt||this.createdAt),this.updatedAt=new Date(o.updatedAt||this.updatedAt),this}async destroy(e){if(!this.id)throw new Error("Cannot destroy unsaved object");if(!FmodeObject._instance)throw new Error("Not initialized");const t={"X-Parse-Application-Id":FmodeObject._instance.appId};if(e?.useMasterKey&&FmodeObject._instance.config.masterKey)t["X-Parse-Master-Key"]=FmodeObject._instance.config.masterKey;else{const e=FmodeObject._instance.sessionToken;e&&(t["X-Parse-Session-Token"]=e)}const s=`${FmodeObject._instance.serverURL}/classes/${this.className}/${this.id}`,i=await fetch(s,{method:"DELETE",headers:t});if(!i.ok){const e=await i.json();throw new Error(e.error||"Failed to delete object")}}static async create(e,t,s){const i=new this(e);return i.set(t),i.save(s)}static async fetchAll(e,t){if(!FmodeObject._instance)throw new Error("Not initialized");if(0===e.length)return[];const s={"Content-Type":"application/json","X-Parse-Application-Id":FmodeObject._instance.appId};if(t?.useMasterKey&&FmodeObject._instance.config.masterKey)s["X-Parse-Master-Key"]=FmodeObject._instance.config.masterKey;else{const e=FmodeObject._instance.sessionToken;e&&(s["X-Parse-Session-Token"]=e)}const i=`${FmodeObject._instance.serverURL}/batch`,n=e.map((e=>({method:"GET",path:`/classes/${e.className}/${e.id}`}))),a=await fetch(i,{method:"POST",headers:s,body:JSON.stringify({requests:n})}),o=await a.json();if(o.error)throw new Error(o.error);return o.map(((t,s)=>{const i=e[s];return i.set(t.success),i}))}relation(e){return new FmodeRelation(this,e)}static async fromFile(e,t,s){if(!FmodeObject._instance)throw new Error("Not initialized");const i=new FormData;i.append("file",t,e);const n={"X-Parse-Application-Id":FmodeObject._instance.appId},a=FmodeObject._instance.sessionToken;a&&(n["X-Parse-Session-Token"]=a);const o=`${FmodeObject._instance.serverURL}/files/${e}`,r=await fetch(o,{method:"POST",headers:n,body:i}),c=await r.json();if(c.error)throw new Error(c.error);return{__type:"File",name:c.name,url:c.url}}}
|
|
9
9
|
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9jb3JlL3BhcnNlL2Ztb2RlLm9iamVjdC5tanM=`
|
|
10
10
|
|