@voyantjs/ground 0.2.0 → 0.3.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.
@@ -0,0 +1,255 @@
1
+ import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
2
+ import type { CreateGroundDispatchInput, CreateGroundExecutionEventInput, CreateGroundTransferPreferenceInput, GroundDispatchListQuery, GroundExecutionEventListQuery, GroundTransferPreferenceListQuery, UpdateGroundDispatchInput, UpdateGroundExecutionEventInput, UpdateGroundTransferPreferenceInput } from "./service-shared.js";
3
+ export declare function listTransferPreferences(db: PostgresJsDatabase, query: GroundTransferPreferenceListQuery): Promise<{
4
+ data: {
5
+ id: string;
6
+ bookingId: string;
7
+ bookingItemId: string | null;
8
+ pickupFacilityId: string | null;
9
+ dropoffFacilityId: string | null;
10
+ pickupAddressId: string | null;
11
+ dropoffAddressId: string | null;
12
+ requestedVehicleCategory: "other" | "car" | "sedan" | "suv" | "van" | "minibus" | "bus" | "boat" | "train" | null;
13
+ requestedVehicleClass: "other" | "economy" | "standard" | "premium" | "luxury" | "accessible" | null;
14
+ serviceLevel: "other" | "private" | "shared" | "vip" | "shuttle";
15
+ passengerCount: number | null;
16
+ checkedBags: number | null;
17
+ carryOnBags: number | null;
18
+ wheelchairCount: number | null;
19
+ childSeatCount: number | null;
20
+ driverLanguage: string | null;
21
+ meetAndGreet: boolean;
22
+ accessibilityNotes: string | null;
23
+ pickupNotes: string | null;
24
+ dropoffNotes: string | null;
25
+ notes: string | null;
26
+ createdAt: Date;
27
+ updatedAt: Date;
28
+ }[];
29
+ total: number;
30
+ limit: number;
31
+ offset: number;
32
+ }>;
33
+ export declare function getTransferPreferenceById(db: PostgresJsDatabase, id: string): Promise<{
34
+ id: string;
35
+ bookingId: string;
36
+ bookingItemId: string | null;
37
+ pickupFacilityId: string | null;
38
+ dropoffFacilityId: string | null;
39
+ pickupAddressId: string | null;
40
+ dropoffAddressId: string | null;
41
+ requestedVehicleCategory: "other" | "car" | "sedan" | "suv" | "van" | "minibus" | "bus" | "boat" | "train" | null;
42
+ requestedVehicleClass: "other" | "economy" | "standard" | "premium" | "luxury" | "accessible" | null;
43
+ serviceLevel: "other" | "private" | "shared" | "vip" | "shuttle";
44
+ passengerCount: number | null;
45
+ checkedBags: number | null;
46
+ carryOnBags: number | null;
47
+ wheelchairCount: number | null;
48
+ childSeatCount: number | null;
49
+ driverLanguage: string | null;
50
+ meetAndGreet: boolean;
51
+ accessibilityNotes: string | null;
52
+ pickupNotes: string | null;
53
+ dropoffNotes: string | null;
54
+ notes: string | null;
55
+ createdAt: Date;
56
+ updatedAt: Date;
57
+ } | null>;
58
+ export declare function createTransferPreference(db: PostgresJsDatabase, data: CreateGroundTransferPreferenceInput): Promise<{
59
+ id: string;
60
+ notes: string | null;
61
+ createdAt: Date;
62
+ updatedAt: Date;
63
+ bookingId: string;
64
+ bookingItemId: string | null;
65
+ pickupFacilityId: string | null;
66
+ dropoffFacilityId: string | null;
67
+ pickupAddressId: string | null;
68
+ dropoffAddressId: string | null;
69
+ requestedVehicleCategory: "other" | "car" | "sedan" | "suv" | "van" | "minibus" | "bus" | "boat" | "train" | null;
70
+ requestedVehicleClass: "other" | "economy" | "standard" | "premium" | "luxury" | "accessible" | null;
71
+ serviceLevel: "other" | "private" | "shared" | "vip" | "shuttle";
72
+ passengerCount: number | null;
73
+ checkedBags: number | null;
74
+ carryOnBags: number | null;
75
+ wheelchairCount: number | null;
76
+ childSeatCount: number | null;
77
+ driverLanguage: string | null;
78
+ meetAndGreet: boolean;
79
+ accessibilityNotes: string | null;
80
+ pickupNotes: string | null;
81
+ dropoffNotes: string | null;
82
+ } | undefined>;
83
+ export declare function updateTransferPreference(db: PostgresJsDatabase, id: string, data: UpdateGroundTransferPreferenceInput): Promise<{
84
+ id: string;
85
+ bookingId: string;
86
+ bookingItemId: string | null;
87
+ pickupFacilityId: string | null;
88
+ dropoffFacilityId: string | null;
89
+ pickupAddressId: string | null;
90
+ dropoffAddressId: string | null;
91
+ requestedVehicleCategory: "other" | "car" | "sedan" | "suv" | "van" | "minibus" | "bus" | "boat" | "train" | null;
92
+ requestedVehicleClass: "other" | "economy" | "standard" | "premium" | "luxury" | "accessible" | null;
93
+ serviceLevel: "other" | "private" | "shared" | "vip" | "shuttle";
94
+ passengerCount: number | null;
95
+ checkedBags: number | null;
96
+ carryOnBags: number | null;
97
+ wheelchairCount: number | null;
98
+ childSeatCount: number | null;
99
+ driverLanguage: string | null;
100
+ meetAndGreet: boolean;
101
+ accessibilityNotes: string | null;
102
+ pickupNotes: string | null;
103
+ dropoffNotes: string | null;
104
+ notes: string | null;
105
+ createdAt: Date;
106
+ updatedAt: Date;
107
+ } | null>;
108
+ export declare function deleteTransferPreference(db: PostgresJsDatabase, id: string): Promise<{
109
+ id: string;
110
+ } | null>;
111
+ export declare function listDispatches(db: PostgresJsDatabase, query: GroundDispatchListQuery): Promise<{
112
+ data: {
113
+ id: string;
114
+ transferPreferenceId: string;
115
+ bookingId: string;
116
+ bookingItemId: string | null;
117
+ operatorId: string | null;
118
+ vehicleId: string | null;
119
+ driverId: string | null;
120
+ serviceDate: string | null;
121
+ scheduledPickupAt: Date | null;
122
+ scheduledDropoffAt: Date | null;
123
+ actualPickupAt: Date | null;
124
+ actualDropoffAt: Date | null;
125
+ status: "draft" | "scheduled" | "assigned" | "en_route" | "arrived" | "picked_up" | "completed" | "cancelled" | "no_show";
126
+ passengerCount: number | null;
127
+ checkedBags: number | null;
128
+ carryOnBags: number | null;
129
+ notes: string | null;
130
+ createdAt: Date;
131
+ updatedAt: Date;
132
+ }[];
133
+ total: number;
134
+ limit: number;
135
+ offset: number;
136
+ }>;
137
+ export declare function getDispatchById(db: PostgresJsDatabase, id: string): Promise<{
138
+ id: string;
139
+ transferPreferenceId: string;
140
+ bookingId: string;
141
+ bookingItemId: string | null;
142
+ operatorId: string | null;
143
+ vehicleId: string | null;
144
+ driverId: string | null;
145
+ serviceDate: string | null;
146
+ scheduledPickupAt: Date | null;
147
+ scheduledDropoffAt: Date | null;
148
+ actualPickupAt: Date | null;
149
+ actualDropoffAt: Date | null;
150
+ status: "draft" | "scheduled" | "assigned" | "en_route" | "arrived" | "picked_up" | "completed" | "cancelled" | "no_show";
151
+ passengerCount: number | null;
152
+ checkedBags: number | null;
153
+ carryOnBags: number | null;
154
+ notes: string | null;
155
+ createdAt: Date;
156
+ updatedAt: Date;
157
+ } | null>;
158
+ export declare function createDispatch(db: PostgresJsDatabase, data: CreateGroundDispatchInput): Promise<{
159
+ id: string;
160
+ notes: string | null;
161
+ createdAt: Date;
162
+ updatedAt: Date;
163
+ status: "draft" | "scheduled" | "assigned" | "en_route" | "arrived" | "picked_up" | "completed" | "cancelled" | "no_show";
164
+ operatorId: string | null;
165
+ bookingId: string;
166
+ bookingItemId: string | null;
167
+ passengerCount: number | null;
168
+ checkedBags: number | null;
169
+ carryOnBags: number | null;
170
+ transferPreferenceId: string;
171
+ vehicleId: string | null;
172
+ driverId: string | null;
173
+ serviceDate: string | null;
174
+ scheduledPickupAt: Date | null;
175
+ scheduledDropoffAt: Date | null;
176
+ actualPickupAt: Date | null;
177
+ actualDropoffAt: Date | null;
178
+ } | undefined>;
179
+ export declare function updateDispatch(db: PostgresJsDatabase, id: string, data: UpdateGroundDispatchInput): Promise<{
180
+ id: string;
181
+ transferPreferenceId: string;
182
+ bookingId: string;
183
+ bookingItemId: string | null;
184
+ operatorId: string | null;
185
+ vehicleId: string | null;
186
+ driverId: string | null;
187
+ serviceDate: string | null;
188
+ scheduledPickupAt: Date | null;
189
+ scheduledDropoffAt: Date | null;
190
+ actualPickupAt: Date | null;
191
+ actualDropoffAt: Date | null;
192
+ status: "draft" | "scheduled" | "assigned" | "en_route" | "arrived" | "picked_up" | "completed" | "cancelled" | "no_show";
193
+ passengerCount: number | null;
194
+ checkedBags: number | null;
195
+ carryOnBags: number | null;
196
+ notes: string | null;
197
+ createdAt: Date;
198
+ updatedAt: Date;
199
+ } | null>;
200
+ export declare function deleteDispatch(db: PostgresJsDatabase, id: string): Promise<{
201
+ id: string;
202
+ } | null>;
203
+ export declare function listExecutionEvents(db: PostgresJsDatabase, query: GroundExecutionEventListQuery): Promise<{
204
+ data: {
205
+ id: string;
206
+ dispatchId: string;
207
+ eventType: "scheduled" | "assigned" | "cancelled" | "driver_en_route" | "driver_arrived" | "pickup_completed" | "dropoff_completed" | "issue" | "note";
208
+ occurredAt: Date;
209
+ facilityId: string | null;
210
+ addressId: string | null;
211
+ notes: string | null;
212
+ metadata: Record<string, unknown> | null;
213
+ createdAt: Date;
214
+ }[];
215
+ total: number;
216
+ limit: number;
217
+ offset: number;
218
+ }>;
219
+ export declare function getExecutionEventById(db: PostgresJsDatabase, id: string): Promise<{
220
+ id: string;
221
+ dispatchId: string;
222
+ eventType: "scheduled" | "assigned" | "cancelled" | "driver_en_route" | "driver_arrived" | "pickup_completed" | "dropoff_completed" | "issue" | "note";
223
+ occurredAt: Date;
224
+ facilityId: string | null;
225
+ addressId: string | null;
226
+ notes: string | null;
227
+ metadata: Record<string, unknown> | null;
228
+ createdAt: Date;
229
+ } | null>;
230
+ export declare function createExecutionEvent(db: PostgresJsDatabase, data: CreateGroundExecutionEventInput): Promise<{
231
+ id: string;
232
+ notes: string | null;
233
+ metadata: Record<string, unknown> | null;
234
+ createdAt: Date;
235
+ facilityId: string | null;
236
+ dispatchId: string;
237
+ eventType: "scheduled" | "assigned" | "cancelled" | "driver_en_route" | "driver_arrived" | "pickup_completed" | "dropoff_completed" | "issue" | "note";
238
+ occurredAt: Date;
239
+ addressId: string | null;
240
+ } | undefined>;
241
+ export declare function updateExecutionEvent(db: PostgresJsDatabase, id: string, data: UpdateGroundExecutionEventInput): Promise<{
242
+ id: string;
243
+ dispatchId: string;
244
+ eventType: "scheduled" | "assigned" | "cancelled" | "driver_en_route" | "driver_arrived" | "pickup_completed" | "dropoff_completed" | "issue" | "note";
245
+ occurredAt: Date;
246
+ facilityId: string | null;
247
+ addressId: string | null;
248
+ notes: string | null;
249
+ metadata: Record<string, unknown> | null;
250
+ createdAt: Date;
251
+ } | null>;
252
+ export declare function deleteExecutionEvent(db: PostgresJsDatabase, id: string): Promise<{
253
+ id: string;
254
+ } | null>;
255
+ //# sourceMappingURL=service-dispatch-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-dispatch-core.d.ts","sourceRoot":"","sources":["../src/service-dispatch-core.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAGjE,OAAO,KAAK,EACV,yBAAyB,EACzB,+BAA+B,EAC/B,mCAAmC,EACnC,uBAAuB,EACvB,6BAA6B,EAC7B,iCAAiC,EACjC,yBAAyB,EACzB,+BAA+B,EAC/B,mCAAmC,EACpC,MAAM,qBAAqB,CAAA;AAG5B,wBAAsB,uBAAuB,CAC3C,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwBzC;AAED,wBAAsB,yBAAyB,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;UAOjF;AAED,wBAAsB,wBAAwB,CAC5C,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,mCAAmC;;;;;;;;;;;;;;;;;;;;;;;;eAI1C;AAED,wBAAsB,wBAAwB,CAC5C,EAAE,EAAE,kBAAkB,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,mCAAmC;;;;;;;;;;;;;;;;;;;;;;;;UAQ1C;AAED,wBAAsB,wBAAwB,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;UAMhF;AAED,wBAAsB,cAAc,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;GA0B1F;AAED,wBAAsB,eAAe,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;UAGvE;AAED,wBAAsB,cAAc,CAAC,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,yBAAyB;;;;;;;;;;;;;;;;;;;;eAa3F;AAED,wBAAsB,cAAc,CAClC,EAAE,EAAE,kBAAkB,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,yBAAyB;;;;;;;;;;;;;;;;;;;;UAgBhC;AAED,wBAAsB,cAAc,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;UAMtE;AAED,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,6BAA6B;;;;;;;;;;;;;;;GAmBrC;AAED,wBAAsB,qBAAqB,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;UAO7E;AAED,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,+BAA+B;;;;;;;;;;eAWtC;AAED,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,kBAAkB,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,+BAA+B;;;;;;;;;;UAYtC;AAED,wBAAsB,oBAAoB,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;UAM5E"}
@@ -0,0 +1,171 @@
1
+ import { and, asc, eq, sql } from "drizzle-orm";
2
+ import { groundDispatches, groundExecutionEvents, groundTransferPreferences } from "./schema.js";
3
+ import { paginate, toDateOrNull } from "./service-shared.js";
4
+ export async function listTransferPreferences(db, query) {
5
+ const conditions = [];
6
+ if (query.bookingId)
7
+ conditions.push(eq(groundTransferPreferences.bookingId, query.bookingId));
8
+ if (query.bookingItemId) {
9
+ conditions.push(eq(groundTransferPreferences.bookingItemId, query.bookingItemId));
10
+ }
11
+ if (query.serviceLevel) {
12
+ conditions.push(eq(groundTransferPreferences.serviceLevel, query.serviceLevel));
13
+ }
14
+ const where = conditions.length > 0 ? and(...conditions) : undefined;
15
+ return paginate(db
16
+ .select()
17
+ .from(groundTransferPreferences)
18
+ .where(where)
19
+ .limit(query.limit)
20
+ .offset(query.offset)
21
+ .orderBy(asc(groundTransferPreferences.createdAt)), db.select({ count: sql `count(*)::int` }).from(groundTransferPreferences).where(where), query.limit, query.offset);
22
+ }
23
+ export async function getTransferPreferenceById(db, id) {
24
+ const [row] = await db
25
+ .select()
26
+ .from(groundTransferPreferences)
27
+ .where(eq(groundTransferPreferences.id, id))
28
+ .limit(1);
29
+ return row ?? null;
30
+ }
31
+ export async function createTransferPreference(db, data) {
32
+ const [row] = await db.insert(groundTransferPreferences).values(data).returning();
33
+ return row;
34
+ }
35
+ export async function updateTransferPreference(db, id, data) {
36
+ const [row] = await db
37
+ .update(groundTransferPreferences)
38
+ .set({ ...data, updatedAt: new Date() })
39
+ .where(eq(groundTransferPreferences.id, id))
40
+ .returning();
41
+ return row ?? null;
42
+ }
43
+ export async function deleteTransferPreference(db, id) {
44
+ const [row] = await db
45
+ .delete(groundTransferPreferences)
46
+ .where(eq(groundTransferPreferences.id, id))
47
+ .returning({ id: groundTransferPreferences.id });
48
+ return row ?? null;
49
+ }
50
+ export async function listDispatches(db, query) {
51
+ const conditions = [];
52
+ if (query.transferPreferenceId) {
53
+ conditions.push(eq(groundDispatches.transferPreferenceId, query.transferPreferenceId));
54
+ }
55
+ if (query.bookingId)
56
+ conditions.push(eq(groundDispatches.bookingId, query.bookingId));
57
+ if (query.bookingItemId)
58
+ conditions.push(eq(groundDispatches.bookingItemId, query.bookingItemId));
59
+ if (query.operatorId)
60
+ conditions.push(eq(groundDispatches.operatorId, query.operatorId));
61
+ if (query.vehicleId)
62
+ conditions.push(eq(groundDispatches.vehicleId, query.vehicleId));
63
+ if (query.driverId)
64
+ conditions.push(eq(groundDispatches.driverId, query.driverId));
65
+ if (query.status)
66
+ conditions.push(eq(groundDispatches.status, query.status));
67
+ if (query.serviceDate)
68
+ conditions.push(eq(groundDispatches.serviceDate, query.serviceDate));
69
+ const where = conditions.length > 0 ? and(...conditions) : undefined;
70
+ return paginate(db
71
+ .select()
72
+ .from(groundDispatches)
73
+ .where(where)
74
+ .limit(query.limit)
75
+ .offset(query.offset)
76
+ .orderBy(asc(groundDispatches.serviceDate), asc(groundDispatches.createdAt)), db.select({ count: sql `count(*)::int` }).from(groundDispatches).where(where), query.limit, query.offset);
77
+ }
78
+ export async function getDispatchById(db, id) {
79
+ const [row] = await db.select().from(groundDispatches).where(eq(groundDispatches.id, id)).limit(1);
80
+ return row ?? null;
81
+ }
82
+ export async function createDispatch(db, data) {
83
+ const { scheduledPickupAt, scheduledDropoffAt, actualPickupAt, actualDropoffAt, ...rest } = data;
84
+ const [row] = await db
85
+ .insert(groundDispatches)
86
+ .values({
87
+ ...rest,
88
+ scheduledPickupAt: toDateOrNull(scheduledPickupAt),
89
+ scheduledDropoffAt: toDateOrNull(scheduledDropoffAt),
90
+ actualPickupAt: toDateOrNull(actualPickupAt),
91
+ actualDropoffAt: toDateOrNull(actualDropoffAt),
92
+ })
93
+ .returning();
94
+ return row;
95
+ }
96
+ export async function updateDispatch(db, id, data) {
97
+ const { scheduledPickupAt, scheduledDropoffAt, actualPickupAt, actualDropoffAt, ...rest } = data;
98
+ const [row] = await db
99
+ .update(groundDispatches)
100
+ .set({
101
+ ...rest,
102
+ scheduledPickupAt: toDateOrNull(scheduledPickupAt),
103
+ scheduledDropoffAt: toDateOrNull(scheduledDropoffAt),
104
+ actualPickupAt: toDateOrNull(actualPickupAt),
105
+ actualDropoffAt: toDateOrNull(actualDropoffAt),
106
+ updatedAt: new Date(),
107
+ })
108
+ .where(eq(groundDispatches.id, id))
109
+ .returning();
110
+ return row ?? null;
111
+ }
112
+ export async function deleteDispatch(db, id) {
113
+ const [row] = await db
114
+ .delete(groundDispatches)
115
+ .where(eq(groundDispatches.id, id))
116
+ .returning({ id: groundDispatches.id });
117
+ return row ?? null;
118
+ }
119
+ export async function listExecutionEvents(db, query) {
120
+ const conditions = [];
121
+ if (query.dispatchId)
122
+ conditions.push(eq(groundExecutionEvents.dispatchId, query.dispatchId));
123
+ if (query.eventType)
124
+ conditions.push(eq(groundExecutionEvents.eventType, query.eventType));
125
+ const where = conditions.length > 0 ? and(...conditions) : undefined;
126
+ return paginate(db
127
+ .select()
128
+ .from(groundExecutionEvents)
129
+ .where(where)
130
+ .limit(query.limit)
131
+ .offset(query.offset)
132
+ .orderBy(asc(groundExecutionEvents.occurredAt), asc(groundExecutionEvents.createdAt)), db.select({ count: sql `count(*)::int` }).from(groundExecutionEvents).where(where), query.limit, query.offset);
133
+ }
134
+ export async function getExecutionEventById(db, id) {
135
+ const [row] = await db
136
+ .select()
137
+ .from(groundExecutionEvents)
138
+ .where(eq(groundExecutionEvents.id, id))
139
+ .limit(1);
140
+ return row ?? null;
141
+ }
142
+ export async function createExecutionEvent(db, data) {
143
+ const { occurredAt, ...rest } = data;
144
+ const [row] = await db
145
+ .insert(groundExecutionEvents)
146
+ .values({
147
+ ...rest,
148
+ occurredAt: toDateOrNull(occurredAt) ?? new Date(),
149
+ })
150
+ .returning();
151
+ return row;
152
+ }
153
+ export async function updateExecutionEvent(db, id, data) {
154
+ const { occurredAt, ...rest } = data;
155
+ const [row] = await db
156
+ .update(groundExecutionEvents)
157
+ .set({
158
+ ...rest,
159
+ occurredAt: occurredAt === undefined ? undefined : (toDateOrNull(occurredAt) ?? new Date()),
160
+ })
161
+ .where(eq(groundExecutionEvents.id, id))
162
+ .returning();
163
+ return row ?? null;
164
+ }
165
+ export async function deleteExecutionEvent(db, id) {
166
+ const [row] = await db
167
+ .delete(groundExecutionEvents)
168
+ .where(eq(groundExecutionEvents.id, id))
169
+ .returning({ id: groundExecutionEvents.id });
170
+ return row ?? null;
171
+ }