@embedpdf/models 1.0.11 → 1.0.12

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/dist/task.d.ts ADDED
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Stage of task
3
+ *
4
+ * @public
5
+ */
6
+ export declare enum TaskStage {
7
+ /**
8
+ * Task is pending, means it just start executing
9
+ */
10
+ Pending = 0,
11
+ /**
12
+ * Task is succeed
13
+ */
14
+ Resolved = 1,
15
+ /**
16
+ * Task is failed
17
+ */
18
+ Rejected = 2,
19
+ /**
20
+ * Task is aborted
21
+ */
22
+ Aborted = 3
23
+ }
24
+ export interface TaskError<D> {
25
+ /**
26
+ * task error type
27
+ */
28
+ type: 'reject' | 'abort';
29
+ /**
30
+ * task error
31
+ */
32
+ reason: D;
33
+ }
34
+ /**
35
+ * callback that will be called when task is resolved
36
+ *
37
+ * @public
38
+ */
39
+ export type ResolvedCallback<R> = (r: R) => void;
40
+ /**
41
+ * callback that will be called when task is rejected
42
+ *
43
+ * @public
44
+ */
45
+ export type RejectedCallback<D> = (e: TaskError<D>) => void;
46
+ /**
47
+ * Task state in different stage
48
+ *
49
+ * @public
50
+ */
51
+ export type TaskState<R, D> = {
52
+ stage: TaskStage.Pending;
53
+ } | {
54
+ stage: TaskStage.Resolved;
55
+ result: R;
56
+ } | {
57
+ stage: TaskStage.Rejected;
58
+ reason: D;
59
+ } | {
60
+ stage: TaskStage.Aborted;
61
+ reason: D;
62
+ };
63
+ /**
64
+ * Result type for allSettled
65
+ *
66
+ * @public
67
+ */
68
+ export type TaskSettledResult<R, D> = {
69
+ status: 'resolved';
70
+ value: R;
71
+ } | {
72
+ status: 'rejected';
73
+ reason: D;
74
+ } | {
75
+ status: 'aborted';
76
+ reason: D;
77
+ };
78
+ export declare class TaskAbortedError<D> extends Error {
79
+ constructor(reason: D);
80
+ }
81
+ export declare class TaskRejectedError<D> extends Error {
82
+ constructor(reason: D);
83
+ }
84
+ /**
85
+ * Base class of task
86
+ *
87
+ * @public
88
+ */
89
+ export declare class Task<R, D> {
90
+ state: TaskState<R, D>;
91
+ /**
92
+ * callbacks that will be executed when task is resolved
93
+ */
94
+ resolvedCallbacks: ResolvedCallback<R>[];
95
+ /**
96
+ * callbacks that will be executed when task is rejected
97
+ */
98
+ rejectedCallbacks: RejectedCallback<D>[];
99
+ /**
100
+ * Promise that will be resolved when task is settled
101
+ */
102
+ private _promise;
103
+ /**
104
+ * Convert task to promise
105
+ * @returns promise that will be resolved when task is settled
106
+ */
107
+ toPromise(): Promise<R>;
108
+ /**
109
+ * wait for task to be settled
110
+ * @param resolvedCallback - callback for resolved value
111
+ * @param rejectedCallback - callback for rejected value
112
+ */
113
+ wait(resolvedCallback: ResolvedCallback<R>, rejectedCallback: RejectedCallback<D>): void;
114
+ /**
115
+ * resolve task with specific result
116
+ * @param result - result value
117
+ */
118
+ resolve(result: R): void;
119
+ /**
120
+ * reject task with specific reason
121
+ * @param reason - abort reason
122
+ *
123
+ */
124
+ reject(reason: D): void;
125
+ /**
126
+ * abort task with specific reason
127
+ * @param reason - abort reason
128
+ */
129
+ abort(reason: D): void;
130
+ /**
131
+ * fail task with a TaskError from another task
132
+ * This is a convenience method for error propagation between tasks
133
+ * @param error - TaskError from another task
134
+ */
135
+ fail(error: TaskError<D>): void;
136
+ /**
137
+ * Static method to wait for all tasks to resolve
138
+ * Returns a new task that resolves with an array of all results
139
+ * Rejects immediately if any task fails
140
+ *
141
+ * @param tasks - array of tasks to wait for
142
+ * @returns new task that resolves when all input tasks resolve
143
+ * @public
144
+ */
145
+ static all<R extends readonly Task<any, any>[]>(tasks: R): Task<{
146
+ [K in keyof R]: R[K] extends Task<infer U, any> ? U : never;
147
+ }, any>;
148
+ /**
149
+ * Static method to wait for all tasks to settle (resolve, reject, or abort)
150
+ * Always resolves with an array of settlement results
151
+ *
152
+ * @param tasks - array of tasks to wait for
153
+ * @returns new task that resolves when all input tasks settle
154
+ * @public
155
+ */
156
+ static allSettled<R extends readonly Task<any, any>[]>(tasks: R): Task<{
157
+ [K in keyof R]: R[K] extends Task<infer U, infer E> ? TaskSettledResult<U, E> : never;
158
+ }, never>;
159
+ /**
160
+ * Static method that resolves/rejects with the first task that settles
161
+ *
162
+ * @param tasks - array of tasks to race
163
+ * @returns new task that settles with the first input task that settles
164
+ * @public
165
+ */
166
+ static race<R extends readonly Task<any, any>[]>(tasks: R): Task<R[number] extends Task<infer U, any> ? U : never, R[number] extends Task<any, infer E> ? E : never>;
167
+ /**
168
+ * Utility to track progress of multiple tasks
169
+ *
170
+ * @param tasks - array of tasks to track
171
+ * @param onProgress - callback called when any task completes
172
+ * @returns new task that resolves when all input tasks resolve
173
+ * @public
174
+ */
175
+ static withProgress<R extends readonly Task<any, any>[]>(tasks: R, onProgress?: (completed: number, total: number) => void): Task<{
176
+ [K in keyof R]: R[K] extends Task<infer U, any> ? U : never;
177
+ }, any>;
178
+ }
179
+ /**
180
+ * Type that represent the result of executing task
181
+ */
182
+ export type TaskReturn<T extends Task<any, any>> = T extends Task<infer R, infer E> ? {
183
+ type: 'result';
184
+ value: R;
185
+ } | {
186
+ type: 'error';
187
+ value: TaskError<E>;
188
+ } : never;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/models",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "private": false,
5
5
  "description": "Shared type definitions, data models, and utility helpers (geometry, tasks, logging, PDF primitives) that underpin every package in the EmbedPDF ecosystem.",
