@jolibox/implement 1.1.4-beta.4
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/.eslintrc.js +3 -0
- package/.rush/temp/package-deps_build.json +104 -0
- package/.rush/temp/shrinkwrap-deps.json +79 -0
- package/README.md +1 -0
- package/dist/common/api-factory/index.d.ts +21 -0
- package/dist/common/api-factory/validator/__tests__/validate/any.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/array.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/arraybuffer.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/boolean.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/enum.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/function.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/literal.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/nullish.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/number.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/object.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/or.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/record.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/string.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/symbol.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/tuple.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/type-asserts.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/utils.test.d.ts +1 -0
- package/dist/common/api-factory/validator/index.d.ts +29 -0
- package/dist/common/api-factory/validator/validate.d.ts +119 -0
- package/dist/common/can-i-use.d.ts +2 -0
- package/dist/common/context/index.d.ts +16 -0
- package/dist/common/context/types.d.ts +5 -0
- package/dist/common/context/url-parse.d.ts +22 -0
- package/dist/common/http/index.d.ts +13 -0
- package/dist/common/http/uuid.d.ts +2 -0
- package/dist/common/http/xua.d.ts +17 -0
- package/dist/common/report/base-tracker.d.ts +13 -0
- package/dist/common/report/create-trace.d.ts +7 -0
- package/dist/common/report/errors/error-types.d.ts +122 -0
- package/dist/common/report/errors/index.d.ts +13 -0
- package/dist/common/report/errors/report/index.d.ts +51 -0
- package/dist/common/report/errors/report/listeners.d.ts +1 -0
- package/dist/common/report/index.d.ts +3 -0
- package/dist/common/report/task-track/index.d.ts +23 -0
- package/dist/common/report/track.d.ts +3 -0
- package/dist/common/report/types.d.ts +75 -0
- package/dist/h5/ads/ads-action-detection.d.ts +6 -0
- package/dist/h5/ads/anti-cheating.d.ts +61 -0
- package/dist/h5/ads/index.d.ts +275 -0
- package/dist/h5/api/base.d.ts +13 -0
- package/dist/h5/api/get-system-info.d.ts +1 -0
- package/dist/h5/api/index.d.ts +4 -0
- package/dist/h5/api/lifecycle.d.ts +1 -0
- package/dist/h5/api/storage.d.ts +27 -0
- package/dist/h5/api/task.d.ts +1 -0
- package/dist/h5/bootstrap/index.d.ts +1 -0
- package/dist/h5/http/index.d.ts +33 -0
- package/dist/h5/http/utils/__tests__/uuid.test.d.ts +1 -0
- package/dist/h5/http/utils/__tests__/xua.test.d.ts +1 -0
- package/dist/h5/http/utils/index.d.ts +14 -0
- package/dist/h5/http/utils/session.d.ts +1 -0
- package/dist/h5/report/errors/index.d.ts +4 -0
- package/dist/h5/report/event-tracker.d.ts +8 -0
- package/dist/h5/report/index.d.ts +10 -0
- package/dist/h5/report/task-tracker.d.ts +14 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5026 -0
- package/dist/index.native.d.ts +2 -0
- package/dist/index.native.js +3743 -0
- package/dist/native/api/base.d.ts +13 -0
- package/dist/native/api/get-system-info.d.ts +1 -0
- package/dist/native/api/index.d.ts +7 -0
- package/dist/native/api/keyboard.d.ts +3 -0
- package/dist/native/api/lifecycle.d.ts +1 -0
- package/dist/native/api/login.d.ts +1 -0
- package/dist/native/api/request.d.ts +1 -0
- package/dist/native/api/storage.d.ts +25 -0
- package/dist/native/api/task.d.ts +1 -0
- package/dist/native/bootstrap/bridge.d.ts +4 -0
- package/dist/native/bootstrap/index.d.ts +1 -0
- package/dist/native/js-bridge/const.d.ts +5 -0
- package/dist/native/js-bridge/index.d.ts +2 -0
- package/dist/native/js-bridge/invoke.d.ts +21 -0
- package/dist/native/js-bridge/js-bridge.d.ts +6 -0
- package/dist/native/js-bridge/report.d.ts +63 -0
- package/dist/native/js-bridge/subscribe.d.ts +8 -0
- package/dist/native/js-bridge/types.d.ts +14 -0
- package/dist/native/js-bridge/utils.d.ts +17 -0
- package/dist/native/js-core/index.d.ts +3 -0
- package/dist/native/js-core/jolibox-js-core.d.ts +45 -0
- package/dist/native/js-core/message-port.d.ts +12 -0
- package/dist/native/js-core/utils.d.ts +7 -0
- package/dist/native/network/create-fetch.d.ts +27 -0
- package/dist/native/network/index.d.ts +11 -0
- package/dist/native/network/report.d.ts +15 -0
- package/dist/native/network/types.d.ts +61 -0
- package/dist/native/network/utils.d.ts +9 -0
- package/dist/native/report/errors/index.d.ts +4 -0
- package/dist/native/report/index.d.ts +10 -0
- package/dist/native/report/task-tracker.d.ts +20 -0
- package/dist/utils/index.d.ts +0 -0
- package/esbuild.config.js +66 -0
- package/implement.build.log +9 -0
- package/package.json +30 -0
- package/src/common/api-factory/index.ts +188 -0
- package/src/common/api-factory/validator/__tests__/validate/any.test.ts +68 -0
- package/src/common/api-factory/validator/__tests__/validate/array.test.ts +402 -0
- package/src/common/api-factory/validator/__tests__/validate/arraybuffer.test.ts +48 -0
- package/src/common/api-factory/validator/__tests__/validate/boolean.test.ts +27 -0
- package/src/common/api-factory/validator/__tests__/validate/enum.test.ts +106 -0
- package/src/common/api-factory/validator/__tests__/validate/function.test.ts +54 -0
- package/src/common/api-factory/validator/__tests__/validate/literal.test.ts +130 -0
- package/src/common/api-factory/validator/__tests__/validate/nullish.test.ts +41 -0
- package/src/common/api-factory/validator/__tests__/validate/number.test.ts +147 -0
- package/src/common/api-factory/validator/__tests__/validate/object.test.ts +131 -0
- package/src/common/api-factory/validator/__tests__/validate/or.test.ts +96 -0
- package/src/common/api-factory/validator/__tests__/validate/record.test.ts +274 -0
- package/src/common/api-factory/validator/__tests__/validate/string.test.ts +187 -0
- package/src/common/api-factory/validator/__tests__/validate/symbol.test.ts +23 -0
- package/src/common/api-factory/validator/__tests__/validate/tuple.test.ts +86 -0
- package/src/common/api-factory/validator/__tests__/validate/type-asserts.test.ts +13 -0
- package/src/common/api-factory/validator/__tests__/validate/utils.test.ts +44 -0
- package/src/common/api-factory/validator/index.ts +107 -0
- package/src/common/api-factory/validator/validate.ts +639 -0
- package/src/common/can-i-use.ts +19 -0
- package/src/common/context/index.ts +91 -0
- package/src/common/context/types.ts +5 -0
- package/src/common/context/url-parse.ts +63 -0
- package/src/common/http/index.ts +29 -0
- package/src/common/http/uuid.ts +11 -0
- package/src/common/http/xua.ts +79 -0
- package/src/common/report/base-tracker.ts +134 -0
- package/src/common/report/create-trace.ts +17 -0
- package/src/common/report/errors/error-types.ts +206 -0
- package/src/common/report/errors/index.ts +20 -0
- package/src/common/report/errors/report/index.ts +63 -0
- package/src/common/report/errors/report/listeners.ts +80 -0
- package/src/common/report/index.ts +3 -0
- package/src/common/report/task-track/index.ts +97 -0
- package/src/common/report/track.ts +49 -0
- package/src/common/report/types.ts +90 -0
- package/src/h5/ads/ads-action-detection.ts +31 -0
- package/src/h5/ads/anti-cheating.ts +244 -0
- package/src/h5/ads/index.ts +641 -0
- package/src/h5/api/base.ts +9 -0
- package/src/h5/api/get-system-info.ts +55 -0
- package/src/h5/api/index.ts +4 -0
- package/src/h5/api/lifecycle.ts +110 -0
- package/src/h5/api/storage.ts +173 -0
- package/src/h5/api/task.ts +197 -0
- package/src/h5/bootstrap/index.ts +16 -0
- package/src/h5/http/index.ts +189 -0
- package/src/h5/http/utils/__tests__/uuid.test.ts +16 -0
- package/src/h5/http/utils/__tests__/xua.test.ts +27 -0
- package/src/h5/http/utils/index.ts +19 -0
- package/src/h5/http/utils/session.ts +10 -0
- package/src/h5/report/errors/index.ts +40 -0
- package/src/h5/report/event-tracker.ts +40 -0
- package/src/h5/report/index.ts +56 -0
- package/src/h5/report/task-tracker.ts +35 -0
- package/src/index.native.ts +7 -0
- package/src/index.ts +9 -0
- package/src/native/api/base.ts +8 -0
- package/src/native/api/get-system-info.ts +41 -0
- package/src/native/api/index.ts +7 -0
- package/src/native/api/keyboard.ts +75 -0
- package/src/native/api/lifecycle.ts +76 -0
- package/src/native/api/login.ts +71 -0
- package/src/native/api/request.ts +154 -0
- package/src/native/api/storage.ts +287 -0
- package/src/native/api/task.ts +267 -0
- package/src/native/bootstrap/bridge.ts +59 -0
- package/src/native/bootstrap/index.ts +58 -0
- package/src/native/js-bridge/const.ts +11 -0
- package/src/native/js-bridge/index.ts +2 -0
- package/src/native/js-bridge/invoke.ts +210 -0
- package/src/native/js-bridge/js-bridge.ts +23 -0
- package/src/native/js-bridge/report.ts +311 -0
- package/src/native/js-bridge/subscribe.ts +50 -0
- package/src/native/js-bridge/types.ts +26 -0
- package/src/native/js-bridge/utils.ts +116 -0
- package/src/native/js-core/index.ts +4 -0
- package/src/native/js-core/jolibox-js-core.ts +188 -0
- package/src/native/js-core/message-port.ts +52 -0
- package/src/native/js-core/utils.ts +9 -0
- package/src/native/network/create-fetch.ts +237 -0
- package/src/native/network/index.ts +15 -0
- package/src/native/network/report.ts +58 -0
- package/src/native/network/types.ts +77 -0
- package/src/native/network/utils.ts +90 -0
- package/src/native/report/errors/index.ts +27 -0
- package/src/native/report/index.ts +51 -0
- package/src/native/report/task-tracker.ts +64 -0
- package/src/native/types/global.d.ts +26 -0
- package/src/native/types/native-method-map.d.ts +282 -0
- package/src/native/types/native-method.d.ts +30 -0
- package/src/utils/index.ts +0 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* eslint-disable no-empty-function */
|
|
2
|
+
import { echo, getType } from '../../validate';
|
|
3
|
+
|
|
4
|
+
describe('validate utils', () => {
|
|
5
|
+
it('getType', () => {
|
|
6
|
+
expect.hasAssertions();
|
|
7
|
+
expect(getType(undefined)).toBe('undefined');
|
|
8
|
+
expect(getType(null)).toBe('null');
|
|
9
|
+
expect(getType(Symbol.for(''))).toBe('symbol');
|
|
10
|
+
|
|
11
|
+
expect(getType(1)).toBe('number');
|
|
12
|
+
expect(getType(BigInt('11111'))).toBe('bigint');
|
|
13
|
+
|
|
14
|
+
expect(getType('str')).toBe('string');
|
|
15
|
+
expect(getType({})).toBe('object');
|
|
16
|
+
expect(getType([])).toBe('array');
|
|
17
|
+
|
|
18
|
+
expect(getType(() => {})).toBe('function');
|
|
19
|
+
expect(getType(async () => {})).toBe('function');
|
|
20
|
+
expect(getType(function* () {})).toBe('function');
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
23
|
+
expect(getType(class {})).toBe('function');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('echo has a(n)', () => {
|
|
27
|
+
expect.hasAssertions();
|
|
28
|
+
expect(echo({})).toBe(`a(n) object`);
|
|
29
|
+
expect(echo([])).toBe(`a(n) array`);
|
|
30
|
+
expect(echo(BigInt('123'))).toBe('a(n) bigint');
|
|
31
|
+
expect(echo(() => {})).toBe(`a(n) function`);
|
|
32
|
+
expect(echo(Symbol.for('abc'))).toBe(`a(n) symbol`);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('echo no a(n)', () => {
|
|
36
|
+
expect.hasAssertions();
|
|
37
|
+
expect(echo('1')).toBe(`"1"`);
|
|
38
|
+
expect(echo(1)).toBe(`1`);
|
|
39
|
+
expect(echo(null)).toBe(`null`);
|
|
40
|
+
expect(echo(undefined)).toBe(`undefined`);
|
|
41
|
+
expect(echo(true)).toBe('true');
|
|
42
|
+
expect(echo(false)).toBe('false');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as V from './validate';
|
|
2
|
+
|
|
3
|
+
type Constructor<T> = new (...args: any[]) => T;
|
|
4
|
+
|
|
5
|
+
export { Validator, Primitive } from './validate';
|
|
6
|
+
|
|
7
|
+
export type Type<T> = T extends V.Validator<infer U> ? U : never;
|
|
8
|
+
type OptionalKeys<T> = { [K in keyof T]-?: T[K] & undefined extends never ? never : Required<K> }[keyof T];
|
|
9
|
+
|
|
10
|
+
export const t = {
|
|
11
|
+
object<T extends Record<string, V.Validator>>(schemas?: T) {
|
|
12
|
+
type U = { [K in keyof T]: Type<T[K]> };
|
|
13
|
+
type O = { [K in OptionalKeys<U>]?: U[K] } & Omit<U, OptionalKeys<U>>;
|
|
14
|
+
return new V.$object<{ [K in keyof O]: O[K] }>(schemas);
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
array<T extends V.Validator>(schema?: T) {
|
|
18
|
+
return new V.$array<unknown>(schema);
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
tuple<T extends V.Validator[]>(...schemas: T) {
|
|
22
|
+
return new V.$tuple<{ [K in keyof T]: Type<T[K]> }>(...schemas);
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
literal<T extends V.Primitive>(v: T) {
|
|
26
|
+
return new V.$literal<T>(v);
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
or<T extends V.Validator[]>(...schemas: T) {
|
|
30
|
+
return new V.$or<T extends V.Validator<infer I>[] ? I : unknown>(...schemas);
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
symbol() {
|
|
34
|
+
return new V.$symbol();
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
record<T extends V.Validator<unknown>>(schema: T) {
|
|
38
|
+
return new V.$record<Type<T>>(schema);
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
function() {
|
|
42
|
+
return new V.$function();
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
boolean() {
|
|
46
|
+
return new V.$boolean();
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
string() {
|
|
50
|
+
return new V.$string();
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
number() {
|
|
54
|
+
return new V.$number();
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
undefined() {
|
|
58
|
+
return new V.$undefined();
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
null() {
|
|
62
|
+
return new V.$null();
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
unknown() {
|
|
66
|
+
return new V.$any<unknown>();
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
any() {
|
|
70
|
+
return new V.$any();
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
as<T>() {
|
|
74
|
+
return new V.$any<T>();
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
arraybuffer() {
|
|
78
|
+
return new V.$arraybuffer();
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
enum<T extends (string | number)[]>(...values: T) {
|
|
82
|
+
return new V.$enum<T[number]>(...values);
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
typedarray<T extends V.TypedArray>(ctor: Constructor<T>) {
|
|
86
|
+
return new V.$typedarray(ctor);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export function typeAsserts<T extends V.Validator>(
|
|
91
|
+
validator: T,
|
|
92
|
+
x: unknown,
|
|
93
|
+
path = 'param'
|
|
94
|
+
): asserts x is Type<T> {
|
|
95
|
+
validator.errors = [];
|
|
96
|
+
validator.path = path;
|
|
97
|
+
|
|
98
|
+
V.setCollect(true);
|
|
99
|
+
|
|
100
|
+
if (!validator.validate(x)) {
|
|
101
|
+
const messages = validator.errors.join('\n');
|
|
102
|
+
validator.errors.length = 0;
|
|
103
|
+
V.setCollect(false);
|
|
104
|
+
|
|
105
|
+
throw new TypeError(messages);
|
|
106
|
+
}
|
|
107
|
+
}
|