@jolibox/common 1.0.0-beta.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.
- package/README.md +1 -0
- package/dist/__tests__/command/service.test.d.ts +1 -0
- package/dist/__tests__/utils/emitter.test.d.ts +1 -0
- package/dist/__tests__/utils/event.test.d.ts +1 -0
- package/dist/__tests__/utils/singleton.test.d.ts +1 -0
- package/dist/__tests__/utils/test-check.test.d.ts +1 -0
- package/dist/command/commands/registry.d.ts +37 -0
- package/dist/command/commands/service.d.ts +17 -0
- package/dist/command/index.d.ts +8 -0
- package/dist/command/types/index.d.ts +11 -0
- package/dist/command/utils/index.d.ts +5 -0
- package/dist/events/emitter.d.ts +43 -0
- package/dist/events/event.d.ts +7 -0
- package/dist/events/global.d.ts +11 -0
- package/dist/events/index.d.ts +5 -0
- package/dist/events/types.d.ts +3 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.es.js +1 -0
- package/dist/utils/async.d.ts +20 -0
- package/dist/utils/can-i-use.d.ts +21 -0
- package/dist/utils/compare-version.d.ts +2 -0
- package/dist/utils/debounce.d.ts +10 -0
- package/dist/utils/error-types.d.ts +134 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/list.d.ts +15 -0
- package/dist/utils/logger/console.d.ts +7 -0
- package/dist/utils/logger/index.d.ts +1 -0
- package/dist/utils/merge-with.d.ts +4 -0
- package/dist/utils/singleton.d.ts +1 -0
- package/dist/utils/types-check.d.ts +15 -0
- package/dist/utils/wrap-func.d.ts +3 -0
- package/package.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Jolibox JSSDK Interface
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Event } from '@/events';
|
|
2
|
+
import { TypeConstraint } from '../utils';
|
|
3
|
+
export type ICommandsMap = Map<string, ICommand>;
|
|
4
|
+
export interface ICommandHandler {
|
|
5
|
+
(...args: any[]): any;
|
|
6
|
+
}
|
|
7
|
+
export interface ICommand {
|
|
8
|
+
id: string;
|
|
9
|
+
handler: ICommandHandler;
|
|
10
|
+
metadata?: ICommandMetadata | null;
|
|
11
|
+
}
|
|
12
|
+
export interface ICommandMetadata {
|
|
13
|
+
readonly description: string;
|
|
14
|
+
readonly args?: ReadonlyArray<{
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly isOptional?: boolean;
|
|
17
|
+
readonly description?: string;
|
|
18
|
+
readonly constraint?: TypeConstraint;
|
|
19
|
+
readonly schema?: JSON;
|
|
20
|
+
}>;
|
|
21
|
+
readonly returns?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ICommandRegistry {
|
|
24
|
+
onDidRegisterCommand: Event<string>;
|
|
25
|
+
registerCommand(command: ICommand): void;
|
|
26
|
+
getCommand(id: string): ICommand | undefined;
|
|
27
|
+
getCommands(): ICommandsMap;
|
|
28
|
+
}
|
|
29
|
+
export declare class CommandsRegistry implements ICommandRegistry {
|
|
30
|
+
private readonly _commands;
|
|
31
|
+
private readonly _onDidRegisterCommand;
|
|
32
|
+
readonly onDidRegisterCommand: Event<string>;
|
|
33
|
+
constructor();
|
|
34
|
+
registerCommand(command: ICommand): void;
|
|
35
|
+
getCommand(id: string): ICommand | undefined;
|
|
36
|
+
getCommands(): ICommandsMap;
|
|
37
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ICommandService, ICommandEvent } from '../types';
|
|
2
|
+
import { Event } from '@/events';
|
|
3
|
+
export declare class CommandService implements ICommandService {
|
|
4
|
+
readonly _serviceBrand: undefined;
|
|
5
|
+
private _starActivation;
|
|
6
|
+
private readonly _onWillExecuteCommand;
|
|
7
|
+
readonly onWillExecuteCommand: Event<ICommandEvent>;
|
|
8
|
+
private readonly _onDidExecuteCommand;
|
|
9
|
+
readonly onDidExecuteCommand: Event<ICommandEvent>;
|
|
10
|
+
private registry;
|
|
11
|
+
constructor();
|
|
12
|
+
private _activateStar;
|
|
13
|
+
executeCommand<T>(id: string, ...args: any[]): Promise<T>;
|
|
14
|
+
executeCommandThowErr<T>(id: string, ...args: any[]): T;
|
|
15
|
+
private _tryExecuteCommand;
|
|
16
|
+
private invokeFunction;
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ICommandMetadata } from './commands/registry';
|
|
2
|
+
import { CommandType, CommandParamsMap } from '@jolibox/types';
|
|
3
|
+
export interface Commands {
|
|
4
|
+
registerCommand<T extends CommandType>(command: T, callback: CommandParamsMap[T], metadata?: ICommandMetadata): void;
|
|
5
|
+
executeCommand<T extends CommandType>(command: T, ...rest: Parameters<CommandParamsMap[T]>): Promise<ReturnType<CommandParamsMap[T]>>;
|
|
6
|
+
excuteCommandSync<T extends CommandType>(command: T, ...rest: Parameters<CommandParamsMap[T]>): ReturnType<CommandParamsMap[T]>;
|
|
7
|
+
}
|
|
8
|
+
export declare function createCommands(): Commands;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Event } from '@/events';
|
|
2
|
+
export interface ICommandEvent {
|
|
3
|
+
commandId: string;
|
|
4
|
+
args: any[];
|
|
5
|
+
}
|
|
6
|
+
export interface ICommandService {
|
|
7
|
+
readonly _serviceBrand: undefined;
|
|
8
|
+
onWillExecuteCommand: Event<ICommandEvent>;
|
|
9
|
+
onDidExecuteCommand: Event<ICommandEvent>;
|
|
10
|
+
executeCommand<T = any>(commandId: string, ...args: any[]): Promise<T | undefined>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type AnyFunction = (...args: any[]) => any;
|
|
2
|
+
export type TypeConstraint = string | AnyFunction;
|
|
3
|
+
export declare function validateConstraints(args: unknown[], constraints: Array<TypeConstraint | undefined>): void;
|
|
4
|
+
export declare function validateConstraint(arg: unknown, constraint: TypeConstraint | undefined): void;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Event } from './types';
|
|
2
|
+
type EmiiterFunction = <T>(emitter: Emitter<T>) => void;
|
|
3
|
+
export interface EmitterOptions {
|
|
4
|
+
onWillAddFirstListener?: EmiiterFunction;
|
|
5
|
+
onDidRemoveLastListener?: () => void;
|
|
6
|
+
onDidFirstListener?: EmiiterFunction;
|
|
7
|
+
onDidAddListener?: EmiiterFunction;
|
|
8
|
+
onListenerError?: (e?: Error) => void;
|
|
9
|
+
}
|
|
10
|
+
declare class UniqueContainer<T> {
|
|
11
|
+
readonly value: T;
|
|
12
|
+
id: number;
|
|
13
|
+
constructor(value: T);
|
|
14
|
+
}
|
|
15
|
+
type ListenerContainer<T> = UniqueContainer<(data: T) => void>;
|
|
16
|
+
type ListenerOrListeners<T> = (ListenerContainer<T> | undefined)[] | ListenerContainer<T>;
|
|
17
|
+
export declare class Emitter<T> {
|
|
18
|
+
readonly options?: EmitterOptions | undefined;
|
|
19
|
+
private _disposed?;
|
|
20
|
+
private _event?;
|
|
21
|
+
protected _listeners?: ListenerOrListeners<T>;
|
|
22
|
+
protected _size: number;
|
|
23
|
+
constructor(options?: EmitterOptions | undefined);
|
|
24
|
+
dispose(listener?: T): void;
|
|
25
|
+
get event(): Event<T>;
|
|
26
|
+
private _deliver;
|
|
27
|
+
/**
|
|
28
|
+
* To be kept private to fire an event to
|
|
29
|
+
* subscribers
|
|
30
|
+
*/
|
|
31
|
+
fire(event: T): void;
|
|
32
|
+
hasListeners(): boolean;
|
|
33
|
+
}
|
|
34
|
+
type Listener<T extends unknown[] = unknown[]> = (...args: T) => void;
|
|
35
|
+
export declare class EventEmitter<M extends Record<string, unknown[]>, T extends keyof M = keyof M> {
|
|
36
|
+
private listeners;
|
|
37
|
+
private listerHandlerMap;
|
|
38
|
+
private cachedEventQueue;
|
|
39
|
+
on(type: T, listener: Listener<M[T]>): void;
|
|
40
|
+
off(type: T, listener: Listener<M[T]>): void;
|
|
41
|
+
emit(type: T, ...args: M[T]): void;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Event } from './types';
|
|
2
|
+
export declare const None: Event<any>;
|
|
3
|
+
export declare function toPromise<T>(event: Event<T>): Promise<T>;
|
|
4
|
+
export declare function once<T>(event: Event<T>): Event<T>;
|
|
5
|
+
export declare function filter<T, U>(event: Event<T | U>, filter: (e: T | U) => e is T): Event<T>;
|
|
6
|
+
export declare function filter<T>(event: Event<T>, filter: (e: T) => boolean): Event<T>;
|
|
7
|
+
export declare function filter<T, R>(event: Event<T | R>, filter: (e: T | R) => e is R): Event<R>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* global EventEmiiter instance for Interface & Implement
|
|
3
|
+
*/
|
|
4
|
+
import { HostEventType, HostEventParamsMap } from '@jolibox/types';
|
|
5
|
+
export interface HostEmitter {
|
|
6
|
+
on<T extends HostEventType>(event: T, callback: HostEventParamsMap[T]): void;
|
|
7
|
+
off<T extends HostEventType>(event: T, callback: HostEventParamsMap[T]): void;
|
|
8
|
+
emit<T extends HostEventType>(event: T, ...rest: Parameters<HostEventParamsMap[T]>): void;
|
|
9
|
+
}
|
|
10
|
+
declare const hostEmitter: HostEmitter;
|
|
11
|
+
export { hostEmitter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var v=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var le=Object.prototype.hasOwnProperty;var ee=(n,e)=>{for(var r in e)v(n,r,{get:e[r],enumerable:!0})},ue=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of me(e))!le.call(n,o)&&o!==r&&v(n,o,{get:()=>e[o],enumerable:!(t=Z(e,o))||t.enumerable});return n};var ce=n=>ue(v({},"__esModule",{value:!0}),n),C=(n,e,r,t)=>{for(var o=t>1?void 0:t?Z(e,r):e,i=n.length-1,s;i>=0;i--)(s=n[i])&&(o=(t?s(e,r,o):s(o))||o);return t&&o&&v(e,r,o),o};var je={};ee(je,{APIError:()=>G,BaseError:()=>E,Deferred:()=>P,EventEmitter:()=>T,EventUtils:()=>R,InternalApplyNativeError:()=>H,InternalBufferError:()=>J,InternalContextError:()=>z,InternalError:()=>m,InternalInvokeMethodError:()=>j,InternalInvokeNativeError:()=>V,InternalJSCoreNotFoundError:()=>K,InternalJSModuleEvalError:()=>F,InternalJSModuleFetchError:()=>D,InternalMetricReportError:()=>B,InternalReporterError:()=>W,InternalSchemaParseError:()=>S,LoadScriptCode:()=>oe,Singleton:()=>h,UserCustomError:()=>g,UserError:()=>p,UserFetchError:()=>M,UserFunctionEvalError:()=>U,UserGlobalError:()=>L,UserValidateError:()=>k,canIUseConfig:()=>we,compareVersion:()=>Le,createCommands:()=>He,createRunTaskQueue:()=>ye,debounce:()=>Ne,get:()=>ke,hostEmitter:()=>Ve,isArray:()=>_e,isBoolean:()=>xe,isDefined:()=>ve,isFunction:()=>N,isIterable:()=>ge,isNumber:()=>he,isObject:()=>ne,isPromiseLike:()=>Ce,isString:()=>I,isStringArray:()=>Te,isTypedArray:()=>Re,isUndefined:()=>te,isUndefinedOrNull:()=>b,logger:()=>$,mergeArray:()=>be,mergeWith:()=>Ie,microTask:()=>Ee,promisifyAPI:()=>fe,sleep:()=>pe,timeout:()=>w,validateConstraint:()=>ae,validateConstraints:()=>X,wrapUserFunction:()=>Oe});module.exports=ce(je);function w(n){return new Promise(e=>{setTimeout(()=>{e()},n)})}function pe(n){return new Promise(e=>setTimeout(e,n))}function fe(n){return e=>new Promise((r,t)=>{n({...e,success:r,fail(o){let i=new Error(o.errMsg);t(i)}})})}function Ee(n){if(n)Promise.resolve().then(n);else return Promise.resolve()}var P=class{constructor(){this.state="pending";this.promise=new Promise((e,r)=>{this.resolve=t=>{this.state==="pending"&&(this.state="fulfilled",e(t))},this.reject=t=>{this.state==="pending"&&(this.state="rejected",r(t))}})}};function ye(){let n=[],e=!1,r=async()=>{let t=n.shift();if(t){e=!0;try{await t()}finally{e=!1,r()}}};return t=>{n.push(t),e||r()}}function I(n){return typeof n=="string"}function Te(n){return Array.isArray(n)&&n.every(e=>I(e))}function ne(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&!(n instanceof RegExp)&&!(n instanceof Date)}function Re(n){let e=Object.getPrototypeOf(Uint8Array);return typeof n=="object"&&n instanceof e}function _e(n){return typeof n=="object"&&Array.isArray(n)}function he(n){return typeof n=="number"&&!isNaN(n)}function ge(n){return!!n&&typeof n[Symbol.iterator]=="function"}function xe(n){return n===!0||n===!1}function te(n){return typeof n>"u"}function ve(n){return!b(n)}function b(n){return te(n)||n===null}function N(n){return typeof n=="function"}function Ce(n){return ne(n)&&N(n.then)}function h(n){let e=n,r=null,t=function(...o){return r||(r=new e(...o)),r};return t.prototype=e.prototype,t}function Ie(n,e,r){if(typeof r!="function")throw new Error("[Jolibox SDK]Customizer must be a function");function t(o,i){for(let s in i)if(Object.prototype.hasOwnProperty.call(i,s)){let l=o[s],a=i[s],c=r(l,a,s,o,i);c!==void 0?o[s]=c:re(a)&&re(l)?o[s]=t({...l},a):Array.isArray(a)&&Array.isArray(l)?o[s]=[...l,...a]:o[s]=a}return o}return t({...n},e)}function re(n){return n&&typeof n=="object"&&n.constructor===Object}function be(n,e){if(Array.isArray(n))return n.concat(e)}function Ne(n,e,r={}){let t=null,o,i,s,{leading:l=!1,trailing:a=!0}=r,c=()=>(s=n.apply(i,o),o=void 0,i=void 0,s),O=function(...de){o=de,i=this;let q=l&&!t;if(t&&clearTimeout(t),t=setTimeout(()=>{t=null,a&&!q&&c()},e),q)return c()};return O.cancel=()=>{t&&clearTimeout(t),t=null,o=i=void 0},O.flush=()=>{if(t)return clearTimeout(t),t=null,c()},O}var oe=(a=>(a[a.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",a[a.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",a[a.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",a[a.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",a[a.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",a[a.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",a[a.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",a[a.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",a))(oe||{}),E=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},m=class extends E{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},p=class extends E{constructor(){super(...arguments);this.kind="USER_ERROR"}},k=class extends p{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},L=class extends p{constructor(){super(...arguments);this.name="USER_GLOBAL_ERROR";this.priority="P1"}},g=class extends p{constructor(r,t,o){super(r);this.message=r;this.errNo=t;this.name="USER_CUSTOM_ERROR";this.errMsg=r,o&&(this.extra=Object.assign({},this.extra,o))}},M=class extends p{constructor(r,t,o){super(r);this.message=r;this.errNo=t;this.name="USER_FETCH_ERROR";this.errMsg=r,o&&(this.extra=Object.assign({},this.extra,o))}},U=class extends p{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},S=class extends m{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},D=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},F=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},V=class extends m{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},H=class extends m{constructor(r,t,o,i){super(r);this.errNo=t;this.name="INTERNAL_APPLY_NATIVE_ERROR";this.errorType=o,this.errorCode=i}},j=class extends m{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},K=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},J=class extends m{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},z=class extends m{constructor(r,t){super(r);this.message=r;this.name="INTERNAL_CONTEXT_ERROR";this.property=t}},G=class extends E{constructor(r,t,o,i,s){super(r);this.message=r;this.code=t;this.kind="API_ERROR";this.name="API_ERROR";o&&(this.errorType=o),i!==void 0&&(this.stack=i),s&&(this.priority=s)}toJSON(){return{message:this.message,stack:this.stack,name:this.name,code:this.code,errorType:this.errorType}}},B=class extends m{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},W=class extends m{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function Ae(n,e){return(...r)=>e(n,...r)}function Oe(n){return e=>Ae(e,function(r,...t){if(typeof r=="function")try{return r.apply(this,t)}catch(o){n(new g(`${o}`))}})}function x(n){return(...e)=>{(globalThis.VConsole?.[n]??globalThis.console[n])(...e)}}var $={log:x("log"),warn:x("warn"),info:x("info"),error:x("error"),debug:x("debug")};Object.assign(globalThis,{logger:$});var ie=Symbol.for("Jolibox.canIUseMap"),Pe={};globalThis[ie]=Pe;var we={get config(){return globalThis[ie]}};function ke(n,e,r){let t=n;for(let o of e)if(t&&typeof t=="object")t=t[o];else return r;return t===void 0?r:t}function Le(n,e,r){let t=0;if(n!==e){let o=n.split("."),i=e.split("."),s=Math.max(o.length,i.length);for(let l=0;l<s;l++){let a=parseInt(o[l],10)||0,c=parseInt(i[l],10)||0;if(a>c){t=1;break}else if(a<c){t=-1;break}}}if(!r)return t;switch(r){case">":return t>0;case"<":return t<0;case"=":return t===0;case">=":return t>=0;case"<=":return t<=0;default:return!1}}var d=class n{static{this.Undefined=new n(void 0)}constructor(e){this.element=e,this.next=n.Undefined,this.prev=n.Undefined}},A=class{constructor(){this._first=d.Undefined;this._last=d.Undefined;this._size=0}get size(){return this._size}isEmpty(){return this._first===d.Undefined}clear(){let e=this._first;for(;e!==d.Undefined;){let r=e.next;e.prev=d.Undefined,e.next=d.Undefined,e=r}this._first=d.Undefined,this._last=d.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,r){let t=new d(e);if(this._first===d.Undefined)this._first=t,this._last=t;else if(r){let i=this._last;this._last=t,t.prev=i,i.next=t}else{let i=this._first;this._first=t,t.next=i,i.prev=t}this._size+=1;let o=!1;return()=>{o||(o=!0,this._remove(t))}}shift(){if(this._first!==d.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==d.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==d.Undefined&&e.next!==d.Undefined){let r=e.prev;r.next=e.next,e.next.prev=r}else e.prev===d.Undefined&&e.next===d.Undefined?(this._first=d.Undefined,this._last=d.Undefined):e.next===d.Undefined?(this._last=this._last.prev,this._last.next=d.Undefined):e.prev===d.Undefined&&(this._first=this._first.next,this._first.prev=d.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==d.Undefined;)yield e.element,e=e.next}};var Me=0,y=class{constructor(e){this.value=e;this.id=Me++}},u=class{constructor(e){this.options=e;this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof y&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(r=>r?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,r)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(e=e.bind(r));let t=new y(e);this._listeners?this._listeners instanceof y?this._listeners=[this._listeners,t]:this._listeners.push(t):(this.options?.onWillAddFirstListener?.(this),this._listeners=t,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,r){if(!e)return;let t=this.options?.onListenerError||Error.constructor;if(!t){e.value(r);return}try{e.value(r)}catch(o){t(o)}}fire(e){this._listeners&&(this._listeners instanceof y?this._deliver(this._listeners,e):this._listeners.forEach(r=>this._deliver(r,e)))}hasListeners(){return this._size>0}},T=class{constructor(){this.listeners=new Map;this.listerHandlerMap=new WeakMap;this.cachedEventQueue=new Map}on(e,r){let t=this.listeners.get(e)??new u,o=s=>r(...s.args);this.listerHandlerMap.set(r,o),t.event(o),this.listeners.set(e,t);let i=this.cachedEventQueue.get(e);if(i)for(;i.size>0;)t.fire({event:e,...i.shift()})}off(e,r){let t=this.listeners.get(e);if(t){let o=this.listerHandlerMap.get(r);t.dispose(o)}}emit(e,...r){let t=this.listeners.get(e);if(t)t.fire({event:e,args:r});else{let o=this.cachedEventQueue.get(e);o||(o=new A,this.cachedEventQueue.set(e,o)),o.push({args:r})}}};var R={};ee(R,{None:()=>Ue,filter:()=>De,once:()=>se,toPromise:()=>Se});var Ue=()=>{console.log("[Jolibox SDK] None Event")};function Se(n){return new Promise(e=>se(n)(e))}function se(n){return(e,r=null)=>{let t=!1;return n(i=>{if(!t)return t=!0,e.call(r,i)},null)}}function De(n,e){return(t=>{let o,i={onWillAddFirstListener(){o=t(s.fire,s)}},s=new u(i);return s.event})((t,o=null)=>n(i=>e(i)&&t.call(o,i),null))}var Q=Symbol.for("Jolibox.hostEmitter"),Fe=()=>{let n=new T;return globalThis[Q]||(globalThis[Q]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n)}),globalThis[Q]},Ve=Fe();function X(n,e){let r=Math.min(n.length,e.length);for(let t=0;t<r;t++)ae(n[t],e[t])}function ae(n,e){if(I(e)){if(typeof n!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(N(e)){try{if(n instanceof e)return}catch{}if(!b(n)&&n.constructor===e||e.length===1&&e.call(void 0,n)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var f=class{constructor(){this._commands=new Map;this._onDidRegisterCommand=new u;this.onDidRegisterCommand=this._onDidRegisterCommand.event;console.log("[Jolibox SDK] command registry")}registerCommand(e){if(!e)throw new Error("invalid command");if(e.metadata&&Array.isArray(e.metadata.args)){let o=[];for(let s of e.metadata.args)o.push(s.constraint);let i=e.handler;e.handler=function(...s){return X(s,o),i(...s)}}let{id:r}=e;this._commands.get(r)&&console.info(`[Jolibox SDK] duplicated command is registered ${r}`),this._commands.set(r,e),this._onDidRegisterCommand.fire(r)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let r of this._commands.keys()){let t=this.getCommand(r);t&&e.set(r,t)}return e}};f=C([h],f);var _=class{constructor(){this._onWillExecuteCommand=new u;this.onWillExecuteCommand=this._onWillExecuteCommand.event;this._onDidExecuteCommand=new u;this.onDidExecuteCommand=this._onDidExecuteCommand.event;this.registry=new f;this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=w(3e4)),this._starActivation}async executeCommand(e,...r){return this.registry.getCommand(e)?this._tryExecuteCommand(e,r):(await Promise.all([Promise.race([this._activateStar(),R.toPromise(R.filter(this.registry.onDidRegisterCommand,o=>o===e))])]),this._tryExecuteCommand(e,r))}executeCommandThowErr(e,...r){if(!!!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let o=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:r});let i=this.invokeFunction(o.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),i}_tryExecuteCommand(e,r){let t=this.registry.getCommand(e);if(!t)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:r});let o=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),Promise.resolve(o)}catch(o){return Promise.reject(o)}}invokeFunction(e,...r){let t=!1;try{return e(...r)}finally{t=!0}}};_=C([h],_);var Y=Symbol.for("Jolibox.commands");function He(){if(globalThis[Y])return globalThis[Y];let n=new f,e=new _,r={registerCommand(t,o,i){n.registerCommand({id:t,handler:o,metadata:i})},executeCommand(t,...o){return e.executeCommand(t,...o)},excuteCommandSync(t,...o){return e.executeCommandThowErr(t,...o)}};return globalThis[Y]=r,r}
|
package/dist/index.d.ts
ADDED
package/dist/index.es.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var k=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var oe=(n,e)=>{for(var r in e)k(n,r,{get:e[r],enumerable:!0})};var g=(n,e,r,t)=>{for(var o=t>1?void 0:t?re(e,r):e,i=n.length-1,s;i>=0;i--)(s=n[i])&&(o=(t?s(e,r,o):s(o))||o);return t&&o&&k(e,r,o),o};function M(n){return new Promise(e=>{setTimeout(()=>{e()},n)})}function Te(n){return new Promise(e=>setTimeout(e,n))}function Re(n){return e=>new Promise((r,t)=>{n({...e,success:r,fail(o){let i=new Error(o.errMsg);t(i)}})})}function _e(n){if(n)Promise.resolve().then(n);else return Promise.resolve()}var L=class{constructor(){this.state="pending";this.promise=new Promise((e,r)=>{this.resolve=t=>{this.state==="pending"&&(this.state="fulfilled",e(t))},this.reject=t=>{this.state==="pending"&&(this.state="rejected",r(t))}})}};function he(){let n=[],e=!1,r=async()=>{let t=n.shift();if(t){e=!0;try{await t()}finally{e=!1,r()}}};return t=>{n.push(t),e||r()}}function b(n){return typeof n=="string"}function xe(n){return Array.isArray(n)&&n.every(e=>b(e))}function ie(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&!(n instanceof RegExp)&&!(n instanceof Date)}function ve(n){let e=Object.getPrototypeOf(Uint8Array);return typeof n=="object"&&n instanceof e}function Ce(n){return typeof n=="object"&&Array.isArray(n)}function Ie(n){return typeof n=="number"&&!isNaN(n)}function be(n){return!!n&&typeof n[Symbol.iterator]=="function"}function Ne(n){return n===!0||n===!1}function se(n){return typeof n>"u"}function Ae(n){return!N(n)}function N(n){return se(n)||n===null}function A(n){return typeof n=="function"}function Oe(n){return ie(n)&&A(n.then)}function x(n){let e=n,r=null,t=function(...o){return r||(r=new e(...o)),r};return t.prototype=e.prototype,t}function ke(n,e,r){if(typeof r!="function")throw new Error("[Jolibox SDK]Customizer must be a function");function t(o,i){for(let s in i)if(Object.prototype.hasOwnProperty.call(i,s)){let l=o[s],a=i[s],c=r(l,a,s,o,i);c!==void 0?o[s]=c:U(a)&&U(l)?o[s]=t({...l},a):Array.isArray(a)&&Array.isArray(l)?o[s]=[...l,...a]:o[s]=a}return o}return t({...n},e)}function U(n){return n&&typeof n=="object"&&n.constructor===Object}function Le(n,e){if(Array.isArray(n))return n.concat(e)}function Ue(n,e,r={}){let t=null,o,i,s,{leading:l=!1,trailing:a=!0}=r,c=()=>(s=n.apply(i,o),o=void 0,i=void 0,s),I=function(...te){o=te,i=this;let w=l&&!t;if(t&&clearTimeout(t),t=setTimeout(()=>{t=null,a&&!w&&c()},e),w)return c()};return I.cancel=()=>{t&&clearTimeout(t),t=null,o=i=void 0},I.flush=()=>{if(t)return clearTimeout(t),t=null,c()},I}var ae=(a=>(a[a.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",a[a.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",a[a.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",a[a.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",a[a.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",a[a.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",a[a.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",a[a.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",a))(ae||{}),T=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},m=class extends T{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},f=class extends T{constructor(){super(...arguments);this.kind="USER_ERROR"}},S=class extends f{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},D=class extends f{constructor(){super(...arguments);this.name="USER_GLOBAL_ERROR";this.priority="P1"}},v=class extends f{constructor(r,t,o){super(r);this.message=r;this.errNo=t;this.name="USER_CUSTOM_ERROR";this.errMsg=r,o&&(this.extra=Object.assign({},this.extra,o))}},F=class extends f{constructor(r,t,o){super(r);this.message=r;this.errNo=t;this.name="USER_FETCH_ERROR";this.errMsg=r,o&&(this.extra=Object.assign({},this.extra,o))}},V=class extends f{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},H=class extends m{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},j=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},K=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},J=class extends m{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},z=class extends m{constructor(r,t,o,i){super(r);this.errNo=t;this.name="INTERNAL_APPLY_NATIVE_ERROR";this.errorType=o,this.errorCode=i}},G=class extends m{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},B=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},W=class extends m{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},$=class extends m{constructor(r,t){super(r);this.message=r;this.name="INTERNAL_CONTEXT_ERROR";this.property=t}},Q=class extends T{constructor(r,t,o,i,s){super(r);this.message=r;this.code=t;this.kind="API_ERROR";this.name="API_ERROR";o&&(this.errorType=o),i!==void 0&&(this.stack=i),s&&(this.priority=s)}toJSON(){return{message:this.message,stack:this.stack,name:this.name,code:this.code,errorType:this.errorType}}},X=class extends m{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},Y=class extends m{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function de(n,e){return(...r)=>e(n,...r)}function He(n){return e=>de(e,function(r,...t){if(typeof r=="function")try{return r.apply(this,t)}catch(o){n(new v(`${o}`))}})}function R(n){return(...e)=>{(globalThis.VConsole?.[n]??globalThis.console[n])(...e)}}var q={log:R("log"),warn:R("warn"),info:R("info"),error:R("error"),debug:R("debug")};Object.assign(globalThis,{logger:q});var Z=Symbol.for("Jolibox.canIUseMap"),me={};globalThis[Z]=me;var Be={get config(){return globalThis[Z]}};function We(n,e,r){let t=n;for(let o of e)if(t&&typeof t=="object")t=t[o];else return r;return t===void 0?r:t}function Qe(n,e,r){let t=0;if(n!==e){let o=n.split("."),i=e.split("."),s=Math.max(o.length,i.length);for(let l=0;l<s;l++){let a=parseInt(o[l],10)||0,c=parseInt(i[l],10)||0;if(a>c){t=1;break}else if(a<c){t=-1;break}}}if(!r)return t;switch(r){case">":return t>0;case"<":return t<0;case"=":return t===0;case">=":return t>=0;case"<=":return t<=0;default:return!1}}var d=class n{static{this.Undefined=new n(void 0)}constructor(e){this.element=e,this.next=n.Undefined,this.prev=n.Undefined}},C=class{constructor(){this._first=d.Undefined;this._last=d.Undefined;this._size=0}get size(){return this._size}isEmpty(){return this._first===d.Undefined}clear(){let e=this._first;for(;e!==d.Undefined;){let r=e.next;e.prev=d.Undefined,e.next=d.Undefined,e=r}this._first=d.Undefined,this._last=d.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,r){let t=new d(e);if(this._first===d.Undefined)this._first=t,this._last=t;else if(r){let i=this._last;this._last=t,t.prev=i,i.next=t}else{let i=this._first;this._first=t,t.next=i,i.prev=t}this._size+=1;let o=!1;return()=>{o||(o=!0,this._remove(t))}}shift(){if(this._first!==d.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==d.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==d.Undefined&&e.next!==d.Undefined){let r=e.prev;r.next=e.next,e.next.prev=r}else e.prev===d.Undefined&&e.next===d.Undefined?(this._first=d.Undefined,this._last=d.Undefined):e.next===d.Undefined?(this._last=this._last.prev,this._last.next=d.Undefined):e.prev===d.Undefined&&(this._first=this._first.next,this._first.prev=d.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==d.Undefined;)yield e.element,e=e.next}};var le=0,E=class{constructor(e){this.value=e;this.id=le++}},u=class{constructor(e){this.options=e;this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof E&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(r=>r?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,r)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(e=e.bind(r));let t=new E(e);this._listeners?this._listeners instanceof E?this._listeners=[this._listeners,t]:this._listeners.push(t):(this.options?.onWillAddFirstListener?.(this),this._listeners=t,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,r){if(!e)return;let t=this.options?.onListenerError||Error.constructor;if(!t){e.value(r);return}try{e.value(r)}catch(o){t(o)}}fire(e){this._listeners&&(this._listeners instanceof E?this._deliver(this._listeners,e):this._listeners.forEach(r=>this._deliver(r,e)))}hasListeners(){return this._size>0}},_=class{constructor(){this.listeners=new Map;this.listerHandlerMap=new WeakMap;this.cachedEventQueue=new Map}on(e,r){let t=this.listeners.get(e)??new u,o=s=>r(...s.args);this.listerHandlerMap.set(r,o),t.event(o),this.listeners.set(e,t);let i=this.cachedEventQueue.get(e);if(i)for(;i.size>0;)t.fire({event:e,...i.shift()})}off(e,r){let t=this.listeners.get(e);if(t){let o=this.listerHandlerMap.get(r);t.dispose(o)}}emit(e,...r){let t=this.listeners.get(e);if(t)t.fire({event:e,args:r});else{let o=this.cachedEventQueue.get(e);o||(o=new C,this.cachedEventQueue.set(e,o)),o.push({args:r})}}};var h={};oe(h,{None:()=>ue,filter:()=>pe,once:()=>ee,toPromise:()=>ce});var ue=()=>{console.log("[Jolibox SDK] None Event")};function ce(n){return new Promise(e=>ee(n)(e))}function ee(n){return(e,r=null)=>{let t=!1;return n(i=>{if(!t)return t=!0,e.call(r,i)},null)}}function pe(n,e){return(t=>{let o,i={onWillAddFirstListener(){o=t(s.fire,s)}},s=new u(i);return s.event})((t,o=null)=>n(i=>e(i)&&t.call(o,i),null))}var O=Symbol.for("Jolibox.hostEmitter"),fe=()=>{let n=new _;return globalThis[O]||(globalThis[O]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n)}),globalThis[O]},En=fe();function ne(n,e){let r=Math.min(n.length,e.length);for(let t=0;t<r;t++)Ee(n[t],e[t])}function Ee(n,e){if(b(e)){if(typeof n!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(A(e)){try{if(n instanceof e)return}catch{}if(!N(n)&&n.constructor===e||e.length===1&&e.call(void 0,n)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var p=class{constructor(){this._commands=new Map;this._onDidRegisterCommand=new u;this.onDidRegisterCommand=this._onDidRegisterCommand.event;console.log("[Jolibox SDK] command registry")}registerCommand(e){if(!e)throw new Error("invalid command");if(e.metadata&&Array.isArray(e.metadata.args)){let o=[];for(let s of e.metadata.args)o.push(s.constraint);let i=e.handler;e.handler=function(...s){return ne(s,o),i(...s)}}let{id:r}=e;this._commands.get(r)&&console.info(`[Jolibox SDK] duplicated command is registered ${r}`),this._commands.set(r,e),this._onDidRegisterCommand.fire(r)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let r of this._commands.keys()){let t=this.getCommand(r);t&&e.set(r,t)}return e}};p=g([x],p);var y=class{constructor(){this._onWillExecuteCommand=new u;this.onWillExecuteCommand=this._onWillExecuteCommand.event;this._onDidExecuteCommand=new u;this.onDidExecuteCommand=this._onDidExecuteCommand.event;this.registry=new p;this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=M(3e4)),this._starActivation}async executeCommand(e,...r){return this.registry.getCommand(e)?this._tryExecuteCommand(e,r):(await Promise.all([Promise.race([this._activateStar(),h.toPromise(h.filter(this.registry.onDidRegisterCommand,o=>o===e))])]),this._tryExecuteCommand(e,r))}executeCommandThowErr(e,...r){if(!!!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let o=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:r});let i=this.invokeFunction(o.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),i}_tryExecuteCommand(e,r){let t=this.registry.getCommand(e);if(!t)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:r});let o=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),Promise.resolve(o)}catch(o){return Promise.reject(o)}}invokeFunction(e,...r){let t=!1;try{return e(...r)}finally{t=!0}}};y=g([x],y);var P=Symbol.for("Jolibox.commands");function Vn(){if(globalThis[P])return globalThis[P];let n=new p,e=new y,r={registerCommand(t,o,i){n.registerCommand({id:t,handler:o,metadata:i})},executeCommand(t,...o){return e.executeCommand(t,...o)},excuteCommandSync(t,...o){return e.executeCommandThowErr(t,...o)}};return globalThis[P]=r,r}export{Q as APIError,T as BaseError,L as Deferred,_ as EventEmitter,h as EventUtils,z as InternalApplyNativeError,W as InternalBufferError,$ as InternalContextError,m as InternalError,G as InternalInvokeMethodError,J as InternalInvokeNativeError,B as InternalJSCoreNotFoundError,K as InternalJSModuleEvalError,j as InternalJSModuleFetchError,X as InternalMetricReportError,Y as InternalReporterError,H as InternalSchemaParseError,ae as LoadScriptCode,x as Singleton,v as UserCustomError,f as UserError,F as UserFetchError,V as UserFunctionEvalError,D as UserGlobalError,S as UserValidateError,Be as canIUseConfig,Qe as compareVersion,Vn as createCommands,he as createRunTaskQueue,Ue as debounce,We as get,En as hostEmitter,Ce as isArray,Ne as isBoolean,Ae as isDefined,A as isFunction,be as isIterable,Ie as isNumber,ie as isObject,Oe as isPromiseLike,b as isString,xe as isStringArray,ve as isTypedArray,se as isUndefined,N as isUndefinedOrNull,q as logger,Le as mergeArray,ke as mergeWith,_e as microTask,Re as promisifyAPI,Te as sleep,M as timeout,Ee as validateConstraint,ne as validateConstraints,He as wrapUserFunction};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function timeout(millis: number): Promise<void>;
|
|
2
|
+
export declare function sleep(t: number): Promise<void>;
|
|
3
|
+
type CallbackAPI = (params: {
|
|
4
|
+
success: CallableFunction;
|
|
5
|
+
fail: CallableFunction;
|
|
6
|
+
[k: string]: unknown;
|
|
7
|
+
}) => void;
|
|
8
|
+
export declare function promisifyAPI<T>(api: CallbackAPI): (args: Record<string, unknown>) => Promise<T>;
|
|
9
|
+
export declare function microTask(): Promise<void>;
|
|
10
|
+
export declare function microTask(cb: (...args: unknown[]) => unknown): void;
|
|
11
|
+
export declare class Deferred<T = unknown> {
|
|
12
|
+
readonly promise: Promise<T>;
|
|
13
|
+
readonly state: 'pending' | 'fulfilled' | 'rejected';
|
|
14
|
+
readonly resolve: (response: T | PromiseLike<T>) => void;
|
|
15
|
+
readonly reject: (error: Error) => void;
|
|
16
|
+
constructor();
|
|
17
|
+
}
|
|
18
|
+
export type Task = () => PromiseLike<unknown>;
|
|
19
|
+
export declare function createRunTaskQueue(): (task: Task) => void;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type VersionString = `${number}.${number}.${number}`;
|
|
2
|
+
export interface Version {
|
|
3
|
+
[key: string]: Version | VersionString | false;
|
|
4
|
+
}
|
|
5
|
+
export interface CanIUseInfo {
|
|
6
|
+
version: string | boolean;
|
|
7
|
+
object?: Version;
|
|
8
|
+
success?: Version;
|
|
9
|
+
callback?: Version | string;
|
|
10
|
+
return?: Version | string;
|
|
11
|
+
properties?: Version;
|
|
12
|
+
}
|
|
13
|
+
type GlobalCanIUseMap = {
|
|
14
|
+
h5?: Record<string, CanIUseInfo>;
|
|
15
|
+
native?: Record<string, CanIUseInfo>;
|
|
16
|
+
};
|
|
17
|
+
export declare const canIUseConfig: {
|
|
18
|
+
readonly config: GlobalCanIUseMap;
|
|
19
|
+
};
|
|
20
|
+
export declare function get<T extends Record<string, any>, P extends string[]>(obj: T, paths: P, defaultValue?: any): any;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type DebounceOptions = {
|
|
2
|
+
leading?: boolean;
|
|
3
|
+
trailing?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export type DebouncedFunction<T extends (...args: any[]) => any> = {
|
|
6
|
+
(...args: Parameters<T>): void;
|
|
7
|
+
cancel: () => void;
|
|
8
|
+
flush: () => ReturnType<T> | undefined;
|
|
9
|
+
};
|
|
10
|
+
export declare function debounce<T extends (...args: any[]) => any>(func: T, wait: number, options?: DebounceOptions): DebouncedFunction<T>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
type InternalLifeCycleErrorName = 'INTERNAL_GAME_LAUNCH_ERROR';
|
|
2
|
+
type InternalAPIErrorName = 'INTERNAL_API_ERROR';
|
|
3
|
+
type InternalMetricErrorName = 'INTERNAL_METRIC_REPORT_ERROR';
|
|
4
|
+
type InternalReporterErrorName = 'INTERNAL_REPORTER_ERROR';
|
|
5
|
+
type InternalUtilErrorName = 'INTERNAL_BUFFER_ERROR' | 'INTERNAL_SCHEMA_PARSE_ERROR';
|
|
6
|
+
type InternalInjectErrorName = 'INTERNAL_CONTEXT_ERROR' | 'INTERNAL_JSCORE_ERROR' | 'INTERNAL_JS_MODULE_FETCH_ERROR' | 'INTERNAL_JS_MODULE_EVAL_ERROR';
|
|
7
|
+
type InternalBridgeErrorName = 'INTERNAL_INVOKE_NATIVE_ERROR' | 'INTERNAL_APPLY_NATIVE_ERROR' | 'INTERNAL_INVOKE_METHOD_ERROR';
|
|
8
|
+
type UserErrorName = 'USER_VALIDATE_ERROR' | 'USER_GLOBAL_ERROR' | 'USER_FETCH_ERROR' | 'API_ERROR' | 'USER_CALLBACK_ERROR' | 'USER_CUSTOM_ERROR';
|
|
9
|
+
export type ErrorName = InternalLifeCycleErrorName | InternalInjectErrorName | InternalAPIErrorName | InternalBridgeErrorName | InternalUtilErrorName | InternalReporterErrorName | UserErrorName | InternalMetricErrorName;
|
|
10
|
+
export type ErrorKind = 'INTERNAL_ERROR' | 'USER_ERROR' | 'API_ERROR';
|
|
11
|
+
export type ErrorEnv = 'native' | 'h5';
|
|
12
|
+
export type LoadScriptError = BaseError & {
|
|
13
|
+
code?: number;
|
|
14
|
+
};
|
|
15
|
+
export declare enum LoadScriptCode {
|
|
16
|
+
DEVELOPER_FILE_NOT_FOUND = 0,
|
|
17
|
+
INTERNAL_IOS_CAN_NOT_FOUND_PKG = 1,
|
|
18
|
+
USER_IOS_LOAD_TIMEOUT = 2,
|
|
19
|
+
INTERNAL_IOS_PKG_LOAD_ERROR = 3,
|
|
20
|
+
INTERNAL_IOS_PKG_PARSE_FAIL = 4,
|
|
21
|
+
USER_IOS_GET_EMPTY_DATA = 5,
|
|
22
|
+
USER_ANDROID_GET_PKG_FAIL = 6,
|
|
23
|
+
DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE = 7
|
|
24
|
+
}
|
|
25
|
+
export declare abstract class BaseError extends Error {
|
|
26
|
+
abstract kind: ErrorKind;
|
|
27
|
+
abstract name: ErrorName;
|
|
28
|
+
priority: 'P0' | 'P1';
|
|
29
|
+
env?: ErrorEnv;
|
|
30
|
+
raw?: Error;
|
|
31
|
+
component?: string;
|
|
32
|
+
constructor(error: string | Error);
|
|
33
|
+
}
|
|
34
|
+
export declare abstract class InternalError extends BaseError {
|
|
35
|
+
readonly kind = "INTERNAL_ERROR";
|
|
36
|
+
}
|
|
37
|
+
export declare abstract class UserError extends BaseError {
|
|
38
|
+
readonly kind = "USER_ERROR";
|
|
39
|
+
}
|
|
40
|
+
export declare class UserValidateError extends UserError {
|
|
41
|
+
readonly name = "USER_VALIDATE_ERROR";
|
|
42
|
+
}
|
|
43
|
+
export declare class UserGlobalError extends UserError {
|
|
44
|
+
readonly name = "USER_GLOBAL_ERROR";
|
|
45
|
+
readonly priority = "P1";
|
|
46
|
+
}
|
|
47
|
+
export declare class UserCustomError extends UserError {
|
|
48
|
+
readonly message: string;
|
|
49
|
+
readonly errNo?: number | undefined;
|
|
50
|
+
readonly name = "USER_CUSTOM_ERROR";
|
|
51
|
+
errMsg: string;
|
|
52
|
+
extra?: {
|
|
53
|
+
[key: string]: unknown;
|
|
54
|
+
};
|
|
55
|
+
constructor(message: string, errNo?: number | undefined, extra?: {
|
|
56
|
+
[key: string]: unknown;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export declare class UserFetchError extends UserError {
|
|
60
|
+
readonly message: string;
|
|
61
|
+
readonly errNo?: number | undefined;
|
|
62
|
+
readonly name = "USER_FETCH_ERROR";
|
|
63
|
+
errMsg: string;
|
|
64
|
+
extra?: {
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
};
|
|
67
|
+
constructor(message: string, errNo?: number | undefined, extra?: {
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
export declare class UserFunctionEvalError extends UserError {
|
|
72
|
+
readonly name = "USER_CALLBACK_ERROR";
|
|
73
|
+
}
|
|
74
|
+
export declare class InternalSchemaParseError extends InternalError {
|
|
75
|
+
readonly name = "INTERNAL_SCHEMA_PARSE_ERROR";
|
|
76
|
+
readonly priority = "P0";
|
|
77
|
+
}
|
|
78
|
+
export declare class InternalJSModuleFetchError extends InternalError {
|
|
79
|
+
readonly name = "INTERNAL_JS_MODULE_FETCH_ERROR";
|
|
80
|
+
readonly priority = "P0";
|
|
81
|
+
}
|
|
82
|
+
export declare class InternalJSModuleEvalError extends InternalError {
|
|
83
|
+
readonly name = "INTERNAL_JS_MODULE_EVAL_ERROR";
|
|
84
|
+
readonly priority = "P0";
|
|
85
|
+
}
|
|
86
|
+
export declare class InternalInvokeNativeError extends InternalError {
|
|
87
|
+
readonly name = "INTERNAL_INVOKE_NATIVE_ERROR";
|
|
88
|
+
}
|
|
89
|
+
export declare class InternalApplyNativeError extends InternalError {
|
|
90
|
+
readonly errNo?: number | undefined;
|
|
91
|
+
readonly name = "INTERNAL_APPLY_NATIVE_ERROR";
|
|
92
|
+
errorType?: string;
|
|
93
|
+
errorCode?: number;
|
|
94
|
+
constructor(message: string, errNo?: number | undefined, errorType?: string, errorCode?: number);
|
|
95
|
+
}
|
|
96
|
+
export declare class InternalInvokeMethodError extends InternalError {
|
|
97
|
+
readonly name = "INTERNAL_INVOKE_METHOD_ERROR";
|
|
98
|
+
}
|
|
99
|
+
export declare class InternalJSCoreNotFoundError extends InternalError {
|
|
100
|
+
readonly name = "INTERNAL_JSCORE_ERROR";
|
|
101
|
+
readonly priority = "P0";
|
|
102
|
+
}
|
|
103
|
+
export declare class InternalBufferError extends InternalError {
|
|
104
|
+
readonly name = "INTERNAL_BUFFER_ERROR";
|
|
105
|
+
}
|
|
106
|
+
export declare class InternalContextError extends InternalError {
|
|
107
|
+
readonly message: string;
|
|
108
|
+
readonly name = "INTERNAL_CONTEXT_ERROR";
|
|
109
|
+
readonly property: string;
|
|
110
|
+
constructor(message: string, property: string);
|
|
111
|
+
}
|
|
112
|
+
export declare class APIError extends BaseError {
|
|
113
|
+
readonly message: string;
|
|
114
|
+
readonly code: number;
|
|
115
|
+
readonly kind = "API_ERROR";
|
|
116
|
+
readonly name = "API_ERROR";
|
|
117
|
+
extra?: Record<string, unknown>;
|
|
118
|
+
errorType?: string;
|
|
119
|
+
constructor(message: string, code: number, errorType?: string, stack?: string, priority?: 'P0' | 'P1');
|
|
120
|
+
toJSON(): {
|
|
121
|
+
message: string;
|
|
122
|
+
stack: string | undefined;
|
|
123
|
+
name: string;
|
|
124
|
+
code: number;
|
|
125
|
+
errorType: string | undefined;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
export declare class InternalMetricReportError extends InternalError {
|
|
129
|
+
readonly name = "INTERNAL_METRIC_REPORT_ERROR";
|
|
130
|
+
}
|
|
131
|
+
export declare class InternalReporterError extends InternalError {
|
|
132
|
+
readonly name = "INTERNAL_REPORTER_ERROR";
|
|
133
|
+
}
|
|
134
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './async';
|
|
2
|
+
export * from './types-check';
|
|
3
|
+
export * from './singleton';
|
|
4
|
+
export * from './merge-with';
|
|
5
|
+
export * from './debounce';
|
|
6
|
+
export * from './error-types';
|
|
7
|
+
export * from './wrap-func';
|
|
8
|
+
export * from './logger';
|
|
9
|
+
export * from './can-i-use';
|
|
10
|
+
export * from './compare-version';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class LinkedList<E> {
|
|
2
|
+
private _first;
|
|
3
|
+
private _last;
|
|
4
|
+
private _size;
|
|
5
|
+
get size(): number;
|
|
6
|
+
isEmpty(): boolean;
|
|
7
|
+
clear(): void;
|
|
8
|
+
unshift(element: E): () => void;
|
|
9
|
+
push(element: E): () => void;
|
|
10
|
+
private _insert;
|
|
11
|
+
shift(): E | undefined;
|
|
12
|
+
pop(): E | undefined;
|
|
13
|
+
private _remove;
|
|
14
|
+
[Symbol.iterator](): Iterator<E>;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './console';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
type Customizer<T, S> = (objValue: any, srcValue: any, key: string | number | symbol, object: T, source: S) => any | undefined;
|
|
2
|
+
export declare function mergeWith<T, S>(object: T, source: S, customizer: Customizer<T, S>): T & S;
|
|
3
|
+
export declare function mergeArray(objValue: unknown, srcValue: unknown): any[] | undefined;
|
|
4
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Singleton<T extends new (...args: any[]) => any>(constructor: T): any;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function isString(str: unknown): str is string;
|
|
2
|
+
export declare function isStringArray(value: unknown): value is string[];
|
|
3
|
+
export declare function isObject(obj: unknown): obj is Record<string, unknown>;
|
|
4
|
+
export declare function isTypedArray(obj: unknown): obj is Array<unknown>;
|
|
5
|
+
export declare function isArray(obj: unknown): obj is Array<unknown>;
|
|
6
|
+
export declare function isNumber(obj: unknown): obj is number;
|
|
7
|
+
export declare function isIterable<T>(obj: unknown): obj is Iterable<T>;
|
|
8
|
+
export declare function isBoolean(obj: unknown): obj is boolean;
|
|
9
|
+
export declare function isUndefined(obj: unknown): obj is undefined;
|
|
10
|
+
export declare function isDefined<T>(arg: T | null | undefined): arg is T;
|
|
11
|
+
export declare function isUndefinedOrNull(obj: unknown): obj is undefined | null;
|
|
12
|
+
type AnyFunction = (...args: any[]) => any;
|
|
13
|
+
export declare function isFunction(obj: unknown): obj is AnyFunction;
|
|
14
|
+
export declare function isPromiseLike<T>(res: unknown): res is PromiseLike<T>;
|
|
15
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jolibox/common",
|
|
3
|
+
"description": "This project is common utils for both sdk & implementation",
|
|
4
|
+
"version": "1.0.0-beta.0",
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
|
+
"module": "dist/index.es.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@jolibox/types": "1.0.0-beta.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"typescript": "5.7.3",
|
|
18
|
+
"@types/jest": "28.1.1",
|
|
19
|
+
"rimraf": "6.0.1",
|
|
20
|
+
"esbuild": "0.24.2",
|
|
21
|
+
"@jolibox/eslint-config": "1.0.0"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"clean": "rimraf ./dist",
|
|
25
|
+
"build": "npm run clean && npm run build:cjs && npm run build:esm && tsc",
|
|
26
|
+
"build:cjs": "esbuild ./src/index.ts --log-level=error --format=cjs --outfile=./dist/index.cjs.js --bundle --minify",
|
|
27
|
+
"build:esm": "esbuild ./src/index.ts --log-level=error --format=esm --outfile=./dist/index.es.js --bundle --minify",
|
|
28
|
+
"test": "jest"
|
|
29
|
+
},
|
|
30
|
+
"readme": "# Jolibox JSSDK Interface\n"
|
|
31
|
+
}
|