@web-sharp/core 0.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/README.md +3 -0
- package/esm/index.d.ts +40 -0
- package/esm/index.js +1 -0
- package/package.json +31 -0
package/README.md
ADDED
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as _web_sharp_types from '@web-sharp/types';
|
|
2
|
+
import { BaseOptionsType, IAnyObject, BasePluginType, BreadcrumbPushData } from '@web-sharp/types';
|
|
3
|
+
|
|
4
|
+
declare abstract class Core<O extends BaseOptionsType> {
|
|
5
|
+
private readonly options;
|
|
6
|
+
private context;
|
|
7
|
+
protected appID: string;
|
|
8
|
+
protected readonly taskQueue: Array<IAnyObject>;
|
|
9
|
+
private isReady;
|
|
10
|
+
constructor(options: O);
|
|
11
|
+
initConsole(): void;
|
|
12
|
+
private bindOptions;
|
|
13
|
+
use(plugins: BasePluginType[]): void;
|
|
14
|
+
executeTaskQueue(): void;
|
|
15
|
+
getClientOptions(): O;
|
|
16
|
+
getContext(): {
|
|
17
|
+
app: _web_sharp_types.AppInfoType;
|
|
18
|
+
uploadUrl: string;
|
|
19
|
+
initUrl: string;
|
|
20
|
+
debug: boolean;
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
};
|
|
23
|
+
abstract isRightEnv(): boolean;
|
|
24
|
+
abstract nextTick(cb: Function, ctx: Object, ...args: any[]): void;
|
|
25
|
+
abstract initAPP(): Promise<string>;
|
|
26
|
+
abstract transform(datas: IAnyObject): IAnyObject;
|
|
27
|
+
abstract report(url: string, datas: IAnyObject, type?: any): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare class Breadcrumb<O extends BaseOptionsType> {
|
|
31
|
+
private readonly maxBreadcrumbs;
|
|
32
|
+
private stack;
|
|
33
|
+
constructor(options?: Partial<O>);
|
|
34
|
+
unshift(data: BreadcrumbPushData): BreadcrumbPushData[];
|
|
35
|
+
private pop;
|
|
36
|
+
clear(): void;
|
|
37
|
+
getStack(): BreadcrumbPushData[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { Breadcrumb, Core };
|
package/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{TAG as t,ConsoleTypes as e,BreadcrumbLevel as s}from"@web-sharp/types";import{formateUrlPath as i}from"@web-sharp/utils";var o=Object.defineProperty,n=(t,e,s)=>((t,e,s)=>e in t?o(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s)(t,"symbol"!=typeof e?e+"":e,s);class r{constructor(){n(this,"dep",new Map)}watch(t,e){const s=this.dep.get(t);s?this.dep.set(t,s.concat(e)):this.dep.set(t,[e])}notify(t,e){const s=this.dep.get(t);t&&s&&s.forEach(t=>{try{t(e)}catch(t){console.error(t)}})}}var a=Object.defineProperty,c=Object.getOwnPropertySymbols,h=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,l=(t,e,s)=>e in t?a(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,u=(t,e)=>{for(var s in e||(e={}))h.call(e,s)&&l(t,s,e[s]);if(c)for(var s of c(e))p.call(e,s)&&l(t,s,e[s]);return t},d=(t,e,s)=>l(t,"symbol"!=typeof e?e+"":e,s);class b{constructor(e){d(this,"options"),d(this,"context"),d(this,"appID"),d(this,"taskQueue"),d(this,"isReady"),this.options=e,this.initConsole(),this.isRightEnv()?(this.bindOptions(),this.isReady=!1,this.taskQueue=[],this.initAPP().then(t=>{console.log("init app"),t&&this.appID!==t&&(this.appID=t),this.isReady=!0,this.executeTaskQueue()})):console.warn(t,"Client does not match the environment")}initConsole(){const{debug:t}=this.options;t&&"undefined"!=typeof console||Object.keys(e).forEach(t=>{console[t]=()=>null})}bindOptions(){const{dsn:e,app:s,debug:o=!1,enabled:n=!0}=this.options;if(!s||!e)return void console.warn(t,"Missing app or dsn in options");const{host:r,init:a,report:c=""}=e,h=i(r,a),p=i(r,c);this.context={app:s,uploadUrl:p,initUrl:h,debug:o,enabled:n}}use(t){const{uploadUrl:e,enabled:s}=this.context,i=new r,o=new Map;for(const n of t){const{name:t,monitor:r,transform:a}=n||{};if(!t||!r){console.warn("The plugin missing name or monitor.");continue}if(o.has(t)){console.warn(`The plugin name [${t}] is duplicate, please modify it.`);continue}o.set(t,1);try{r.call(this,i.notify.bind(i,t))}catch(t){console.error(t)}const c=(...t)=>{const i="function"==typeof a?a.apply(this,t):t;if(!i)return;const o=this.transform(i);o&&s&&(this.isReady?this.nextTick(this.report,this,e,u({aid:this.appID},o)):this.taskQueue.push(o))};i.watch(t,c)}}executeTaskQueue(){const{uploadUrl:t}=this.context;for(;this.taskQueue.length;){const e=this.taskQueue.shift();console.log("执行任务队列",e),this.nextTick(this.report,this,t,u({aid:this.appID},e))}}getClientOptions(){return u({},this.options)}getContext(){return u({},this.context)}}var f=Object.defineProperty,m=(t,e,s)=>((t,e,s)=>e in t?f(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s)(t,"symbol"!=typeof e?e+"":e,s);class y{constructor(t={}){m(this,"maxBreadcrumbs"),m(this,"stack"),this.maxBreadcrumbs=t.maxBreadcrumbs||80,this.stack=[]}unshift(t){return t.l||(t.l=s.INFO),this.stack.length>=this.maxBreadcrumbs&&this.pop(),this.stack.unshift(t),this.stack.sort((t,e)=>e.t-t.t),this.stack}pop(){return void 0!==this.stack.pop()}clear(){this.stack=[]}getStack(){return this.stack.slice(0)}}export{y as Breadcrumb,b as Core};
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@web-sharp/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "@web-sharp/core",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "",
|
|
7
|
+
"main": "esm/index.js",
|
|
8
|
+
"module": "esm/index.js",
|
|
9
|
+
"types": "esm/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"esm"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/ShetePro/web-sharp.git"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/ShetePro/web-sharp.git/issues"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"dev": "rimraf esm && rollup -c -w",
|
|
25
|
+
"build": "rimraf esm && rollup -c"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@web-sharp/types": "workspace:^",
|
|
29
|
+
"@web-sharp/utils": "workspace:^"
|
|
30
|
+
}
|
|
31
|
+
}
|