pwebm 0.0.1-alpha.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.
@@ -0,0 +1,30 @@
1
+ import { z } from "zod";
2
+
3
+ const Idle = z.object({
4
+ stage: z.literal("IDLE"),
5
+ });
6
+
7
+ const SinglePass = z.object({
8
+ stage: z.literal("SINGLE-PASS"),
9
+ total: z.number(),
10
+ current: z.number(),
11
+ percentage: z.number().optional(),
12
+ });
13
+
14
+ const FirstPass = z.object({
15
+ stage: z.literal("FIRST-PASS"),
16
+ tries: z.number(),
17
+ total: z.number(),
18
+ current: z.number(),
19
+ });
20
+
21
+ const SecondPass = z.object({
22
+ stage: z.literal("SECOND-PASS"),
23
+ tries: z.number(),
24
+ total: z.number(),
25
+ current: z.number(),
26
+ percentage: z.number().optional(),
27
+ });
28
+
29
+ export type StatusSchema = z.infer<typeof StatusSchema>;
30
+ export const StatusSchema = z.union([Idle, SinglePass, FirstPass, SecondPass]);
package/src/status.ts ADDED
@@ -0,0 +1,53 @@
1
+ import { queue } from "./queue";
2
+ import { StatusSchema } from "./schema/status";
3
+
4
+ type Stage = StatusSchema["stage"];
5
+
6
+ let store: StatusSchema = {
7
+ stage: "IDLE",
8
+ };
9
+
10
+ const update = (stage: Stage, percentage?: number, tries = 1) => {
11
+ const baseStore = {
12
+ total: queue.getTotalCount(),
13
+ current: queue.getProcessedCount(),
14
+ };
15
+
16
+ switch (stage) {
17
+ case "IDLE":
18
+ store = { stage };
19
+ break;
20
+ case "SINGLE-PASS":
21
+ store = {
22
+ ...baseStore,
23
+ stage,
24
+ percentage,
25
+ };
26
+ break;
27
+ case "FIRST-PASS":
28
+ store = {
29
+ ...baseStore,
30
+ stage,
31
+ tries,
32
+ };
33
+ break;
34
+ case "SECOND-PASS":
35
+ store = {
36
+ ...baseStore,
37
+ stage,
38
+ tries,
39
+ percentage,
40
+ };
41
+ break;
42
+ }
43
+ };
44
+
45
+ export const status = {
46
+ getStatus: () => ({ ...store }),
47
+ updateFirstPass: (percentage?: number, tries?: number) =>
48
+ update("FIRST-PASS", percentage, tries),
49
+ updateSinglePass: (percentage?: number) =>
50
+ update("SINGLE-PASS", percentage, undefined),
51
+ updateSecondPass: (percentage?: number, tries?: number) =>
52
+ update("SECOND-PASS", percentage, tries),
53
+ };
package/src/utils.ts ADDED
@@ -0,0 +1,3 @@
1
+ export const assertNever = (value: never) => {
2
+ throw new Error(`Unexpected value: ${value}`);
3
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": ["ESNext"],
4
+ "module": "esnext",
5
+ "target": "esnext",
6
+ "moduleResolution": "bundler",
7
+ "moduleDetection": "force",
8
+ "allowImportingTsExtensions": true,
9
+ "noEmit": true,
10
+ "composite": true,
11
+ "strict": true,
12
+ "downlevelIteration": true,
13
+ "skipLibCheck": true,
14
+ "jsx": "preserve",
15
+ "allowSyntheticDefaultImports": true,
16
+ "forceConsistentCasingInFileNames": true,
17
+ "allowJs": true
18
+ }
19
+ }