@art-lib/operations 0.0.1 → 0.0.3

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 (36) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/README.md +68 -64
  3. package/dist/index.mjs +47 -39
  4. package/dist/index.mjs.map +3 -3
  5. package/dist/log/createOperationsLog.d.ts +2 -1
  6. package/dist/log/createPipeSeparatedFormatter.d.ts +3 -0
  7. package/dist/log/index.d.ts +2 -1
  8. package/dist/log/index.mjs +32 -3
  9. package/dist/log/index.mjs.map +3 -3
  10. package/dist/log/private/constants.d.ts +4 -0
  11. package/dist/log/private/isFinished.d.ts +3 -2
  12. package/dist/log/types.d.ts +7 -13
  13. package/dist/model/createGenericOperation.d.ts +3 -1
  14. package/dist/model/createOperationFailure.d.ts +1 -3
  15. package/dist/model/createOperationSuccess.d.ts +1 -1
  16. package/dist/model/index.d.ts +1 -1
  17. package/dist/model/index.mjs +16 -37
  18. package/dist/model/index.mjs.map +3 -3
  19. package/dist/model/private/formatData.d.ts +1 -0
  20. package/dist/model/types.d.ts +6 -12
  21. package/dist/test/helpers/log/createOperationsLogMock.d.ts +3 -0
  22. package/dist/test/helpers/model/makeFailureOperationFixture.d.ts +3 -0
  23. package/dist/test/helpers/model/makePendingOperationFixture.d.ts +3 -0
  24. package/dist/test/helpers/model/makeSuccessOperationFixture.d.ts +3 -0
  25. package/dist/test/helpers/model/types.d.ts +3 -0
  26. package/package.json +8 -12
  27. package/src/test/helpers/log/createOperationsLogMock.ts +13 -0
  28. package/src/test/helpers/model/makeFailureOperationFixture.ts +19 -0
  29. package/src/test/helpers/model/makePendingOperationFixture.ts +14 -0
  30. package/src/test/helpers/model/makeSuccessOperationFixture.ts +18 -0
  31. package/src/test/helpers/model/operationFixtures.test.ts +13 -0
  32. package/src/test/helpers/model/types.ts +3 -0
  33. package/dist/model/private/constants.d.ts +0 -3
  34. package/dist/model/private/readInputUri.d.ts +0 -1
  35. package/dist/test/helpers/logger/createLoggerMock.d.ts +0 -3
  36. package/dist/test/helpers/logger/types.d.ts +0 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.0.1
3
+ ## 0.0.3
4
4
 
5
5
  ### Added
6
+
7
+ - Add an injectable operation formatter and a pipe-separated formatter for status symbols and elapsed time.
8
+ - Export reusable operation test helpers.
9
+
10
+ ### Changed
11
+
12
+ - Use `@art-lib/logger` 0.0.4; translate operation outcomes into logger messages and levels.
13
+ - Consolidate model and log APIs at the package root.
14
+
15
+ ### Removed
16
+
17
+ - Remove operation-level `level`, failure labels, and `errorSerialized()`.
18
+
19
+ ### Tested
20
+
21
+ - Cover typed operation lifecycles, formatter output, logger forwarding, history queries, and error handling.
22
+
23
+ ### Documented
24
+
25
+ - Update the README and architecture documents for the operation model, logger boundary, and formatter.
26
+
27
+ ## 0.0.2
28
+
29
+ ### Added
30
+
31
+ - Extend the three model factories with `<D>` generics and an optional `message` hook on `createGenericOperation`.
package/README.md CHANGED
@@ -1,110 +1,114 @@
1
1
  # @art-lib/operations
2
2
 
3
- > Operation outcome types and factories, and an append-only operations log that forwards every operation to the logger.
3
+ > Model CLI operations and forward their formatted messages to `@art-lib/logger`.
4
4
 
5
5
  This package is part of the [Art Lib toolkit](../../README.md).
6
6
 
7
- ## Design
8
-
9
- The package publishes two subpath modules. **`/model`** is the pure operation model: one unit of work in a command invocation with a `pending`, `success`, or `failure` outcome, plus the factories that move a pending operation to a finished one. **`/log`** is the append-only operations log: created with the logger, it forwards every operation to it and keeps the finished ones queryable.
10
-
11
- Operations conform to the `Message` interface of [`@art-lib/logger`](../logger/README.md) structurally — the level is derived from the outcome (`pending` → `debug`, `success` → `info`, `failure` → `error`) — so the logger never learns about operations. The logger is this package's only dependency.
12
-
13
- See also:
14
-
15
- - [package knowledge](knowledge/index.md) — overview, design, and decision records
16
- - [repository design record](../../knowledge/design/operations.md) — what a CLI needs from the package
17
-
18
- ## Usage
19
-
20
- ### Install
7
+ ## Install
21
8
 
22
9
  ```bash
23
10
  npm install @art-lib/operations
24
11
  ```
25
12
 
26
- `@art-lib/logger` arrives as a dependency; import it wherever you create the logger.
13
+ Import public operations APIs from `@art-lib/operations`.
27
14
 
28
- ### Configure
15
+ ## Use the generic operation model
29
16
 
30
- Create one operations log per command invocation, right after the logger. Every operation logged through it is forwarded to the logger, so resolve the output mode first:
17
+ The generic factory creates a pending operation from a name, typed data, and an optional function that supplies its detail text. Shared factories create its success or failure state.
31
18
 
32
19
  ```ts
33
20
  import { createLogger } from '@art-lib/logger';
34
- import { createOperationsLog } from '@art-lib/operations/log';
21
+ import {
22
+ createGenericOperation,
23
+ createOperationFailure,
24
+ createOperationSuccess,
25
+ createOperationsLog,
26
+ createPipeSeparatedFormatter,
27
+ } from '@art-lib/operations';
35
28
 
36
29
  const logger = createLogger();
30
+ logger.setOutputMode('normal');
31
+
32
+ const operations = createOperationsLog(logger, {
33
+ formatter: createPipeSeparatedFormatter(operation => [operation.operation, operation.text()]),
34
+ });
37
35
 
38
- // Buffered messages flush as soon as the mode is resolved.
39
- logger.setOutputMode(process.env.VERBOSE ? 'verbose' : 'normal');
36
+ const uri = 'notes.art';
37
+ const pending = createGenericOperation('parse', { uri }, () => uri);
38
+ operations.log(pending);
40
39
 
41
- // One log per command invocation; discard it when the invocation ends.
42
- export const operations = createOperationsLog(logger);
40
+ try {
41
+ const document = await parse(uri);
42
+ operations.log(createOperationSuccess(pending, `parsed ${document.name}`));
43
+ } catch (error) {
44
+ operations.log(createOperationFailure(pending, error));
45
+ }
43
46
  ```
44
47
 
45
- The package root re-exports both subpaths, so `import { ... } from '@art-lib/operations'` works as well.
48
+ The formatter callback returns the ordered field values for an operation. The default pipe-separated formatter adds an outcome symbol and, for completed operations, the elapsed time. The operations log derives the logger level from the outcome—`pending` to `debug`, `success` to `info`, and `failure` to `error`—then forwards a `{ level, text, ts }` message to the injected logger.
46
49
 
47
- ### Example
50
+ ## Define CLI-specific operations
51
+
52
+ A CLI can define a typed pending operation and one factory for each operation kind. Each factory specialises the shared model with a literal operation name, a typed data shape, and operation-specific detail text. The shared success and failure factories handle completion for all operation kinds.
48
53
 
49
54
  ```ts
50
55
  import {
51
56
  createGenericOperation,
52
- createOperationFailure,
53
- createOperationSuccess,
57
+ type OperationPending,
58
+ type OperationSuccess,
59
+ type OperationFailure,
54
60
  } from '@art-lib/operations';
55
- import { operations } from './log.js';
56
61
 
57
- const startedAt = Date.now();
62
+ export type PullData = {
63
+ checkout?: Checkout;
64
+ branch: string;
65
+ };
58
66
 
59
- const pending = createGenericOperation('clone', { repo });
60
- operations.log(pending); // forwarded as `debug`; pending operations are not stored
67
+ export type PullPending = OperationPending<PullData> & {
68
+ operation: 'pull';
69
+ };
61
70
 
62
- try {
63
- const path = await clone(pending.data.repo);
71
+ export function createPullOperation(checkout: Checkout, branch: string): PullPending {
72
+ const data = { checkout, branch };
73
+ const toText = () => `from origin/${branch}`;
64
74
 
65
- operations.log(createOperationSuccess(pending, `cloned ${path}`)); // stored
66
- } catch (error) {
67
- // The label prefixes `errorSerialized()` only — `error` stays the raw message.
68
- operations.log(createOperationFailure(pending, error, { label: 'CloneError' })); // stored
75
+ return createGenericOperation('pull', data, toText);
69
76
  }
70
77
 
71
- // The log keeps finished operations only, in order:
72
- operations.all(); // every finished operation
73
- operations.since(startedAt); // created at or after `startedAt`
74
- operations.latest(5); // the last five finished operations
78
+ export type Operation = PullPending | OperationPending | OperationSuccess | OperationFailure;
75
79
  ```
