@pallasoft/ps-core-components 2.47.0 → 2.48.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.
Files changed (78) hide show
  1. package/dist/components/ps-form-page-skeleton.d.ts +5 -1
  2. package/dist/components/ps-form-page-skeleton.js +1 -1
  3. package/dist/components/ps-metric-grid-skeleton.js +5 -1
  4. package/dist/components/ps-page-header.d.ts +2 -1
  5. package/dist/components/ps-page-header.js +1 -1
  6. package/dist/components/ps-page-skeleton.d.ts +2 -1
  7. package/dist/components/ps-page-skeleton.js +4 -1
  8. package/dist/components/ps-section-header.js +1 -1
  9. package/dist/components/ps-section-panel-skeleton.d.ts +2 -1
  10. package/dist/components/ps-section-panel-skeleton.js +4 -1
  11. package/dist/esm/components/ps-form-page-skeleton.js +1 -1
  12. package/dist/esm/components/ps-metric-grid-skeleton.js +5 -1
  13. package/dist/esm/components/ps-page-header.js +1 -1
  14. package/dist/esm/components/ps-page-skeleton.js +4 -1
  15. package/dist/esm/components/ps-section-header.js +1 -1
  16. package/dist/esm/components/ps-section-panel-skeleton.js +4 -1
  17. package/dist/esm/hooks/use-ps-optimistic-fetcher.js +2 -4
  18. package/dist/esm/hooks/use-ps-optimistic-save.js +1 -1
  19. package/dist/esm/hooks/use-ps-text-param.js +1 -1
  20. package/dist/esm/index.js +2 -12
  21. package/dist/esm/services/ps-draft-state-service.js +1 -1
  22. package/dist/hooks/use-ps-optimistic-fetcher.js +7 -9
  23. package/dist/hooks/use-ps-optimistic-save.js +4 -4
  24. package/dist/hooks/use-ps-text-param.js +2 -2
  25. package/dist/index.d.ts +2 -12
  26. package/dist/index.js +9 -12
  27. package/dist/interfaces/ps-optimistic-failure.d.ts +1 -1
  28. package/dist/interfaces/ps-optimistic-save-input.d.ts +1 -1
  29. package/dist/services/ps-draft-state-service.js +2 -2
  30. package/package.json +2 -2
  31. package/dist/constants/ps-optimistic-config.d.ts +0 -5
  32. package/dist/constants/ps-optimistic-config.js +0 -8
  33. package/dist/esm/constants/ps-optimistic-config.js +0 -5
  34. package/dist/esm/hooks/use-ps-change-queue.js +0 -36
  35. package/dist/esm/hooks/use-ps-debounced-value.js +0 -11
  36. package/dist/esm/hooks/use-ps-optimistic-rows.js +0 -29
  37. package/dist/esm/interfaces/ps-change-queue-input.js +0 -1
  38. package/dist/esm/interfaces/ps-change-queue-result.js +0 -1
  39. package/dist/esm/interfaces/ps-optimistic-changes.js +0 -1
  40. package/dist/esm/interfaces/ps-optimistic-failure-reason.js +0 -1
  41. package/dist/esm/interfaces/ps-optimistic-outcome.js +0 -1
  42. package/dist/esm/interfaces/ps-optimistic-rows-input.js +0 -1
  43. package/dist/esm/interfaces/ps-optimistic-rows-result.js +0 -1
  44. package/dist/esm/interfaces/ps-optimistic-save-spec.js +0 -1
  45. package/dist/esm/services/ps-deep-equal-service.js +0 -31
  46. package/dist/esm/services/ps-optimistic-fetcher-service.js +0 -12
  47. package/dist/esm/services/ps-optimistic-release-service.js +0 -38
  48. package/dist/esm/services/ps-optimistic-save-service.js +0 -64
  49. package/dist/hooks/use-ps-change-queue.d.ts +0 -3
  50. package/dist/hooks/use-ps-change-queue.js +0 -40
  51. package/dist/hooks/use-ps-debounced-value.d.ts +0 -1
  52. package/dist/hooks/use-ps-debounced-value.js +0 -15
  53. package/dist/hooks/use-ps-optimistic-rows.d.ts +0 -3
  54. package/dist/hooks/use-ps-optimistic-rows.js +0 -33
  55. package/dist/interfaces/ps-change-queue-input.d.ts +0 -5
  56. package/dist/interfaces/ps-change-queue-input.js +0 -2
  57. package/dist/interfaces/ps-change-queue-result.d.ts +0 -3
  58. package/dist/interfaces/ps-change-queue-result.js +0 -2
  59. package/dist/interfaces/ps-optimistic-changes.d.ts +0 -7
  60. package/dist/interfaces/ps-optimistic-changes.js +0 -2
  61. package/dist/interfaces/ps-optimistic-failure-reason.d.ts +0 -1
  62. package/dist/interfaces/ps-optimistic-failure-reason.js +0 -2
  63. package/dist/interfaces/ps-optimistic-outcome.d.ts +0 -5
  64. package/dist/interfaces/ps-optimistic-outcome.js +0 -2
  65. package/dist/interfaces/ps-optimistic-rows-input.d.ts +0 -6
  66. package/dist/interfaces/ps-optimistic-rows-input.js +0 -2
  67. package/dist/interfaces/ps-optimistic-rows-result.d.ts +0 -6
  68. package/dist/interfaces/ps-optimistic-rows-result.js +0 -2
  69. package/dist/interfaces/ps-optimistic-save-spec.d.ts +0 -11
  70. package/dist/interfaces/ps-optimistic-save-spec.js +0 -2
  71. package/dist/services/ps-deep-equal-service.d.ts +0 -5
  72. package/dist/services/ps-deep-equal-service.js +0 -35
  73. package/dist/services/ps-optimistic-fetcher-service.d.ts +0 -6
  74. package/dist/services/ps-optimistic-fetcher-service.js +0 -16
  75. package/dist/services/ps-optimistic-release-service.d.ts +0 -5
  76. package/dist/services/ps-optimistic-release-service.js +0 -42
  77. package/dist/services/ps-optimistic-save-service.d.ts +0 -11
  78. package/dist/services/ps-optimistic-save-service.js +0 -68