6
6
  "type": "module",
@@ -30,20 +30,18 @@
30
30
  "author": "Bob Singor, Ji Chang",
31
31
  "license": "MIT",
32
32
  "devDependencies": {
33
- "tsup": "^8.0.0",
34
33
  "typescript": "^5.0.0",
35
34
  "@types/jest": "^29.5.14",
36
- "jest": "^29.7.0"
35
+ "jest": "^29.7.0",
36
+ "@embedpdf/build": "1.0.0"
37
37
  },
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
41
  "scripts": {
42
- "build": "PROJECT_CWD=$(pwd) pnpm -w p:build",
43
- "build:watch": "PROJECT_CWD=$(pwd) pnpm -w p:build:watch",
44
- "clean": "PROJECT_CWD=$(pwd) pnpm -w p:clean",
45
- "lint": "PROJECT_CWD=$(pwd) pnpm -w p:lint",
46
- "lint:fix": "PROJECT_CWD=$(pwd) pnpm -w p:lint:fix",
47
- "typecheck": "PROJECT_CWD=$(pwd) pnpm -w p:typecheck"
42
+ "build": "pnpm run clean && vite build",
43
+ "clean": "rimraf dist",
44
+ "lint": "eslint src --color",
45
+ "lint:fix": "eslint src --color --fix"
48
46
  }
49
47
  }