76
80
 
77
- ### Options
81
+ A CLI's complete `Operation` union combines its specific pending types—such as `ClonePending`, `PushPending`, and `PullPending`—with the common pending, success, and failure types. Its formatter callback selects the fields for the CLI's standard output layout.
78
82
 
79
- | Function | Arguments | Returns | Notes |
80
- | -------------------------------------------- | ------------------------------------------------- | ------------------ | -------------------------------------------------------------------------- |
81
- | `createGenericOperation(name, data?)` | operation name, optional payload | `OperationPending` | frozen; `message()` reports `data.uri` when present; `timing()` is `NaN` |
82
- | `createOperationSuccess(pending, message?)` | a pending operation, optional success message | `OperationSuccess` | `message()` falls back to `pending.message()` |
83
- | `createOperationFailure(pending, error, o?)` | a pending operation, any error-shaped value, `o?` | `OperationFailure` | `o.label` prefixes `errorSerialized()`; without it the raw message is used |
84
- | `createOperationsLog(logger, options?)` | a `LoggerAPI`, reserved options | `OperationsLog` | forwards every operation; stores finished operations only |
83
+ ## Operations log
85
84
 
86
- - **`data`** — carried on the operation untouched and read back by the factory closures; a `uri` string property becomes `message()` until a success message overrides it.
87
- - **`options`** — `createOperationsLog` accepts and deliberately ignores it; it is reserved for a future iteration.
88
- - **`OperationsLog`** — `log(operation)`, `all()`, `since(timestamp)`, and `latest(count)`; queries return copies, never the internal buffer.
85
+ Create one operations log with a logger and formatter for each command invocation. Every logged operation is converted to a logger message and forwarded. Completed operations are retained for `all()`, `since(timestamp)`, and `latest(count)` queries; pending operations are forwarded as well.
89
86
 
90
- ## Development
87
+ The standard pipe-separated format can produce output such as:
91
88
 
92
- Make sure you read the [Art Lib README](../../README.md) first.
89
+ ```text
90
+ ⏳ | Art MD | art-md | pull | from origin/main |
91
+ 🔴 | Workspace Tooling | workspace-tooling | pull | Could not read from remote repository. | (1224ms)
92
+ ⏳ | Art MD | art-md | scan-checkout-state | art-md |
93
+ 🟢 | Art MD | art-md | pull | from origin/main | (3317ms)
94
+ ```
95
+
96
+ ## Development
93
97
 
94
- ### Build Targets
98
+ Read the [Art Lib README](../../README.md) before contributing.
95
99
 