@@ -1,29 +0,0 @@
1
- import { useCallback, useEffect, useMemo, useState } from 'react';
2
- import { PsOptimisticConfig } from '../constants/ps-optimistic-config.js';
3
- import { PsOptimisticReleaseService } from '../services/ps-optimistic-release-service.js';
4
- export const usePsOptimisticRows = ({ apply, isHolding = false, isSaving, rows, }) => {
5
- const [remembered, setRemembered] = useState(() => PsOptimisticReleaseService.empty(rows));
6
- const isActive = isSaving || isHolding;
7
- const current = PsOptimisticReleaseService.next(remembered, rows, isActive, isHolding, apply);
8
- if (current !== remembered)
9
- setRemembered(current);
10
- const { changes } = current;
11
- const isHeld = changes.length > 0 && !isActive;
12
- const shown = useMemo(() => (changes.length === 0 ? rows : apply(rows, changes)), [apply, changes, rows]);
13
- useEffect(() => {
14
- if (!isHeld)
15
- return undefined;
16
- const timer = setTimeout(() => setRemembered(PsOptimisticReleaseService.empty(rows)), PsOptimisticConfig.releaseTimeoutMs);
17
- return () => clearTimeout(timer);
18
- }, [isHeld, changes, rows]);
19
- const remember = useCallback((change) => setRemembered((previous) => ({
20
- base: rows,
21
- changes: [...previous.changes, change],
22
- drainBase: null,
23
- wasActive: previous.wasActive,
24
- wasHolding: previous.wasHolding,
25
- })), [rows]);
26
- const forgetLast = useCallback(() => setRemembered((previous) => ({ ...previous, changes: previous.changes.slice(0, -1) })), []);
27
- const rollback = useCallback(() => setRemembered(PsOptimisticReleaseService.empty(rows)), [rows]);
28
- return { forgetLast, remember, rollback, rows: shown };
29
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,31 +0,0 @@
1
- export class PsDeepEqualService {
2
- static isEqual(left, right) {
3
- if (Object.is(left, right))
4
- return true;
5
- if (typeof left !== 'object' || typeof right !== 'object')
6
- return false;
7
- if (left === null || right === null)
8
- return false;
9
- if (Array.isArray(left) || Array.isArray(right))
10
- return PsDeepEqualService.isArrayEqual(left, right);
11
- if (left instanceof Date || right instanceof Date) {
12
- return left instanceof Date && right instanceof Date && left.getTime() === right.getTime();
13
- }
14
- return PsDeepEqualService.isRecordEqual(left, right);
15
- }
16
- static isArrayEqual(left, right) {
17
- if (!Array.isArray(left) || !Array.isArray(right))
18
- return false;
19
- if (left.length !== right.length)
20
- return false;
21
- return left.every((item, index) => PsDeepEqualService.isEqual(item, right[index]));
22
- }
23
- static isRecordEqual(left, right) {
24
- const leftEntries = Object.entries(left);
25
- const rightRecord = { ...right };
26
- if (leftEntries.length !== Object.keys(rightRecord).length)
27
- return false;
28
- return leftEntries.every(([key, value]) => Object.prototype.hasOwnProperty.call(rightRecord, key) &&
29
- PsDeepEqualService.isEqual(value, rightRecord[key]));
30
- }
31
- }
@@ -1,12 +0,0 @@
1
- export class PsOptimisticFetcherService {
2
- static outcome(data, before) {
3
- if (data === before)
4
- return { data: undefined, reason: 'no-response' };
5
- return { data, reason: 'settled' };
6
- }
7
- static failureReason(outcome, isSuccess) {
8
- if (outcome.reason !== 'settled')
9
- return outcome.reason;
10
- return isSuccess(outcome.data) ? null : 'rejected';
11
- }
12
- }
@@ -1,38 +0,0 @@
1
- import { PsDeepEqualService } from './ps-deep-equal-service.js';
2
- export class PsOptimisticReleaseService {
3
- static empty(rows) {
4
- return { base: rows, changes: [], drainBase: null, wasActive: false, wasHolding: false };
5
- }
6
- static next(remembered, rows, isActive, isHolding, apply) {
7
- if (isActive) {
8
- const wasHolding = remembered.wasHolding || isHolding;
9
- if (remembered.wasActive &&
10
- remembered.drainBase === null &&
11
- remembered.wasHolding === wasHolding)
12
- return remembered;
13
- return { ...remembered, drainBase: null, wasActive: true, wasHolding };
14
- }
15
- if (remembered.changes.length === 0) {
16
- if (remembered.base === rows && !remembered.wasActive)
17
- return remembered;
18
- return PsOptimisticReleaseService.empty(rows);
19
- }
20
- if (remembered.wasActive) {
21
- if (remembered.wasHolding && rows !== remembered.base) {
22
- return PsOptimisticReleaseService.empty(rows);
23
- }
24
- if (!PsDeepEqualService.isEqual(rows, remembered.base)) {
25
- return PsOptimisticReleaseService.empty(rows);
26
- }
27
- return { ...remembered, drainBase: rows, wasActive: false, wasHolding: false };
28
- }
29
- const reference = remembered.drainBase === null ? remembered.base : remembered.drainBase;
30
- if (!PsDeepEqualService.isEqual(rows, reference)) {
31
- return PsOptimisticReleaseService.empty(rows);
32
- }
33
- if (PsDeepEqualService.isEqual(apply(rows, remembered.changes), rows)) {
34
- return PsOptimisticReleaseService.empty(rows);
35
- }
36
- return remembered;
37
- }
38
- }
@@ -1,64 +0,0 @@
1
- import { PsOptimisticConfig } from '../constants/ps-optimistic-config.js';
2
- export class PsOptimisticSaveService {
3
- static isPending(id) {
4
- return id.startsWith(PsOptimisticConfig.pendingPrefix);
5
- }
6
- static pendingId() {
7
- return `${PsOptimisticConfig.pendingPrefix}${crypto.randomUUID()}`;
8
- }
9
- static saveValues(spec, values, existingId, scopeId) {
10
- const fields = spec.isFlat
11
- ? Object.fromEntries(Object.entries(values).map(([key, value]) => [key, String(value)]))
12
- : { values: JSON.stringify(values) };
13
- return {
14
- ...fields,
15
- [spec.idField]: existingId,
16
- intent: spec.intent,
17
- pendingId: PsOptimisticSaveService.pendingId(),
18
- scopeId,
19
- };
20
- }
21
- static removeValues(spec, ids) {
22
- return spec.remove === undefined
23
- ? {}
24
- : { [spec.remove.idsField]: JSON.stringify(ids), intent: spec.remove.intent };
25
- }
26
- static apply(rows, changes, spec) {
27
- return changes.reduce((current, change) => {
28
- if (change.intent === spec.intent)
29
- return PsOptimisticSaveService.saved(current, change, spec);
30
- if (spec.remove !== undefined && change.intent === spec.remove.intent)
31
- return PsOptimisticSaveService.removed(current, change, spec, spec.remove.idsField);
32
- return current;
33
- }, rows);
34
- }
35
- static read(raw) {
36
- if (raw === undefined)
37
- return null;
38
- try {
39
- return JSON.parse(raw);
40
- }
41
- catch {
42
- return null;
43
- }
44
- }
45
- static saved(rows, change, spec) {
46
- const parsed = spec.isFlat ? change : PsOptimisticSaveService.read(change.values);
47
- if (parsed === null || typeof parsed !== 'object')
48
- return rows;
49
- const existingId = change[spec.idField];
50
- const id = existingId === '' ? change.pendingId : existingId;
51
- const previous = rows.find((row) => spec.getId(row) === existingId);
52
- const built = spec.build(parsed, id, previous === undefined ? null : previous, change.scopeId);
53
- if (built === null)
54
- return rows;
55
- return previous === undefined
56
- ? [...rows, built]
57
- : rows.map((row) => (spec.getId(row) === existingId ? built : row));
58
- }
59
- static removed(rows, change, spec, idsField) {
60
- const parsed = PsOptimisticSaveService.read(change[idsField]);
61
- const ids = new Set(Array.isArray(parsed) ? parsed : []);
62
- return rows.filter((row) => !ids.has(spec.getId(row)));
63
- }
64
- }
@@ -1,3 +0,0 @@
1
- import type { PsChangeQueueInput } from '../interfaces/ps-change-queue-input';
2
- import type { PsChangeQueueResult } from '../interfaces/ps-change-queue-result';
3
- export declare const usePsChangeQueue: <Change>({ onDrained, onFailed, send, }: PsChangeQueueInput<Change>) => PsChangeQueueResult<Change>;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePsChangeQueue = void 0;
4
- const react_1 = require("react");
5
- const usePsChangeQueue = ({ onDrained, onFailed, send, }) => {
6
- const pending = (0, react_1.useRef)([]);
7
- const isRunning = (0, react_1.useRef)(false);
8
- const latest = (0, react_1.useRef)({ onDrained, onFailed, send });
9
- (0, react_1.useEffect)(() => {
10
- latest.current = { onDrained, onFailed, send };
11
- }, [onDrained, onFailed, send]);
12
- const run = (0, react_1.useCallback)(async () => {
13
- if (isRunning.current)
14
- return;
15
- isRunning.current = true;
16
- await Promise.resolve();
17
- while (pending.current.length > 0) {
18
- const batch = pending.current;
19
- pending.current = [];
20
- await new Promise((resolve) => resolve(latest.current.send(batch))).catch(() => {
21
- const dropped = pending.current;
22
- pending.current = [];
23
- try {
24
- latest.current.onFailed(batch, dropped);
25
- }
26
- catch {
27
- return;
28
- }
29
- });
30
- }
31
- isRunning.current = false;
32
- latest.current.onDrained();
33
- }, []);
34
- const enqueue = (0, react_1.useCallback)((change) => {
35
- pending.current = [...pending.current, change];
36
- void run();
37
- }, [run]);
38
- return { enqueue };
39
- };
40
- exports.usePsChangeQueue = usePsChangeQueue;
@@ -1 +0,0 @@
1
- export declare const usePsDebouncedValue: <T>(value: T, waitMs: number) => T;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePsDebouncedValue = void 0;
4
- const react_1 = require("react");
5
- const ps_utilities_1 = require("@pallasoft/ps-utilities");
6
- const usePsDebouncedValue = (value, waitMs) => {
7
- const [settled, setSettled] = (0, react_1.useState)(value);
8
- (0, react_1.useEffect)(() => {
9
- const debounced = ps_utilities_1.Client.DebounceService.create((next) => setSettled(next), waitMs);
10
- debounced.run(value);
11
- return debounced.cancel;
12
- }, [value, waitMs]);
13
- return settled;
14
- };
15
- exports.usePsDebouncedValue = usePsDebouncedValue;
@@ -1,3 +0,0 @@
1
- import type { PsOptimisticRowsInput } from '../interfaces/ps-optimistic-rows-input';
2
- import type { PsOptimisticRowsResult } from '../interfaces/ps-optimistic-rows-result';
3
- export declare const usePsOptimisticRows: <Row, Change>({ apply, isHolding, isSaving, rows, }: PsOptimisticRowsInput<Row, Change>) => PsOptimisticRowsResult<Row, Change>;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePsOptimisticRows = void 0;
4
- const react_1 = require("react");
5
- const ps_optimistic_config_1 = require("../constants/ps-optimistic-config");
6
- const ps_optimistic_release_service_1 = require("../services/ps-optimistic-release-service");
7
- const usePsOptimisticRows = ({ apply, isHolding = false, isSaving, rows, }) => {
8
- const [remembered, setRemembered] = (0, react_1.useState)(() => ps_optimistic_release_service_1.PsOptimisticReleaseService.empty(rows));
9
- const isActive = isSaving || isHolding;
10
- const current = ps_optimistic_release_service_1.PsOptimisticReleaseService.next(remembered, rows, isActive, isHolding, apply);
11
- if (current !== remembered)
12
- setRemembered(current);
13
- const { changes } = current;
14
- const isHeld = changes.length > 0 && !isActive;
15
- const shown = (0, react_1.useMemo)(() => (changes.length === 0 ? rows : apply(rows, changes)), [apply, changes, rows]);
16
- (0, react_1.useEffect)(() => {
17
- if (!isHeld)
18
- return undefined;
19
- const timer = setTimeout(() => setRemembered(ps_optimistic_release_service_1.PsOptimisticReleaseService.empty(rows)), ps_optimistic_config_1.PsOptimisticConfig.releaseTimeoutMs);
20
- return () => clearTimeout(timer);
21
- }, [isHeld, changes, rows]);
22
- const remember = (0, react_1.useCallback)((change) => setRemembered((previous) => ({
23
- base: rows,
24
- changes: [...previous.changes, change],
25
- drainBase: null,
26
- wasActive: previous.wasActive,
27
- wasHolding: previous.wasHolding,
28
- })), [rows]);
29
- const forgetLast = (0, react_1.useCallback)(() => setRemembered((previous) => ({ ...previous, changes: previous.changes.slice(0, -1) })), []);
30
- const rollback = (0, react_1.useCallback)(() => setRemembered(ps_optimistic_release_service_1.PsOptimisticReleaseService.empty(rows)), [rows]);
31
- return { forgetLast, remember, rollback, rows: shown };
32
- };
33
- exports.usePsOptimisticRows = usePsOptimisticRows;
@@ -1,5 +0,0 @@
1
- export interface PsChangeQueueInput<Change> {
2
- onDrained: () => void;
3
- onFailed: (failed: Change[], dropped: Change[]) => void;
4
- send: (changes: Change[]) => Promise<unknown>;
5
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- export interface PsChangeQueueResult<Change> {
2
- enqueue: (change: Change) => void;
3
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +0,0 @@
1
- export interface PsOptimisticChanges<Row, Change> {
2
- base: Row[];
3
- changes: Change[];
4
- drainBase: Row[] | null;
5
- wasActive: boolean;
6
- wasHolding: boolean;
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export type PsOptimisticFailureReason = 'error' | 'no-response' | 'rejected' | 'timeout' | 'unmounted';
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +0,0 @@
1
- import type { PsOptimisticFailureReason } from './ps-optimistic-failure-reason';
2
- export interface PsOptimisticOutcome<Data> {
3
- data: Data | undefined;
4
- reason: PsOptimisticFailureReason | 'settled';
5
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +0,0 @@
1
- export interface PsOptimisticRowsInput<Row, Change> {
2
- apply: (rows: Row[], changes: Change[]) => Row[];
3
- isHolding?: boolean;
4
- isSaving: boolean;
5
- rows: Row[];
6
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +0,0 @@
1
- export interface PsOptimisticRowsResult<Row, Change> {
2
- forgetLast: () => void;
3
- remember: (change: Change) => void;
4
- rollback: () => void;
5
- rows: Row[];
6
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +0,0 @@
1
- export interface PsOptimisticSaveSpec<Row, Values> {
2
- build: (values: Values, id: string, previous: Row | null, scopeId: string) => Row | null;
3
- getId: (row: Row) => string;
4
- idField: string;
5
- intent: string;
6
- isFlat: boolean;
7
- remove?: {
8
- idsField: string;
9
- intent: string;
10
- };
11
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +0,0 @@
1
- export declare class PsDeepEqualService {
2
- static isEqual(left: unknown, right: unknown): boolean;
3
- private static isArrayEqual;
4
- private static isRecordEqual;
5
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PsDeepEqualService = void 0;
4
- class PsDeepEqualService {
5
- static isEqual(left, right) {
6
- if (Object.is(left, right))
7
- return true;
8
- if (typeof left !== 'object' || typeof right !== 'object')
9
- return false;
10
- if (left === null || right === null)
11
- return false;
12
- if (Array.isArray(left) || Array.isArray(right))
13
- return PsDeepEqualService.isArrayEqual(left, right);
14
- if (left instanceof Date || right instanceof Date) {
15
- return left instanceof Date && right instanceof Date && left.getTime() === right.getTime();
16
- }
17
- return PsDeepEqualService.isRecordEqual(left, right);
18
- }
19
- static isArrayEqual(left, right) {
20
- if (!Array.isArray(left) || !Array.isArray(right))
21
- return false;
22
- if (left.length !== right.length)
23
- return false;
24
- return left.every((item, index) => PsDeepEqualService.isEqual(item, right[index]));
25
- }
26
- static isRecordEqual(left, right) {
27
- const leftEntries = Object.entries(left);
28
- const rightRecord = { ...right };
29
- if (leftEntries.length !== Object.keys(rightRecord).length)
30
- return false;
31
- return leftEntries.every(([key, value]) => Object.prototype.hasOwnProperty.call(rightRecord, key) &&
32
- PsDeepEqualService.isEqual(value, rightRecord[key]));
33
- }
34
- }
35
- exports.PsDeepEqualService = PsDeepEqualService;
@@ -1,6 +0,0 @@
1
- import type { PsOptimisticFailureReason } from '../interfaces/ps-optimistic-failure-reason';
2
- import type { PsOptimisticOutcome } from '../interfaces/ps-optimistic-outcome';
3
- export declare class PsOptimisticFetcherService {
4
- static outcome<Data>(data: Data | undefined, before: Data | undefined): PsOptimisticOutcome<Data>;
5
- static failureReason<Data>(outcome: PsOptimisticOutcome<Data>, isSuccess: (data: Data | undefined) => boolean): PsOptimisticFailureReason | null;
6
- }
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PsOptimisticFetcherService = void 0;
4
- class PsOptimisticFetcherService {
5
- static outcome(data, before) {
6
- if (data === before)
7
- return { data: undefined, reason: 'no-response' };
8
- return { data, reason: 'settled' };
9
- }
10
- static failureReason(outcome, isSuccess) {
11
- if (outcome.reason !== 'settled')
12
- return outcome.reason;
13
- return isSuccess(outcome.data) ? null : 'rejected';
14
- }
15
- }
16
- exports.PsOptimisticFetcherService = PsOptimisticFetcherService;
@@ -1,5 +0,0 @@
1
- import type { PsOptimisticChanges } from '../interfaces/ps-optimistic-changes';
2
- export declare class PsOptimisticReleaseService {
3
- static empty<Row, Change>(rows: Row[]): PsOptimisticChanges<Row, Change>;
4
- static next<Row, Change>(remembered: PsOptimisticChanges<Row, Change>, rows: Row[], isActive: boolean, isHolding: boolean, apply: (rows: Row[], changes: Change[]) => Row[]): PsOptimisticChanges<Row, Change>;
5
- }
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PsOptimisticReleaseService = void 0;
4
- const ps_deep_equal_service_1 = require("./ps-deep-equal-service");
5
- class PsOptimisticReleaseService {
6
- static empty(rows) {
7
- return { base: rows, changes: [], drainBase: null, wasActive: false, wasHolding: false };
8
- }
9
- static next(remembered, rows, isActive, isHolding, apply) {
10
- if (isActive) {
11
- const wasHolding = remembered.wasHolding || isHolding;
12
- if (remembered.wasActive &&
13
- remembered.drainBase === null &&
14
- remembered.wasHolding === wasHolding)
15
- return remembered;
16
- return { ...remembered, drainBase: null, wasActive: true, wasHolding };
17
- }
18
- if (remembered.changes.length === 0) {
19
- if (remembered.base === rows && !remembered.wasActive)
20
- return remembered;
21
- return PsOptimisticReleaseService.empty(rows);
22
- }
23
- if (remembered.wasActive) {
24
- if (remembered.wasHolding && rows !== remembered.base) {
25
- return PsOptimisticReleaseService.empty(rows);
26
- }
27
- if (!ps_deep_equal_service_1.PsDeepEqualService.isEqual(rows, remembered.base)) {
28
- return PsOptimisticReleaseService.empty(rows);
29
- }
30
- return { ...remembered, drainBase: rows, wasActive: false, wasHolding: false };
31
- }
32
- const reference = remembered.drainBase === null ? remembered.base : remembered.drainBase;
33
- if (!ps_deep_equal_service_1.PsDeepEqualService.isEqual(rows, reference)) {
34
- return PsOptimisticReleaseService.empty(rows);
35
- }
36
- if (ps_deep_equal_service_1.PsDeepEqualService.isEqual(apply(rows, remembered.changes), rows)) {
37
- return PsOptimisticReleaseService.empty(rows);
38
- }
39
- return remembered;
40
- }
41
- }
42
- exports.PsOptimisticReleaseService = PsOptimisticReleaseService;
@@ -1,11 +0,0 @@
1
- import type { PsOptimisticSaveSpec } from '../interfaces/ps-optimistic-save-spec';
2
- export declare class PsOptimisticSaveService {
3
- static isPending(id: string): boolean;
4
- static pendingId(): string;
5
- static saveValues<Row, Values>(spec: PsOptimisticSaveSpec<Row, Values>, values: Values, existingId: string, scopeId: string): Record<string, string>;
6
- static removeValues<Row, Values>(spec: PsOptimisticSaveSpec<Row, Values>, ids: string[]): Record<string, string>;
7
- static apply<Row, Values>(rows: Row[], changes: Record<string, string>[], spec: PsOptimisticSaveSpec<Row, Values>): Row[];
8
- private static read;
9
- private static saved;
10
- private static removed;
11
- }
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PsOptimisticSaveService = void 0;
4
- const ps_optimistic_config_1 = require("../constants/ps-optimistic-config");
5
- class PsOptimisticSaveService {
6
- static isPending(id) {
7
- return id.startsWith(ps_optimistic_config_1.PsOptimisticConfig.pendingPrefix);
8
- }
9
- static pendingId() {
10
- return `${ps_optimistic_config_1.PsOptimisticConfig.pendingPrefix}${crypto.randomUUID()}`;
11
- }
12
- static saveValues(spec, values, existingId, scopeId) {
13
- const fields = spec.isFlat
14
- ? Object.fromEntries(Object.entries(values).map(([key, value]) => [key, String(value)]))
15
- : { values: JSON.stringify(values) };
16
- return {
17
- ...fields,
18
- [spec.idField]: existingId,
19
- intent: spec.intent,
20
- pendingId: PsOptimisticSaveService.pendingId(),
21
- scopeId,
22
- };
23
- }
24
- static removeValues(spec, ids) {
25
- return spec.remove === undefined
26
- ? {}
27
- : { [spec.remove.idsField]: JSON.stringify(ids), intent: spec.remove.intent };
28
- }
29
- static apply(rows, changes, spec) {
30
- return changes.reduce((current, change) => {
31
- if (change.intent === spec.intent)
32
- return PsOptimisticSaveService.saved(current, change, spec);
33
- if (spec.remove !== undefined && change.intent === spec.remove.intent)
34
- return PsOptimisticSaveService.removed(current, change, spec, spec.remove.idsField);
35
- return current;
36
- }, rows);
37
- }
38
- static read(raw) {
39
- if (raw === undefined)
40
- return null;
41
- try {
42
- return JSON.parse(raw);
43
- }
44
- catch {
45
- return null;
46
- }
47
- }
48
- static saved(rows, change, spec) {
49
- const parsed = spec.isFlat ? change : PsOptimisticSaveService.read(change.values);
50
- if (parsed === null || typeof parsed !== 'object')
51
- return rows;
52
- const existingId = change[spec.idField];
53
- const id = existingId === '' ? change.pendingId : existingId;
54
- const previous = rows.find((row) => spec.getId(row) === existingId);
55
- const built = spec.build(parsed, id, previous === undefined ? null : previous, change.scopeId);
56
- if (built === null)
57
- return rows;
58
- return previous === undefined
59
- ? [...rows, built]
60
- : rows.map((row) => (spec.getId(row) === existingId ? built : row));
61
- }
62
- static removed(rows, change, spec, idsField) {
63
- const parsed = PsOptimisticSaveService.read(change[idsField]);
64
- const ids = new Set(Array.isArray(parsed) ? parsed : []);
65
- return rows.filter((row) => !ids.has(spec.getId(row)));
66
- }
67
- }
68
- exports.PsOptimisticSaveService = PsOptimisticSaveService;