@fabriktor/fx 0.0.78 → 0.0.80

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.
@@ -1,5 +1,12 @@
1
- import type { Date as SchemaDate } from "@fabriktor/schema";
2
- export type LocalDateParts = Pick<SchemaDate, "y" | "m" | "d" | "h" | "min">;
3
- export declare function normalizeBackendDate(v: LocalDateParts): SchemaDate;
1
+ import type { Date as SchemaDate, InDate } from "@fabriktor/schema";
2
+ export type LocalDateParts = {
3
+ y: number;
4
+ m: number;
5
+ d: number;
6
+ h: number;
7
+ min: number;
8
+ };
9
+ export declare function normalizeInputDate(v: InDate): InDate;
10
+ export declare function zeroInputDate(): InDate;
4
11
  export declare function zeroDate(): SchemaDate;
5
12
  export declare function isZeroDate(v: LocalDateParts): boolean;
@@ -5,23 +5,14 @@
5
5
  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
6
  const zeroUTC = "0001-01-01T00:00:00Z";
7
7
  const utcTimezone = "UTC";
8
- export function normalizeBackendDate(v) {
8
+ export function normalizeInputDate(v) {
9
9
  if (isZeroDate(v)) {
10
- return zeroDate();
10
+ return zeroInputDate();
11
11
  }
12
- return {
13
- utc: zeroUTC,
14
- y: v.y,
15
- m: v.m,
16
- d: v.d,
17
- h: v.h,
18
- min: v.min,
19
- tz: utcTimezone,
20
- };
12
+ return { ...v };
21
13
  }
22
- export function zeroDate() {
14
+ export function zeroInputDate() {
23
15
  return {
24
- utc: zeroUTC,
25
16
  y: 1,
26
17
  m: 1,
27
18
  d: 1,
@@ -30,6 +21,12 @@ export function zeroDate() {
30
21
  tz: utcTimezone,
31
22
  };
32
23
  }
24
+ export function zeroDate() {
25
+ return {
26
+ utc: zeroUTC,
27
+ ...zeroInputDate(),
28
+ };
29
+ }
33
30
  export function isZeroDate(v) {
34
31
  if (v.h !== 0 || v.min !== 0) {
35
32
  return false;
@@ -5,7 +5,7 @@
5
5
  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
6
  import { Cancelled, Completed, Pending, RecurrenceEndTypeAfterDate, RecurrenceEndTypeAfterOccurrences, RecurrenceEndTypeIndefinite, Started, } from "@fabriktor/schema";
7
7
  import { queryParams } from "@fabriktor/client";
8
- import { isZeroDate, normalizeBackendDate, zeroDate, } from "../core/date.js";
8
+ import { isZeroDate, normalizeInputDate, zeroInputDate, } from "../core/date.js";
9
9
  import { errRequired, errResolveFailed, errValidation, } from "../core/err.js";
10
10
  import { requiredOperationID, resolvedID } from "../core/id.js";
11
11
  import { runOwnerSearch, runSearch, } from "../core/search.js";
@@ -56,7 +56,6 @@ export class JobsFX {
56
56
  in: {
57
57
  ...opts.in,
58
58
  is_archived: false,
59
- address_timezone: "",
60
59
  current_members: normalizeIDs(opts.in.current_members),
61
60
  },
62
61
  });
@@ -122,7 +121,7 @@ export class JobsFX {
122
121
  });
123
122
  const input = {
124
123
  ...opts.in,
125
- job_start_date: normalizeBackendDate(opts.in.job_start_date),
124
+ job_start_date: opts.in.job_start_date,
126
125
  job_current_members,
127
126
  job_foremen,
128
127
  job_location_id,
@@ -174,7 +173,7 @@ export class JobsFX {
174
173
  field: "in",
175
174
  msg: msgForemenOutsideJob,
176
175
  });
177
- const expected_end_date = normalizeBackendDate(opts.in.expected_end_date);
176
+ const expected_end_date = normalizeInputDate(opts.in.expected_end_date);
178
177
  validateExpectedEnd({
179
178
  start: opts.in,
180
179
  end: expected_end_date,
@@ -183,7 +182,6 @@ export class JobsFX {
183
182
  const out = await this.jobs.insertOneJob({
184
183
  in: {
185
184
  ...opts.in,
186
- ...normalizeBackendDate(opts.in),
187
185
  expected_end_date,
188
186
  current_members,
189
187
  foremen,
@@ -428,14 +426,14 @@ function validateProgramStart(opts) {
428
426
  msg: msgTimezoneInvalid,
429
427
  });
430
428
  }
431
- const current_day = sameCalendarDay(opts.start, now);
432
- if (!current_day && compareLocalDate(opts.start, now) < 0) {
429
+ const comparison = compareLocalDate(opts.start, now);
430
+ if (comparison < 0) {
433
431
  throw errValidation({
434
432
  field: "in",
435
433
  msg: msgProgramStartPast,
436
434
  });
437
435
  }
438
- return current_day;
436
+ return comparison === 0;
439
437
  }
440
438
  function validateDuration(v, field) {
441
439
  if (!Number.isFinite(v) || !Number.isInteger(v) || v < 0) {
@@ -452,7 +450,7 @@ function normalizeRecurrenceEnd(opts) {
452
450
  case RecurrenceEndTypeIndefinite:
453
451
  return {
454
452
  occurrences_to_end: 0,
455
- recurrence_end_date: zeroDate(),
453
+ recurrence_end_date: zeroInputDate(),
456
454
  };
457
455
  case RecurrenceEndTypeAfterOccurrences:
458
456
  if (!Number.isFinite(opts.occurrences_to_end) ||
@@ -465,7 +463,7 @@ function normalizeRecurrenceEnd(opts) {
465
463
  }
466
464
  return {
467
465
  occurrences_to_end: opts.occurrences_to_end,
468
- recurrence_end_date: zeroDate(),
466
+ recurrence_end_date: zeroInputDate(),
469
467
  };
470
468
  case RecurrenceEndTypeAfterDate:
471
469
  if (isZeroDate(opts.recurrence_end_date)) {
@@ -476,7 +474,7 @@ function normalizeRecurrenceEnd(opts) {
476
474
  }
477
475
  return {
478
476
  occurrences_to_end: 0,
479
- recurrence_end_date: normalizeBackendDate(opts.recurrence_end_date),
477
+ recurrence_end_date: opts.recurrence_end_date,
480
478
  };
481
479
  default:
482
480
  throw errValidation({
@@ -485,9 +483,6 @@ function normalizeRecurrenceEnd(opts) {
485
483
  });
486
484
  }
487
485
  }
488
- function sameCalendarDay(a, b) {
489
- return a.y === b.y && a.m === b.m && a.d === b.d;
490
- }
491
486
  function locationTimezone(location, field) {
492
487
  const out = location.timezone.trim();
493
488
  if (out === "") {
@@ -555,7 +550,6 @@ function datePart(parts, type) {
555
550
  }
556
551
  function locationAddressInput(location) {
557
552
  return {
558
- address_timezone: location.address_timezone,
559
553
  lat: location.lat,
560
554
  lon: location.lon,
561
555
  street: location.street,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.78",
3
+ "version": "0.0.80",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,7 +17,7 @@
17
17
  "typescript": "^6.0.3"
18
18
  },
19
19
  "dependencies": {
20
- "@fabriktor/client": "0.0.69",
20
+ "@fabriktor/client": "0.0.71",
21
21
  "@fabriktor/schema": "0.0.51"
22
22
  }
23
23
  }