96
- This package is meant for use in Node.js environments. The entry point is built using `esbuild` pre-configured by [Workspace Tooling](https://github.com/noodlestan/workspace-tooling).
100
+ This package targets Node.js and uses `esbuild` for its entry point.
97
101
 
98
- ### Scripts
102
+ Available scripts:
99
103
 
100
- - **$** `npm run dev` — Watch mode for development
101
- - **$** `npm run lint` — Check formatting, lint, and type check
102
- - **$** `npm run lint:fix` — Fix formatting and lint issues
103
- - **$** `npm run build` — Build the package
104
- - **$** `npm run build:clean` — Remove build artifacts
105
- - **$** `npm run test` — Run tests
106
- - **$** `npm run ci` — Run CI pipeline
104
+ - `npm run dev` — Watch for changes
105
+ - `npm run lint` — Check formatting, lint and types
106
+ - `npm run lint:fix` — Fix formatting and lint issues
107
+ - `npm run build` — Build the package
108
+ - `npm run build:clean` — Remove build artefacts
109
+ - `npm run test` — Run tests
110
+ - `npm run ci` — Run the CI pipeline
107
111
 
108
112
  ## Copyright (c) 2026 [Noodlestan](https://noodlestan.org/).
109
113
 
110
- Published under a [MIT license](https://noodlestan.mit-license.org/).
114
+ Published under the [MIT licence](https://noodlestan.mit-license.org/).
package/dist/index.mjs CHANGED
@@ -1,3 +1,15 @@
1
+ // src/log/private/constants.ts
2
+ var OUTCOME_SYMBOLS = {
3
+ pending: "\u23F3",
4
+ success: "\u{1F7E2}",
5
+ failure: "\u{1F534}"
6
+ };
7
+ var OUTCOME_LEVELS = {
8
+ pending: "debug",
9
+ success: "info",
10
+ failure: "error"
11
+ };
12
+
1
13
  // src/log/private/isFinished.ts
2
14
  function isFinished(operation) {
3
15
  return operation.outcome !== "pending";
@@ -5,11 +17,15 @@ function isFinished(operation) {
5
17
 
6
18
  // src/log/createOperationsLog.ts
7
19
  function createOperationsLog(logger, options) {
8
- void options;
9
20
  const storedOperations = [];
10
21
  return {
11
22
  log(operation) {
12
- logger.log(operation);
23
+ const message = {
24
+ level: OUTCOME_LEVELS[operation.outcome],
25
+ text: options.formatter(operation),
26
+ ts: operation.ts
27
+ };
28
+ logger.log(message);
13
29
  if (isFinished(operation)) {
14
30
  storedOperations.push(operation);
15
31
  }
@@ -29,39 +45,39 @@ function createOperationsLog(logger, options) {
29
45
  };
30
46
  }
31
47
 
32
- // src/model/private/constants.ts
33
- var LEVELS = {
34
- pending: "debug",
35
- success: "info",
36
- failure: "error"
37
- };
48
+ // src/log/createPipeSeparatedFormatter.ts
49
+ function createPipeSeparatedFormatter(getFields) {
50
+ return (operation) => {
51
+ const fields = [OUTCOME_SYMBOLS[operation.outcome], ...getFields(operation)];
52
+ const line = `${fields.join(" | ")} |`;
53
+ if (operation.outcome === "pending") {
54
+ return line;
55
+ }
56
+ return `${line} (${operation.timing()}ms)`;
57
+ };
58
+ }
38
59
 
39
- // src/model/private/readInputUri.ts
40
- function readInputUri(data) {
41
- if (typeof data !== "object" || data === null || !("uri" in data)) {
42
- return "";
43
- }
44
- const { uri } = data;
45
- return typeof uri === "string" ? uri : "";
60
+ // src/model/private/formatData.ts
61
+ function formatData(data) {
62
+ return data ? JSON.stringify(data) : "";
46
63
  }
47
64
 
48
65
  // src/model/createGenericOperation.ts
49
- function createGenericOperation(name, data) {
66
+ function createGenericOperation(name, data, toText) {
50
67
  const ts = Date.now();
51
- function message() {
52
- return readInputUri(data);
68
+ const resolveToText = toText ?? formatData;
69
+ function readText() {
70
+ return resolveToText(data);
53
71
  }
54
72
  const pending = {
55
73
  operation: name,
56
74
  ts,
57
75
  outcome: "pending",
58
- level: LEVELS.pending,
59
76
  data,
60
- message,
77
+ text: readText,
61
78
  timing() {
62
79
  return Number.NaN;
63
- },
64
- text: message
80
+ }
65
81
  };
66
82
  return Object.freeze(pending);
67
83
  }
@@ -88,38 +104,31 @@ function readRawErrorMessage(error) {
88
104
  }
89
105
 
90
106
  // src/model/createOperationFailure.ts
91
- function createOperationFailure(pending, error, options) {
107
+ function createOperationFailure(pending, error) {
92
108
  const finishedTs = Date.now();
93
109
  const rawError = readRawErrorMessage(error);
94
- const label = options?.label;
95
110
  function report() {
96
111
  return rawError;
97
112
  }
98
- function errorSerialized() {
99
- return label ? `${label}: ${rawError}` : rawError;
100
- }
101
113
  const failure = {
102
114
  operation: pending.operation,
103
115
  ts: pending.ts,
104
116
  finishedTs,
105
117
  outcome: "failure",
106
- level: LEVELS.failure,
107
118
  data: pending.data,
108
119
  error: rawError,
109
- message: report,
120
+ text: report,
110
121
  timing() {
111
122
  return finishedTs - pending.ts;
112
- },
113
- text: report,
114
- errorSerialized
123
+ }
115
124
  };
116
125
  return Object.freeze(failure);
117
126
  }
118
127
 
119
128
  // src/model/createOperationSuccess.ts
120
- function createOperationSuccess(pending, message) {
129
+ function createOperationSuccess(pending, text) {
121
130
  const finishedTs = Date.now();
122
- const givenText = message ?? pending.message();
131
+ const givenText = text ?? pending.text();
123
132
  function report() {
124
133
  return givenText;
125
134
  }
@@ -128,13 +137,11 @@ function createOperationSuccess(pending, message) {
128
137
  ts: pending.ts,
129
138
  finishedTs,
130
139
  outcome: "success",
131
- level: LEVELS.success,
132
140
  data: pending.data,
133
- message: report,
141
+ text: report,
134
142
  timing() {
135
143
  return finishedTs - pending.ts;
136
- },
137
- text: report
144
+ }
138
145
  };
139
146
  return Object.freeze(success);
140
147
  }
@@ -142,6 +149,7 @@ export {
142
149
  createGenericOperation,
143
150
  createOperationFailure,
144
151
  createOperationSuccess,
145
- createOperationsLog
152
+ createOperationsLog,
153
+ createPipeSeparatedFormatter
146
154
  };
147
155
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/log/private/isFinished.ts", "../src/log/createOperationsLog.ts", "../src/model/private/constants.ts", "../src/model/private/readInputUri.ts", "../src/model/createGenericOperation.ts", "../src/model/private/readRawErrorMessage.ts", "../src/model/createOperationFailure.ts", "../src/model/createOperationSuccess.ts"],
4
- "sourcesContent": ["import type { AnyFinishedOperation, LoggableOperation } from '../types.js';\n\nexport function isFinished(operation: LoggableOperation): operation is AnyFinishedOperation {\n\treturn operation.outcome !== 'pending';\n}\n", "import type { LoggerAPI } from '@art-lib/logger';\n\nimport { isFinished } from './private/isFinished.js';\nimport type { AnyFinishedOperation, OperationsLog, OperationsLogOptions } from './types.js';\n\nexport function createOperationsLog(\n\tlogger: LoggerAPI,\n\toptions?: OperationsLogOptions,\n): OperationsLog {\n\t// Reserved for a future iteration: accepted, deliberately not read here.\n\t// eslint-disable-next-line no-void\n\tvoid options;\n\n\tconst storedOperations: AnyFinishedOperation[] = [];\n\n\treturn {\n\t\tlog(operation): void {\n\t\t\tlogger.log(operation); // every operation is a message: pending and finished alike\n\n\t\t\tif (isFinished(operation)) {\n\t\t\t\tstoredOperations.push(operation); // finished operations only\n\t\t\t}\n\t\t},\n\t\tall(): AnyFinishedOperation[] {\n\t\t\treturn [...storedOperations]; // a copy \u2014 never leak the internal buffer\n\t\t},\n\t\tsince(timestamp: number): AnyFinishedOperation[] {\n\t\t\treturn storedOperations.filter(operation => operation.ts >= timestamp);\n\t\t},\n\t\tlatest(count: number): AnyFinishedOperation[] {\n\t\t\tif (count <= 0) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\treturn storedOperations.slice(Math.max(storedOperations.length - count, 0));\n\t\t},\n\t};\n}\n", "import type { MessageLevel } from '@art-lib/logger';\n\nimport type { OperationOutcome } from '../types.js';\n\nexport const LEVELS: Record<OperationOutcome, MessageLevel> = {\n\tpending: 'debug',\n\tsuccess: 'info',\n\tfailure: 'error',\n};\n", "export function readInputUri(data: unknown): string {\n\tif (typeof data !== 'object' || data === null || !('uri' in data)) {\n\t\treturn '';\n\t}\n\n\tconst { uri } = data as { uri: unknown };\n\n\treturn typeof uri === 'string' ? uri : '';\n}\n", "import { LEVELS } from './private/constants.js';\nimport { readInputUri } from './private/readInputUri.js';\nimport type { OperationPending } from './types.js';\n\nexport function createGenericOperation(name: string, data?: unknown): OperationPending {\n\tconst ts = Date.now();\n\n\tfunction message(): string {\n\t\treturn readInputUri(data);\n\t}\n\n\tconst pending: OperationPending = {\n\t\toperation: name,\n\t\tts,\n\t\toutcome: 'pending',\n\t\tlevel: LEVELS.pending,\n\t\tdata,\n\t\tmessage,\n\t\ttiming(): number {\n\t\t\treturn Number.NaN;\n\t\t},\n\t\ttext: message,\n\t};\n\n\treturn Object.freeze(pending);\n}\n", "export function readRawErrorMessage(error: unknown): string {\n\tif (typeof error === 'string') {\n\t\treturn error;\n\t}\n\n\tif (error === null || error === undefined) {\n\t\treturn '';\n\t}\n\n\tif (typeof error === 'object' && 'message' in error) {\n\t\tconst { message } = error as { message: unknown };\n\n\t\tif (typeof message === 'string') {\n\t\t\treturn message;\n\t\t}\n\t}\n\n\ttry {\n\t\treturn String(error);\n\t} catch {\n\t\treturn '';\n\t}\n}\n", "import { LEVELS } from './private/constants.js';\nimport { readRawErrorMessage } from './private/readRawErrorMessage.js';\nimport type { OperationFailure, OperationPending } from './types.js';\n\nexport function createOperationFailure(\n\tpending: OperationPending,\n\terror: unknown,\n\toptions?: { label?: string },\n): OperationFailure {\n\tconst finishedTs = Date.now();\n\tconst rawError = readRawErrorMessage(error);\n\tconst label = options?.label;\n\n\tfunction report(): string {\n\t\treturn rawError;\n\t}\n\n\tfunction errorSerialized(): string {\n\t\treturn label ? `${label}: ${rawError}` : rawError;\n\t}\n\n\tconst failure: OperationFailure = {\n\t\toperation: pending.operation,\n\t\tts: pending.ts,\n\t\tfinishedTs,\n\t\toutcome: 'failure',\n\t\tlevel: LEVELS.failure,\n\t\tdata: pending.data,\n\t\terror: rawError,\n\t\tmessage: report,\n\t\ttiming(): number {\n\t\t\treturn finishedTs - pending.ts;\n\t\t},\n\t\ttext: report,\n\t\terrorSerialized,\n\t};\n\n\treturn Object.freeze(failure);\n}\n", "import { LEVELS } from './private/constants.js';\nimport type { OperationPending, OperationSuccess } from './types.js';\n\nexport function createOperationSuccess(\n\tpending: OperationPending,\n\tmessage?: string,\n): OperationSuccess {\n\tconst finishedTs = Date.now();\n\tconst givenText = message ?? pending.message();\n\n\tfunction report(): string {\n\t\treturn givenText;\n\t}\n\n\tconst success: OperationSuccess = {\n\t\toperation: pending.operation,\n\t\tts: pending.ts,\n\t\tfinishedTs,\n\t\toutcome: 'success',\n\t\tlevel: LEVELS.success,\n\t\tdata: pending.data,\n\t\tmessage: report,\n\t\ttiming(): number {\n\t\t\treturn finishedTs - pending.ts;\n\t\t},\n\t\ttext: report,\n\t};\n\n\treturn Object.freeze(success);\n}\n"],
5
- "mappings": ";AAEO,SAAS,WAAW,WAAiE;AAC3F,SAAO,UAAU,YAAY;AAC9B;;;ACC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AA,EACP;AAEA,SAAO,OAAO,OAAO,OAAO;AAC7B;",
3
+ "sources": ["../src/log/private/constants.ts", "../src/log/private/isFinished.ts", "../src/log/createOperationsLog.ts", "../src/log/createPipeSeparatedFormatter.ts", "../src/model/private/formatData.ts", "../src/model/createGenericOperation.ts", "../src/model/private/readRawErrorMessage.ts", "../src/model/createOperationFailure.ts", "../src/model/createOperationSuccess.ts"],
4
+ "sourcesContent": ["import type { MessageLevel } from '@art-lib/logger';\n\nimport type { OperationOutcome } from '../../model/types.js';\n\nexport const OUTCOME_SYMBOLS: Record<OperationOutcome, string> = {\n\tpending: '\u23F3',\n\tsuccess: '\uD83D\uDFE2',\n\tfailure: '\uD83D\uDD34',\n};\n\nexport const OUTCOME_LEVELS: Record<OperationOutcome, MessageLevel> = {\n\tpending: 'debug',\n\tsuccess: 'info',\n\tfailure: 'error',\n};\n", "import type { OperationBase } from '../../model/types.js';\nimport type { AnyFinishedOperation } from '../types.js';\n\nexport function isFinished(operation: OperationBase): operation is AnyFinishedOperation {\n\treturn operation.outcome !== 'pending';\n}\n", "import type { LoggerAPI } from '@art-lib/logger';\n\nimport type { OperationBase } from '../model/index.js';\n\nimport { OUTCOME_LEVELS } from './private/constants.js';\nimport { isFinished } from './private/isFinished.js';\nimport type { AnyFinishedOperation, OperationsLog, OperationsLogOptions } from './types.js';\n\nexport function createOperationsLog<TOperation extends OperationBase = OperationBase>(\n\tlogger: LoggerAPI,\n\toptions: OperationsLogOptions<TOperation>,\n): OperationsLog<TOperation> {\n\tconst storedOperations: AnyFinishedOperation[] = [];\n\n\treturn {\n\t\tlog(operation): void {\n\t\t\tconst message = {\n\t\t\t\tlevel: OUTCOME_LEVELS[operation.outcome],\n\t\t\t\ttext: options.formatter(operation),\n\t\t\t\tts: operation.ts,\n\t\t\t};\n\n\t\t\tlogger.log(message);\n\n\t\t\tif (isFinished(operation)) {\n\t\t\t\tstoredOperations.push(operation);\n\t\t\t}\n\t\t},\n\t\tall(): AnyFinishedOperation[] {\n\t\t\treturn [...storedOperations];\n\t\t},\n\t\tsince(timestamp: number): AnyFinishedOperation[] {\n\t\t\treturn storedOperations.filter(operation => operation.ts >= timestamp);\n\t\t},\n\t\tlatest(count: number): AnyFinishedOperation[] {\n\t\t\tif (count <= 0) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\treturn storedOperations.slice(Math.max(storedOperations.length - count, 0));\n\t\t},\n\t};\n}\n", "import type { OperationBase } from '../model/index.js';\n\nimport { OUTCOME_SYMBOLS } from './private/constants.js';\nimport type { OperationFormatter } from './types.js';\n\nexport function createPipeSeparatedFormatter<TOperation extends OperationBase = OperationBase>(\n\tgetFields: (operation: TOperation) => readonly string[],\n): OperationFormatter<TOperation> {\n\treturn operation => {\n\t\tconst fields = [OUTCOME_SYMBOLS[operation.outcome], ...getFields(operation)];\n\t\tconst line = `${fields.join(' | ')} |`;\n\n\t\tif (operation.outcome === 'pending') {\n\t\t\treturn line;\n\t\t}\n\n\t\treturn `${line} (${operation.timing()}ms)`;\n\t};\n}\n", "export function formatData(data: unknown): string {\n\treturn data ? JSON.stringify(data) : '';\n}\n", "import { formatData } from './private/formatData.js';\nimport type { OperationPending } from './types.js';\n\nexport function createGenericOperation<N extends string, D = unknown>(\n\tname: N,\n\tdata?: D,\n\ttoText?: (data: D) => string,\n): OperationPending<D> & { operation: N } {\n\tconst ts = Date.now();\n\tconst resolveToText: (value: D) => string = toText ?? formatData;\n\n\tfunction readText(): string {\n\t\treturn resolveToText(data as D);\n\t}\n\n\tconst pending: OperationPending<D> & { operation: N } = {\n\t\toperation: name,\n\t\tts,\n\t\toutcome: 'pending',\n\t\tdata,\n\t\ttext: readText,\n\t\ttiming(): number {\n\t\t\treturn Number.NaN;\n\t\t},\n\t};\n\n\treturn Object.freeze(pending);\n}\n", "export function readRawErrorMessage(error: unknown): string {\n\tif (typeof error === 'string') {\n\t\treturn error;\n\t}\n\n\tif (error === null || error === undefined) {\n\t\treturn '';\n\t}\n\n\tif (typeof error === 'object' && 'message' in error) {\n\t\tconst { message } = error as { message: unknown };\n\n\t\tif (typeof message === 'string') {\n\t\t\treturn message;\n\t\t}\n\t}\n\n\ttry {\n\t\treturn String(error);\n\t} catch {\n\t\treturn '';\n\t}\n}\n", "import { readRawErrorMessage } from './private/readRawErrorMessage.js';\nimport type { OperationFailure, OperationPending } from './types.js';\n\nexport function createOperationFailure<D>(\n\tpending: OperationPending<D>,\n\terror: unknown,\n): OperationFailure<D> {\n\tconst finishedTs = Date.now();\n\tconst rawError = readRawErrorMessage(error);\n\n\tfunction report(): string {\n\t\treturn rawError;\n\t}\n\n\tconst failure: OperationFailure<D> = {\n\t\toperation: pending.operation,\n\t\tts: pending.ts,\n\t\tfinishedTs,\n\t\toutcome: 'failure',\n\t\tdata: pending.data,\n\t\terror: rawError,\n\t\ttext: report,\n\t\ttiming(): number {\n\t\t\treturn finishedTs - pending.ts;\n\t\t},\n\t};\n\n\treturn Object.freeze(failure);\n}\n", "import type { OperationPending, OperationSuccess } from './types.js';\n\nexport function createOperationSuccess<D>(\n\tpending: OperationPending<D>,\n\ttext?: string,\n): OperationSuccess<D> {\n\tconst finishedTs = Date.now();\n\tconst givenText = text ?? pending.text();\n\n\tfunction report(): string {\n\t\treturn givenText;\n\t}\n\n\tconst success: OperationSuccess<D> = {\n\t\toperation: pending.operation,\n\t\tts: pending.ts,\n\t\tfinishedTs,\n\t\toutcome: 'success',\n\t\tdata: pending.data,\n\t\ttext: report,\n\t\ttiming(): number {\n\t\t\treturn finishedTs - pending.ts;\n\t\t},\n\t};\n\n\treturn Object.freeze(success);\n}\n"],
5
+ "mappings": ";AAIO,IAAM,kBAAoD;AAAA,EAChE,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AACV;AAEO,IAAM,iBAAyD;AAAA,EACrE,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AACV;;;ACXO,SAAS,WAAW,WAA6D;AACvF,SAAO,UAAU,YAAY;AAC9B;;;ACGO,SAAS,oBACf,QACA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,OAAO,OAAO,OAAO;AAC7B;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
1
  import type { LoggerAPI } from '@art-lib/logger';
2
+ import type { OperationBase } from '../model/index.js';
2
3
  import type { OperationsLog, OperationsLogOptions } from './types.js';
3
- export declare function createOperationsLog(logger: LoggerAPI, options?: OperationsLogOptions): OperationsLog;
4
+ export declare function createOperationsLog<TOperation extends OperationBase = OperationBase>(logger: LoggerAPI, options: OperationsLogOptions<TOperation>): OperationsLog<TOperation>;
@@ -0,0 +1,3 @@
1
+ import type { OperationBase } from '../model/index.js';
2
+ import type { OperationFormatter } from './types.js';
3
+ export declare function createPipeSeparatedFormatter<TOperation extends OperationBase = OperationBase>(getFields: (operation: TOperation) => readonly string[]): OperationFormatter<TOperation>;
@@ -1,2 +1,3 @@
1
1
  export { createOperationsLog } from './createOperationsLog.js';
2
- export type { AnyFinishedOperation, LoggableOperation, OperationsLog, OperationsLogOptions, } from './types.js';
2
+ export { createPipeSeparatedFormatter } from './createPipeSeparatedFormatter.js';
3
+ export type { AnyFinishedOperation, OperationFormatter, OperationsLog, OperationsLogOptions, } from './types.js';
@@ -1,3 +1,15 @@
1
+ // src/log/private/constants.ts
2
+ var OUTCOME_SYMBOLS = {
3
+ pending: "\u23F3",
4
+ success: "\u{1F7E2}",
5
+ failure: "\u{1F534}"
6
+ };
7
+ var OUTCOME_LEVELS = {
8
+ pending: "debug",
9
+ success: "info",
10
+ failure: "error"
11
+ };
12
+
1
13
  // src/log/private/isFinished.ts
2
14
  function isFinished(operation) {
3
15
  return operation.outcome !== "pending";
@@ -5,11 +17,15 @@ function isFinished(operation) {
5
17
 
6
18
  // src/log/createOperationsLog.ts
7
19
  function createOperationsLog(logger, options) {
8
- void options;
9
20
  const storedOperations = [];
10
21
  return {
11
22
  log(operation) {
12
- logger.log(operation);
23
+ const message = {
24
+ level: OUTCOME_LEVELS[operation.outcome],
25
+ text: options.formatter(operation),
26
+ ts: operation.ts
27
+ };
28
+ logger.log(message);
13
29
  if (isFinished(operation)) {
14
30
  storedOperations.push(operation);
15
31
  }
@@ -28,7 +44,20 @@ function createOperationsLog(logger, options) {
28
44
  }
29
45
  };
30
46
  }
47
+
48
+ // src/log/createPipeSeparatedFormatter.ts
49
+ function createPipeSeparatedFormatter(getFields) {
50
+ return (operation) => {
51
+ const fields = [OUTCOME_SYMBOLS[operation.outcome], ...getFields(operation)];
52
+ const line = `${fields.join(" | ")} |`;
53
+ if (operation.outcome === "pending") {
54
+ return line;
55
+ }
56
+ return `${line} (${operation.timing()}ms)`;
57
+ };
58
+ }
31
59
  export {
32
- createOperationsLog
60
+ createOperationsLog,
61
+ createPipeSeparatedFormatter
33
62
  };
34
63
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/log/private/isFinished.ts", "../../src/log/createOperationsLog.ts"],
4
- "sourcesContent": ["import type { AnyFinishedOperation, LoggableOperation } from '../types.js';\n\nexport function isFinished(operation: LoggableOperation): operation is AnyFinishedOperation {\n\treturn operation.outcome !== 'pending';\n}\n", "import type { LoggerAPI } from '@art-lib/logger';\n\nimport { isFinished } from './private/isFinished.js';\nimport type { AnyFinishedOperation, OperationsLog, OperationsLogOptions } from './types.js';\n\nexport function createOperationsLog(\n\tlogger: LoggerAPI,\n\toptions?: OperationsLogOptions,\n): OperationsLog {\n\t// Reserved for a future iteration: accepted, deliberately not read here.\n\t// eslint-disable-next-line no-void\n\tvoid options;\n\n\tconst storedOperations: AnyFinishedOperation[] = [];\n\n\treturn {\n\t\tlog(operation): void {\n\t\t\tlogger.log(operation); // every operation is a message: pending and finished alike\n\n\t\t\tif (isFinished(operation)) {\n\t\t\t\tstoredOperations.push(operation); // finished operations only\n\t\t\t}\n\t\t},\n\t\tall(): AnyFinishedOperation[] {\n\t\t\treturn [...storedOperations]; // a copy \u2014 never leak the internal buffer\n\t\t},\n\t\tsince(timestamp: number): AnyFinishedOperation[] {\n\t\t\treturn storedOperations.filter(operation => operation.ts >= timestamp);\n\t\t},\n\t\tlatest(count: number): AnyFinishedOperation[] {\n\t\t\tif (count <= 0) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\treturn storedOperations.slice(Math.max(storedOperations.length - count, 0));\n\t\t},\n\t};\n}\n"],
5
- "mappings": ";AAEO,SAAS,WAAW,WAAiE;AAC3F,SAAO,UAAU,YAAY;AAC9B;;;ACCO,SAAS,oBACf,QACA,SACgB;AAGhB,OAAK;AAEL,QAAM,mBAA2C,CAAC;AAElD,SAAO;AAAA,IACN,IAAI,WAAiB;AACpB,aAAO,IAAI,SAAS;AAEpB,UAAI,WAAW,SAAS,GAAG;AAC1B,yBAAiB,KAAK,SAAS;AAAA,MAChC;AAAA,IACD;AAAA,IACA,MAA8B;AAC7B,aAAO,CAAC,GAAG,gBAAgB;AAAA,IAC5B;AAAA,IACA,MAAM,WAA2C;AAChD,aAAO,iBAAiB,OAAO,eAAa,UAAU,MAAM,SAAS;AAAA,IACtE;AAAA,IACA,OAAO,OAAuC;AAC7C,UAAI,SAAS,GAAG;AACf,eAAO,CAAC;AAAA,MACT;AAEA,aAAO,iBAAiB,MAAM,KAAK,IAAI,iBAAiB,SAAS,OAAO,CAAC,CAAC;AAAA,IAC3E;AAAA,EACD;AACD;",
3
+ "sources": ["../../src/log/private/constants.ts", "../../src/log/private/isFinished.ts", "../../src/log/createOperationsLog.ts", "../../src/log/createPipeSeparatedFormatter.ts"],
4
+ "sourcesContent": ["import type { MessageLevel } from '@art-lib/logger';\n\nimport type { OperationOutcome } from '../../model/types.js';\n\nexport const OUTCOME_SYMBOLS: Record<OperationOutcome, string> = {\n\tpending: '\u23F3',\n\tsuccess: '\uD83D\uDFE2',\n\tfailure: '\uD83D\uDD34',\n};\n\nexport const OUTCOME_LEVELS: Record<OperationOutcome, MessageLevel> = {\n\tpending: 'debug',\n\tsuccess: 'info',\n\tfailure: 'error',\n};\n", "import type { OperationBase } from '../../model/types.js';\nimport type { AnyFinishedOperation } from '../types.js';\n\nexport function isFinished(operation: OperationBase): operation is AnyFinishedOperation {\n\treturn operation.outcome !== 'pending';\n}\n", "import type { LoggerAPI } from '@art-lib/logger';\n\nimport type { OperationBase } from '../model/index.js';\n\nimport { OUTCOME_LEVELS } from './private/constants.js';\nimport { isFinished } from './private/isFinished.js';\nimport type { AnyFinishedOperation, OperationsLog, OperationsLogOptions } from './types.js';\n\nexport function createOperationsLog<TOperation extends OperationBase = OperationBase>(\n\tlogger: LoggerAPI,\n\toptions: OperationsLogOptions<TOperation>,\n): OperationsLog<TOperation> {\n\tconst storedOperations: AnyFinishedOperation[] = [];\n\n\treturn {\n\t\tlog(operation): void {\n\t\t\tconst message = {\n\t\t\t\tlevel: OUTCOME_LEVELS[operation.outcome],\n\t\t\t\ttext: options.formatter(operation),\n\t\t\t\tts: operation.ts,\n\t\t\t};\n\n\t\t\tlogger.log(message);\n\n\t\t\tif (isFinished(operation)) {\n\t\t\t\tstoredOperations.push(operation);\n\t\t\t}\n\t\t},\n\t\tall(): AnyFinishedOperation[] {\n\t\t\treturn [...storedOperations];\n\t\t},\n\t\tsince(timestamp: number): AnyFinishedOperation[] {\n\t\t\treturn storedOperations.filter(operation => operation.ts >= timestamp);\n\t\t},\n\t\tlatest(count: number): AnyFinishedOperation[] {\n\t\t\tif (count <= 0) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\treturn storedOperations.slice(Math.max(storedOperations.length - count, 0));\n\t\t},\n\t};\n}\n", "import type { OperationBase } from '../model/index.js';\n\nimport { OUTCOME_SYMBOLS } from './private/constants.js';\nimport type { OperationFormatter } from './types.js';\n\nexport function createPipeSeparatedFormatter<TOperation extends OperationBase = OperationBase>(\n\tgetFields: (operation: TOperation) => readonly string[],\n): OperationFormatter<TOperation> {\n\treturn operation => {\n\t\tconst fields = [OUTCOME_SYMBOLS[operation.outcome], ...getFields(operation)];\n\t\tconst line = `${fields.join(' | ')} |`;\n\n\t\tif (operation.outcome === 'pending') {\n\t\t\treturn line;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
  "names": []
7
7
  }
@@ -0,0 +1,4 @@
1
+ import type { MessageLevel } from '@art-lib/logger';
2
+ import type { OperationOutcome } from '../../model/types.js';
3
+ export declare const OUTCOME_SYMBOLS: Record<OperationOutcome, string>;
4
+ export declare const OUTCOME_LEVELS: Record<OperationOutcome, MessageLevel>;
@@ -1,2 +1,3 @@
1
- import type { AnyFinishedOperation, LoggableOperation } from '../types.js';
2
- export declare function isFinished(operation: LoggableOperation): operation is AnyFinishedOperation;
1
+ import type { OperationBase } from '../../model/types.js';
2
+ import type { AnyFinishedOperation } from '../types.js';
3
+ export declare function isFinished(operation: OperationBase): operation is AnyFinishedOperation;
@@ -1,18 +1,12 @@
1
- import type { Message } from '@art-lib/logger';
2
- import type { OperationFailure, OperationSuccess } from '../model/index.js';
1
+ import type { OperationBase, OperationFailure, OperationSuccess } from '../model/index.js';
3
2
  export type AnyFinishedOperation = OperationSuccess | OperationFailure;
4
- /**
5
- * Any operation with an `outcome` that also satisfies `Message` of `@art-lib/logger`.
6
- * Pending operations keep forwarding to the logger; finished-only storage is
7
- * enforced at runtime by `createOperationsLog`.
8
- */
9
- export type LoggableOperation = Message & {
10
- outcome: string;
11
- };
12
- export type OperationsLog = {
13
- log(operation: LoggableOperation): void;
3
+ export type OperationFormatter<TOperation extends OperationBase = OperationBase> = (operation: TOperation) => string;
4
+ export type OperationsLog<TOperation extends OperationBase = OperationBase> = {
5
+ log(operation: TOperation): void;
14
6
  all(): AnyFinishedOperation[];
15
7
  since(timestamp: number): AnyFinishedOperation[];
16
8
  latest(count: number): AnyFinishedOperation[];
17
9
  };
18
- export type OperationsLogOptions = unknown;
10
+ export type OperationsLogOptions<TOperation extends OperationBase = OperationBase> = {
11
+ formatter: OperationFormatter<TOperation>;
12
+ };
@@ -1,2 +1,4 @@
1
1
  import type { OperationPending } from './types.js';
2
- export declare function createGenericOperation(name: string, data?: unknown): OperationPending;
2
+ export declare function createGenericOperation<N extends string, D = unknown>(name: N, data?: D, toText?: (data: D) => string): OperationPending<D> & {
3
+ operation: N;
4
+ };
@@ -1,4 +1,2 @@
1
1
  import type { OperationFailure, OperationPending } from './types.js';
2
- export declare function createOperationFailure(pending: OperationPending, error: unknown, options?: {
3
- label?: string;
4
- }): OperationFailure;
2
+ export declare function createOperationFailure<D>(pending: OperationPending<D>, error: unknown): OperationFailure<D>;
@@ -1,2 +1,2 @@
1
1
  import type { OperationPending, OperationSuccess } from './types.js';
2
- export declare function createOperationSuccess(pending: OperationPending, message?: string): OperationSuccess;
2
+ export declare function createOperationSuccess<D>(pending: OperationPending<D>, text?: string): OperationSuccess<D>;
@@ -1,4 +1,4 @@
1
- export type { OperationBase, OperationFailure, OperationOutcome, OperationPending, OperationSuccess, } from './types.js';
1
+ export type { OperationBase, OperationOutcome, OperationFailure, OperationPending, OperationSuccess, } from './types.js';
2
2
  export { createGenericOperation } from './createGenericOperation.js';
3
3
  export { createOperationFailure } from './createOperationFailure.js';
4
4
  export { createOperationSuccess } from './createOperationSuccess.js';
@@ -1,36 +1,24 @@
1
- // src/model/private/constants.ts
2
- var LEVELS = {
3
- pending: "debug",
4
- success: "info",
5
- failure: "error"
6
- };
7
-
8
- // src/model/private/readInputUri.ts
9
- function readInputUri(data) {
10
- if (typeof data !== "object" || data === null || !("uri" in data)) {
11
- return "";
12
- }
13
- const { uri } = data;
14
- return typeof uri === "string" ? uri : "";
1
+ // src/model/private/formatData.ts
2
+ function formatData(data) {
3
+ return data ? JSON.stringify(data) : "";
15
4
  }
16
5
 
17
6
  // src/model/createGenericOperation.ts
18
- function createGenericOperation(name, data) {
7
+ function createGenericOperation(name, data, toText) {
19
8
  const ts = Date.now();
20
- function message() {
21
- return readInputUri(data);
9
+ const resolveToText = toText ?? formatData;
10
+ function readText() {
11
+ return resolveToText(data);
22
12
  }
23
13
  const pending = {
24
14
  operation: name,
25
15
  ts,
26
16
  outcome: "pending",
27
- level: LEVELS.pending,
28
17
  data,
29
- message,
18
+ text: readText,
30
19
  timing() {
31
20
  return Number.NaN;
32
- },
33
- text: message
21
+ }
34
22
  };
35
23
  return Object.freeze(pending);
36
24
  }
@@ -57,38 +45,31 @@ function readRawErrorMessage(error) {
57
45
  }
58
46
 
59
47
  // src/model/createOperationFailure.ts
60
- function createOperationFailure(pending, error, options) {
48
+ function createOperationFailure(pending, error) {
61
49
  const finishedTs = Date.now();
62
50
  const rawError = readRawErrorMessage(error);
63
- const label = options?.label;
64
51
  function report() {
65
52
  return rawError;
66
53
  }
67
- function errorSerialized() {
68
- return label ? `${label}: ${rawError}` : rawError;
69
- }
70
54
  const failure = {
71
55
  operation: pending.operation,
72
56
  ts: pending.ts,
73
57
  finishedTs,
74
58
  outcome: "failure",
75
- level: LEVELS.failure,
76
59
  data: pending.data,
77
60
  error: rawError,
78
- message: report,
61
+ text: report,
79
62
  timing() {
80
63
  return finishedTs - pending.ts;
81
- },
82
- text: report,
83
- errorSerialized
64
+ }
84
65
  };
85
66
  return Object.freeze(failure);
86
67
  }
87
68
 
88
69
  // src/model/createOperationSuccess.ts
89
- function createOperationSuccess(pending, message) {
70
+ function createOperationSuccess(pending, text) {
90
71
  const finishedTs = Date.now();
91
- const givenText = message ?? pending.message();
72
+ const givenText = text ?? pending.text();
92
73
  function report() {
93
74
  return givenText;
94
75
  }
@@ -97,13 +78,11 @@ function createOperationSuccess(pending, message) {
97
78
  ts: pending.ts,
98
79
  finishedTs,
99
80
  outcome: "success",
100
- level: LEVELS.success,
101
81
  data: pending.data,
102
- message: report,
82
+ text: report,
103
83
  timing() {
104
84
  return finishedTs - pending.ts;
105
- },
106
- text: report
85
+ }
107
86
  };
108
87
  return Object.freeze(success);
109
88
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/model/private/constants.ts", "../../src/model/private/readInputUri.ts", "../../src/model/createGenericOperation.ts", "../../src/model/private/readRawErrorMessage.ts", "../../src/model/createOperationFailure.ts", "../../src/model/createOperationSuccess.ts"],
4
- "sourcesContent": ["import type { MessageLevel } from '@art-lib/logger';\n\nimport type { OperationOutcome } from '../types.js';\n\nexport const LEVELS: Record<OperationOutcome, MessageLevel> = {\n\tpending: 'debug',\n\tsuccess: 'info',\n\tfailure: 'error',\n};\n", "export function readInputUri(data: unknown): string {\n\tif (typeof data !== 'object' || data === null || !('uri' in data)) {\n\t\treturn '';\n\t}\n\n\tconst { uri } = data as { uri: unknown };\n\n\treturn typeof uri === 'string' ? uri : '';\n}\n", "import { LEVELS } from './private/constants.js';\nimport { readInputUri } from './private/readInputUri.js';\nimport type { OperationPending } from './types.js';\n\nexport function createGenericOperation(name: string, data?: unknown): OperationPending {\n\tconst ts = Date.now();\n\n\tfunction message(): string {\n\t\treturn readInputUri(data);\n\t}\n\n\tconst pending: OperationPending = {\n\t\toperation: name,\n\t\tts,\n\t\toutcome: 'pending',\n\t\tlevel: LEVELS.pending,\n\t\tdata,\n\t\tmessage,\n\t\ttiming(): number {\n\t\t\treturn Number.NaN;\n\t\t},\n\t\ttext: message,\n\t};\n\n\treturn Object.freeze(pending);\n}\n", "export function readRawErrorMessage(error: unknown): string {\n\tif (typeof error === 'string') {\n\t\treturn error;\n\t}\n\n\tif (error === null || error === undefined) {\n\t\treturn '';\n\t}\n\n\tif (typeof error === 'object' && 'message' in error) {\n\t\tconst { message } = error as { message: unknown };\n\n\t\tif (typeof message === 'string') {\n\t\t\treturn message;\n\t\t}\n\t}\n\n\ttry {\n\t\treturn String(error);\n\t} catch {\n\t\treturn '';\n\t}\n}\n", "import { LEVELS } from './private/constants.js';\nimport { readRawErrorMessage } from './private/readRawErrorMessage.js';\nimport type { OperationFailure, OperationPending } from './types.js';\n\nexport function createOperationFailure(\n\tpending: OperationPending,\n\terror: unknown,\n\toptions?: { label?: string },\n): OperationFailure {\n\tconst finishedTs = Date.now();\n\tconst rawError = readRawErrorMessage(error);\n\tconst label = options?.label;\n\n\tfunction report(): string {\n\t\treturn rawError;\n\t}\n\n\tfunction errorSerialized(): string {\n\t\treturn label ? `${label}: ${rawError}` : rawError;\n\t}\n\n\tconst failure: OperationFailure = {\n\t\toperation: pending.operation,\n\t\tts: pending.ts,\n\t\tfinishedTs,\n\t\toutcome: 'failure',\n\t\tlevel: LEVELS.failure,\n\t\tdata: pending.data,\n\t\terror: rawError,\n\t\tmessage: report,\n\t\ttiming(): number {\n\t\t\treturn finishedTs - pending.ts;\n\t\t},\n\t\ttext: report,\n\t\terrorSerialized,\n\t};\n\n\treturn Object.freeze(failure);\n}\n", "import { LEVELS } from './private/constants.js';\nimport type { OperationPending, OperationSuccess } from './types.js';\n\nexport function createOperationSuccess(\n\tpending: OperationPending,\n\tmessage?: string,\n): OperationSuccess {\n\tconst finishedTs = Date.now();\n\tconst givenText = message ?? pending.message();\n\n\tfunction report(): string {\n\t\treturn givenText;\n\t}\n\n\tconst success: OperationSuccess = {\n\t\toperation: pending.operation,\n\t\tts: pending.ts,\n\t\tfinishedTs,\n\t\toutcome: 'success',\n\t\tlevel: LEVELS.success,\n\t\tdata: pending.data,\n\t\tmessage: report,\n\t\ttiming(): number {\n\t\t\treturn finishedTs - pending.ts;\n\t\t},\n\t\ttext: report,\n\t};\n\n\treturn Object.freeze(success);\n}\n"],
5
- "mappings": ";AAIO,IAAM,SAAiD;AAAA,EAC7D,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AACV;;;ACRO,SAAS,aAAa,MAAuB;AACnD,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,SAAS,OAAO;AAClE,WAAO;AAAA,EACR;AAEA,QAAM,EAAE,IAAI,IAAI;AAEhB,SAAO,OAAO,QAAQ,WAAW,MAAM;AACxC;;;ACJO,SAAS,uBAAuB,MAAc,MAAkC;AACtF,QAAM,KAAK,KAAK,IAAI;AAEpB,WAAS,UAAkB;AAC1B,WAAO,aAAa,IAAI;AAAA,EACzB;AAEA,QAAM,UAA4B;AAAA,IACjC,WAAW;AAAA,IACX;AAAA,IACA,SAAS;AAAA,IACT,OAAO,OAAO;AAAA,IACd;AAAA,IACA;AAAA,IACA,S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B,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,IACT,OAAO,OAAO;AAAA,IACd,MAAM,QAAQ;AAAA,IACd,SAAS;AAAA,IACT,SAAiB;AAChB,aAAO,aAAa,QAAQ;AAAA,IAC7B;AAAA,IACA,MAAM;AAAA,EACP;AAEA,SAAO,OAAO,OAAO,OAAO;AAC7B;",
3
+ "sources": ["../../src/model/private/formatData.ts", "../../src/model/createGenericOperation.ts", "../../src/model/private/readRawErrorMessage.ts", "../../src/model/createOperationFailure.ts", "../../src/model/createOperationSuccess.ts"],
4
+ "sourcesContent": ["export function formatData(data: unknown): string {\n\treturn data ? JSON.stringify(data) : '';\n}\n", "import { formatData } from './private/formatData.js';\nimport type { OperationPending } from './types.js';\n\nexport function createGenericOperation<N extends string, D = unknown>(\n\tname: N,\n\tdata?: D,\n\ttoText?: (data: D) => string,\n): OperationPending<D> & { operation: N } {\n\tconst ts = Date.now();\n\tconst resolveToText: (value: D) => string = toText ?? formatData;\n\n\tfunction readText(): string {\n\t\treturn resolveToText(data as D);\n\t}\n\n\tconst pending: OperationPending<D> & { operation: N } = {\n\t\toperation: name,\n\t\tts,\n\t\toutcome: 'pending',\n\t\tdata,\n\t\ttext: readText,\n\t\ttiming(): number {\n\t\t\treturn Number.NaN;\n\t\t},\n\t};\n\n\treturn Object.freeze(pending);\n}\n", "export function readRawErrorMessage(error: unknown): string {\n\tif (typeof error === 'string') {\n\t\treturn error;\n\t}\n\n\tif (error === null || error === undefined) {\n\t\treturn '';\n\t}\n\n\tif (typeof error === 'object' && 'message' in error) {\n\t\tconst { message } = error as { message: unknown };\n\n\t\tif (typeof message === 'string') {\n\t\t\treturn message;\n\t\t}\n\t}\n\n\ttry {\n\t\treturn String(error);\n\t} catch {\n\t\treturn '';\n\t}\n}\n", "import { readRawErrorMessage } from './private/readRawErrorMessage.js';\nimport type { OperationFailure, OperationPending } from './types.js';\n\nexport function createOperationFailure<D>(\n\tpending: OperationPending<D>,\n\terror: unknown,\n): OperationFailure<D> {\n\tconst finishedTs = Date.now();\n\tconst rawError = readRawErrorMessage(error);\n\n\tfunction report(): string {\n\t\treturn rawError;\n\t}\n\n\tconst failure: OperationFailure<D> = {\n\t\toperation: pending.operation,\n\t\tts: pending.ts,\n\t\tfinishedTs,\n\t\toutcome: 'failure',\n\t\tdata: pending.data,\n\t\terror: rawError,\n\t\ttext: report,\n\t\ttiming(): number {\n\t\t\treturn finishedTs - pending.ts;\n\t\t},\n\t};\n\n\treturn Object.freeze(failure);\n}\n", "import type { OperationPending, OperationSuccess } from './types.js';\n\nexport function createOperationSuccess<D>(\n\tpending: OperationPending<D>,\n\ttext?: string,\n): OperationSuccess<D> {\n\tconst finishedTs = Date.now();\n\tconst givenText = text ?? pending.text();\n\n\tfunction report(): string {\n\t\treturn givenText;\n\t}\n\n\tconst success: OperationSuccess<D> = {\n\t\toperation: pending.operation,\n\t\tts: pending.ts,\n\t\tfinishedTs,\n\t\toutcome: 'success',\n\t\tdata: pending.data,\n\t\ttext: report,\n\t\ttiming(): number {\n\t\t\treturn finishedTs - pending.ts;\n\t\t},\n\t};\n\n\treturn Object.freeze(success);\n}\n"],
5
+ "mappings": ";AAAO,SAAS,WAAW,MAAuB;AACjD,SAAO,OAAO,KAAK,UAAU,IAAI,IAAI;AACtC;;;ACCO,SAAS,uBACf,MACA,MACA,QACyC;AACzC,QAAM,KAAK,KAAK,IAAI;AACpB,QAAM,gBAAsC,UAAU;AAEtD,WAAS,WAAmB;AAC3B,WAAO,cAAc,IAAS;AAAA,EAC/B;AAEA,QAAM,UAAkD;AAAA,IACvD,WAAW;AAAA,IACX;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA,MAAM;AAAA,IACN,SAAiB;AAChB,aAAO,OAAO;AAAA,IACf;AAAA,EACD;AAEA,SAAO,OAAO,OAAO,OAAO;AAC7B;;;AC3BO,SAAS,oBAAoB,OAAwB;AAC3D,MAAI,OAAO,UAAU,UAAU;AAC9B,WAAO;AAAA,EACR;AAEA,MAAI,UAAU,QAAQ,UAAU,QAAW;AAC1C,WAAO;AAAA,EACR;AAEA,MAAI,OAAO,UAAU,YAAY,aAAa,OAAO;AACpD,UAAM,EAAE,QAAQ,IAAI;AAEpB,QAAI,OAAO,YAAY,UAAU;AAChC,aAAO;AAAA,IACR;AAAA,EACD;AAEA,MAAI;AACH,WAAO,OAAO,KAAK;AAAA,EACpB,QAAQ;AACP,WAAO;AAAA,EACR;AACD;;;ACnBO,SAAS,uBACf,SACA,OACsB;AACtB,QAAM,aAAa,KAAK,IAAI;AAC5B,QAAM,WAAW,oBAAoB,KAAK;AAE1C,WAAS,SAAiB;AACzB,WAAO;AAAA,EACR;AAEA,QAAM,UAA+B;AAAA,IACpC,WAAW,QAAQ;AAAA,IACnB,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,IACT,MAAM,QAAQ;AAAA,IACd,OAAO;AAAA,IACP,MAAM;AAAA,IACN,SAAiB;AAChB,aAAO,aAAa,QAAQ;AAAA,IAC7B;AAAA,EACD;AAEA,SAAO,OAAO,OAAO,OAAO;AAC7B;;;AC1BO,SAAS,uBACf,SACA,MACsB;AACtB,QAAM,aAAa,KAAK,IAAI;AAC5B,QAAM,YAAY,QAAQ,QAAQ,KAAK;AAEvC,WAAS,SAAiB;AACzB,WAAO;AAAA,EACR;AAEA,QAAM,UAA+B;AAAA,IACpC,WAAW,QAAQ;AAAA,IACnB,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,IACT,MAAM,QAAQ;AAAA,IACd,MAAM;AAAA,IACN,SAAiB;AAChB,aAAO,aAAa,QAAQ;AAAA,IAC7B;AAAA,EACD;AAEA,SAAO,OAAO,OAAO,OAAO;AAC7B;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1 @@
1
+ export declare function formatData(data: unknown): string;
@@ -1,26 +1,20 @@
1
- import type { MessageLevel } from '@art-lib/logger';
2
1
  export type OperationOutcome = 'pending' | 'success' | 'failure';
3
- export type OperationBase = {
2
+ export type OperationBase<D = unknown> = {
4
3
  readonly operation: string;
5
4
  readonly ts: number;
6
5
  readonly finishedTs?: number;
7
6
  readonly outcome: OperationOutcome;
8
- message(): string;
9
- timing(): number;
10
- readonly level: MessageLevel;
7
+ readonly data?: D;
11
8
  text(): string;
9
+ timing(): number;
12
10
  };
13
- export type OperationPending<D = unknown> = OperationBase & {
11
+ export type OperationPending<D = unknown> = OperationBase<D> & {
14
12
  readonly outcome: 'pending';
15
- readonly data?: D;
16
13
  };
17
- export type OperationSuccess<D = unknown> = OperationBase & {
14
+ export type OperationSuccess<D = unknown> = OperationBase<D> & {
18
15
  readonly outcome: 'success';
19
- readonly data?: D;
20
16
  };
21
- export type OperationFailure<D = unknown> = OperationBase & {
17
+ export type OperationFailure<D = unknown> = OperationBase<D> & {
22
18
  readonly outcome: 'failure';
23
- readonly data?: D;
24
19
  readonly error: string;
25
- errorSerialized(): string;
26
20
  };
@@ -0,0 +1,3 @@
1
+ import type { OperationsLog } from '../../../log/types.js';
2
+ /** @mocks the operations log API */
3
+ export declare function createOperationsLogMock(): OperationsLog;
@@ -0,0 +1,3 @@
1
+ import type { OperationFailure } from '../../../model/types.js';
2
+ import type { OperationFixtureData } from './types.js';
3
+ export declare function makeFailureOperationFixture(ts?: number, finishedTs?: number): OperationFailure<OperationFixtureData>;
@@ -0,0 +1,3 @@
1
+ import type { OperationPending } from '../../../model/types.js';
2
+ import type { OperationFixtureData } from './types.js';
3
+ export declare function makePendingOperationFixture(ts?: number): OperationPending<OperationFixtureData>;
@@ -0,0 +1,3 @@
1
+ import type { OperationSuccess } from '../../../model/types.js';
2
+ import type { OperationFixtureData } from './types.js';
3
+ export declare function makeSuccessOperationFixture(ts?: number, finishedTs?: number): OperationSuccess<OperationFixtureData>;
@@ -0,0 +1,3 @@
1
+ export type OperationFixtureData = {
2
+ branch: string;
3
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@art-lib/operations",
3
- "version": "0.0.1",
4
- "description": "Operation outcome types and factories, and an append-only operations log that forwards every operation to the logger.",
3
+ "version": "0.0.3",
4
+ "description": "Shared operation model and formatted operations log for CLI workflows.",
5
5
  "keywords": [
6
6
  "library",
7
7
  "operations",
@@ -23,6 +23,7 @@
23
23
  },
24
24
  "files": [
25
25
  "dist",
26
+ "src/test/helpers",
26
27
  "README.md",
27
28
  "LICENSE-MIT",
28
29
  "CHANGELOG.md"
@@ -37,14 +38,7 @@
37
38
  "types": "./dist/index.d.ts",
38
39
  "import": "./dist/index.mjs"
39
40
  },
40
- "./model": {
41
- "types": "./dist/model/index.d.ts",
42
- "import": "./dist/model/index.mjs"
43
- },
44
- "./log": {
45
- "types": "./dist/log/index.d.ts",
46
- "import": "./dist/log/index.mjs"
47
- }
41
+ "./test/helpers/*": "./src/test/helpers/*.ts"
48
42
  },
49
43
  "scripts": {
50
44
  "dev": "esbuild-cli-watch",
@@ -58,7 +52,9 @@
58
52
  "ci": "npm run lint && npm run build && npm run test:ci"
59
53
  },
60
54
  "dependencies": {
61
- "@art-lib/logger": "0.0.1"
55
+ "@art-lib/logger": "0.0.4"
62
56
  },
63
- "devDependencies": {}
57
+ "devDependencies": {
58
+ "vitest": "5.0.5"
59
+ }
64
60
  }
@@ -0,0 +1,13 @@
1
+ import { vi } from 'vitest';
2
+
3
+ import type { OperationsLog } from '../../../log/types.js';
4
+
5
+ /** @mocks the operations log API */
6
+ export function createOperationsLogMock(): OperationsLog {
7
+ return {
8
+ log: vi.fn(),
9
+ all: vi.fn(),
10
+ since: vi.fn(),
11
+ latest: vi.fn(),
12
+ };
13
+ }
@@ -0,0 +1,19 @@
1
+ import type { OperationFailure } from '../../../model/types.js';
2
+
3
+ import type { OperationFixtureData } from './types.js';
4
+
5
+ export function makeFailureOperationFixture(
6
+ ts = 1_000,
7
+ finishedTs = 1_075,
8
+ ): OperationFailure<OperationFixtureData> {
9
+ return {
10
+ operation: 'pull',
11
+ ts,
12
+ finishedTs,
13
+ outcome: 'failure',
14
+ data: { branch: 'main' },
15
+ error: 'remote unavailable',
16
+ text: () => 'remote unavailable',
17
+ timing: () => finishedTs - ts,
18
+ };
19
+ }
@@ -0,0 +1,14 @@
1
+ import type { OperationPending } from '../../../model/types.js';
2
+
3
+ import type { OperationFixtureData } from './types.js';
4
+
5
+ export function makePendingOperationFixture(ts = 1_000): OperationPending<OperationFixtureData> {
6
+ return {
7
+ operation: 'pull',
8
+ ts,
9
+ outcome: 'pending',
10
+ data: { branch: 'main' },
11
+ text: () => 'from origin/main',
12
+ timing: () => Number.NaN,
13
+ };
14
+ }
@@ -0,0 +1,18 @@
1
+ import type { OperationSuccess } from '../../../model/types.js';
2
+
3
+ import type { OperationFixtureData } from './types.js';
4
+
5
+ export function makeSuccessOperationFixture(
6
+ ts = 1_000,
7
+ finishedTs = 1_050,
8
+ ): OperationSuccess<OperationFixtureData> {
9
+ return {
10
+ operation: 'pull',
11
+ ts,
12
+ finishedTs,
13
+ outcome: 'success',
14
+ data: { branch: 'main' },
15
+ text: () => 'from origin/main',
16
+ timing: () => finishedTs - ts,
17
+ };
18
+ }
@@ -0,0 +1,13 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { makeFailureOperationFixture } from './makeFailureOperationFixture.js';
4
+ import { makePendingOperationFixture } from './makePendingOperationFixture.js';
5
+ import { makeSuccessOperationFixture } from './makeSuccessOperationFixture.js';
6
+
7
+ describe('operation fixtures', () => {
8
+ it('WHEN fixture timestamps are supplied, timing reflects the operation outcome', () => {
9
+ expect(makePendingOperationFixture(1_000).timing()).toBeNaN();
10
+ expect(makeSuccessOperationFixture(1_000, 1_050).timing()).toBe(50);
11
+ expect(makeFailureOperationFixture(1_000, 1_075).timing()).toBe(75);
12
+ });
13
+ });
@@ -0,0 +1,3 @@
1
+ export type OperationFixtureData = {
2
+ branch: string;
3
+ };
@@ -1,3 +0,0 @@
1
- import type { MessageLevel } from '@art-lib/logger';
2
- import type { OperationOutcome } from '../types.js';
3
- export declare const LEVELS: Record<OperationOutcome, MessageLevel>;
@@ -1 +0,0 @@
1
- export declare function readInputUri(data: unknown): string;
@@ -1,3 +0,0 @@
1
- import type { LoggerMock } from './types.js';
2
- /** @mocks LoggerAPI */
3
- export declare function createLoggerMock(): LoggerMock;
@@ -1,5 +0,0 @@
1
- import type { LoggerAPI, Message } from '@art-lib/logger';
2
- export type LoggerMock = {
3
- logger: LoggerAPI;
4
- messages: Message[];
5
- };