@webiny/api 6.6.0-alpha.0 → 6.6.0-alpha.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/package.json +6 -7
- package/testing/index.d.ts +3 -0
- package/testing/index.js +3 -0
- package/testing/lifecycleTracker.d.ts +14 -0
- package/testing/lifecycleTracker.js +37 -0
- package/testing/lifecycleTracker.js.map +1 -0
- package/testing/sleep.d.ts +1 -0
- package/testing/sleep.js +6 -0
- package/testing/sleep.js.map +1 -0
- package/testing/until.d.ts +7 -0
- package/testing/until.js +22 -0
- package/testing/until.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api",
|
|
3
|
-
"version": "6.6.0-alpha.
|
|
3
|
+
"version": "6.6.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -16,16 +16,15 @@
|
|
|
16
16
|
],
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@webiny/feature": "6.6.0-alpha.
|
|
20
|
-
"@webiny/plugins": "6.6.0-alpha.
|
|
21
|
-
"@webiny/utils": "6.6.0-alpha.
|
|
19
|
+
"@webiny/feature": "6.6.0-alpha.1",
|
|
20
|
+
"@webiny/plugins": "6.6.0-alpha.1",
|
|
21
|
+
"@webiny/utils": "6.6.0-alpha.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@webiny/build-tools": "6.6.0-alpha.
|
|
25
|
-
"@webiny/project-utils": "6.6.0-alpha.0",
|
|
24
|
+
"@webiny/build-tools": "6.6.0-alpha.1",
|
|
26
25
|
"rimraf": "6.1.3",
|
|
27
26
|
"typescript": "7.0.2",
|
|
28
|
-
"vitest": "4.1.
|
|
27
|
+
"vitest": "4.1.11"
|
|
29
28
|
},
|
|
30
29
|
"publishConfig": {
|
|
31
30
|
"access": "public"
|
package/testing/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface Track {
|
|
2
|
+
count: number;
|
|
3
|
+
params: any;
|
|
4
|
+
}
|
|
5
|
+
export declare class LifecycleEventTracker {
|
|
6
|
+
private _tracked;
|
|
7
|
+
track(name: string, params: any): void;
|
|
8
|
+
getLast(name: string): Track | null;
|
|
9
|
+
reset(): void;
|
|
10
|
+
isExecutedOnce(name: string): boolean;
|
|
11
|
+
isExecuted(name: string): boolean;
|
|
12
|
+
getExecuted(name: string): number;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
class LifecycleEventTracker {
|
|
2
|
+
track(name, params) {
|
|
3
|
+
if (!this._tracked[name]) this._tracked[name] = {
|
|
4
|
+
count: 0,
|
|
5
|
+
params: []
|
|
6
|
+
};
|
|
7
|
+
this._tracked[name] = {
|
|
8
|
+
count: this._tracked[name].count + 1,
|
|
9
|
+
params: this._tracked[name].params.concat([
|
|
10
|
+
params
|
|
11
|
+
])
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
getLast(name) {
|
|
15
|
+
return this._tracked[name] || null;
|
|
16
|
+
}
|
|
17
|
+
reset() {
|
|
18
|
+
this._tracked = {};
|
|
19
|
+
}
|
|
20
|
+
isExecutedOnce(name) {
|
|
21
|
+
if (!this._tracked[name]) return false;
|
|
22
|
+
return 1 === this._tracked[name].count;
|
|
23
|
+
}
|
|
24
|
+
isExecuted(name) {
|
|
25
|
+
return !!this._tracked[name];
|
|
26
|
+
}
|
|
27
|
+
getExecuted(name) {
|
|
28
|
+
if (!this._tracked[name]) return 0;
|
|
29
|
+
return this._tracked[name].count;
|
|
30
|
+
}
|
|
31
|
+
constructor(){
|
|
32
|
+
this._tracked = {};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export { LifecycleEventTracker };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=lifecycleTracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing/lifecycleTracker.js","sources":["../../src/testing/lifecycleTracker.ts"],"sourcesContent":["interface Track {\n count: number;\n params: any;\n}\n\ninterface Trackers {\n [key: string]: Track;\n}\n\nexport class LifecycleEventTracker {\n private _tracked: Trackers = {};\n\n public track(name: string, params: any): void {\n if (!this._tracked[name]) {\n this._tracked[name] = {\n count: 0,\n params: []\n };\n }\n this._tracked[name] = {\n count: this._tracked[name].count + 1,\n params: this._tracked[name].params.concat([params])\n };\n }\n\n public getLast(name: string): Track | null {\n return this._tracked[name] || null;\n }\n\n public reset(): void {\n this._tracked = {};\n }\n\n public isExecutedOnce(name: string): boolean {\n if (!this._tracked[name]) {\n return false;\n }\n return this._tracked[name].count === 1;\n }\n\n public isExecuted(name: string): boolean {\n return !!this._tracked[name];\n }\n\n public getExecuted(name: string): number {\n if (!this._tracked[name]) {\n return 0;\n }\n return this._tracked[name].count;\n }\n}\n"],"names":["LifecycleEventTracker","name","params"],"mappings":"AASO,MAAMA;IAGF,MAAMC,IAAY,EAAEC,MAAW,EAAQ;QAC1C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAACD,KAAK,EACpB,IAAI,CAAC,QAAQ,CAACA,KAAK,GAAG;YAClB,OAAO;YACP,QAAQ,EAAE;QACd;QAEJ,IAAI,CAAC,QAAQ,CAACA,KAAK,GAAG;YAClB,OAAO,IAAI,CAAC,QAAQ,CAACA,KAAK,CAAC,KAAK,GAAG;YACnC,QAAQ,IAAI,CAAC,QAAQ,CAACA,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;gBAACC;aAAO;QACtD;IACJ;IAEO,QAAQD,IAAY,EAAgB;QACvC,OAAO,IAAI,CAAC,QAAQ,CAACA,KAAK,IAAI;IAClC;IAEO,QAAc;QACjB,IAAI,CAAC,QAAQ,GAAG,CAAC;IACrB;IAEO,eAAeA,IAAY,EAAW;QACzC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAACA,KAAK,EACpB,OAAO;QAEX,OAAO,AAA8B,MAA9B,IAAI,CAAC,QAAQ,CAACA,KAAK,CAAC,KAAK;IACpC;IAEO,WAAWA,IAAY,EAAW;QACrC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAACA,KAAK;IAChC;IAEO,YAAYA,IAAY,EAAU;QACrC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAACA,KAAK,EACpB,OAAO;QAEX,OAAO,IAAI,CAAC,QAAQ,CAACA,KAAK,CAAC,KAAK;IACpC;;aAvCQ,QAAQ,GAAa,CAAC;;AAwClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sleep: (ms?: number) => Promise<unknown>;
|
package/testing/sleep.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing/sleep.js","sources":["../../src/testing/sleep.ts"],"sourcesContent":["export const sleep = (ms = 333) => {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n};\n"],"names":["sleep","ms","Promise","resolve","setTimeout"],"mappings":"AAAO,MAAMA,QAAQ,CAACC,KAAK,GAAG,GACnB,IAAIC,QAAQC,CAAAA;QACfC,WAAWD,SAASF;IACxB"}
|
package/testing/until.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { sleep } from "./sleep.js";
|
|
2
|
+
const until_until = async (execute, until, options = {})=>{
|
|
3
|
+
const { name = "NO_NAME", tries = 10, wait = 1000, debounce = 0 } = options;
|
|
4
|
+
let result;
|
|
5
|
+
let triesCount = 0;
|
|
6
|
+
if (debounce > 0) await sleep(debounce);
|
|
7
|
+
while(true){
|
|
8
|
+
result = await execute();
|
|
9
|
+
let done;
|
|
10
|
+
try {
|
|
11
|
+
done = await until(result);
|
|
12
|
+
} catch {}
|
|
13
|
+
if (done) return result;
|
|
14
|
+
triesCount++;
|
|
15
|
+
if (triesCount === tries) break;
|
|
16
|
+
await sleep(wait);
|
|
17
|
+
}
|
|
18
|
+
throw new Error(`[${name}] Tried ${tries} times but failed.`);
|
|
19
|
+
};
|
|
20
|
+
export { until_until as until };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=until.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing/until.js","sources":["../../src/testing/until.ts"],"sourcesContent":["import { sleep } from \"./sleep.js\";\n\nexport interface UntilOptions {\n name?: string;\n tries?: number;\n wait?: number;\n debounce?: number;\n}\n\nexport const until = async (\n execute: () => Promise<any>,\n until: (response: any) => boolean,\n options: UntilOptions = {}\n) => {\n const { name = \"NO_NAME\", tries = 10, wait = 1000, debounce = 0 } = options;\n\n let result;\n let triesCount = 0;\n\n if (debounce > 0) {\n await sleep(debounce);\n }\n\n while (true) {\n result = await execute();\n\n let done;\n try {\n done = await until(result);\n } catch {}\n\n if (done) {\n return result;\n }\n\n triesCount++;\n if (triesCount === tries) {\n break;\n }\n\n // Wait.\n await sleep(wait);\n }\n\n throw new Error(`[${name}] Tried ${tries} times but failed.`);\n};\n"],"names":["until","execute","options","name","tries","wait","debounce","result","triesCount","sleep","done","Error"],"mappings":";AASO,MAAMA,cAAQ,OACjBC,SACAD,OACAE,UAAwB,CAAC,CAAC;IAE1B,MAAM,EAAEC,OAAO,SAAS,EAAEC,QAAQ,EAAE,EAAEC,OAAO,IAAI,EAAEC,WAAW,CAAC,EAAE,GAAGJ;IAEpE,IAAIK;IACJ,IAAIC,aAAa;IAEjB,IAAIF,WAAW,GACX,MAAMG,MAAMH;IAGhB,MAAO,KAAM;QACTC,SAAS,MAAMN;QAEf,IAAIS;QACJ,IAAI;YACAA,OAAO,MAAMV,MAAMO;QACvB,EAAE,OAAM,CAAC;QAET,IAAIG,MACA,OAAOH;QAGXC;QACA,IAAIA,eAAeJ,OACf;QAIJ,MAAMK,MAAMJ;IAChB;IAEA,MAAM,IAAIM,MAAM,CAAC,CAAC,EAAER,KAAK,QAAQ,EAAEC,MAAM,kBAAkB,CAAC;AAChE"}
|