@art-lib/operations 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.0.1
3
+ ## 0.0.2
4
4
 
5
5
  ### Added
6
+
7
+ - Extend the three model factories with `<D>` generics and an optional `message` hook on `createGenericOperation`.
package/README.md CHANGED
@@ -6,9 +6,9 @@ This package is part of the [Art Lib toolkit](../../README.md).
6
6
 
7
7
  ## Design
8
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.
9
+ The package defines the operation model: one unit of work in a command invocation, carrying a pending, success, or failure outcome. Factories build the pending operation and then derive the finished one from it. The package also provides a thin, append-only operations log. Created alongside a logger, it forwards every operation to that logger and keeps the finished ones queryable.
10
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.
11
+ Every operation doubles as a log message for [`@art-lib/logger`](../logger/README.md). It carries a level derived from its outcome — pending logs as debug, success as info, failure as error — so the logger consumes operations directly without ever learning what they are. That logger is the package's only dependency.
12
12
 
13
13
  See also:
14
14
 
@@ -76,16 +76,16 @@ operations.latest(5); // the last five finished operations
76
76
 
77
77
  ### Options
78
78
 
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 |
79
+ | Function | Arguments | Returns | Notes |
80
+ | -------------------------------------------------- | ---------------------------------------------------- | ------------------ | ------------------------------------------------------------------- |
81
+ | `createGenericOperation(name, data?, text?)` | operation name, optional payload, optional text | `OperationPending` | frozen; reports the payload as JSON by default; `timing()` is `NaN` |
82
+ | `createOperationSuccess(pending, text?)` | a pending operation, optional success text | `OperationSuccess` | falls back to the pending's own text |
83
+ | `createOperationFailure(pending, error, options?)` | a pending operation, any error-shaped value, options | `OperationFailure` | the options carry a label that prefixes `errorSerialized()` |
84
+ | `createOperationsLog(logger, options?)` | a logger, reserved options | `OperationsLog` | forwards every operation; stores finished operations only |
85
85
 
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.
86
+ - **Payload** — carried on the operation untouched, from pending through to success or failure. By default the payload is serialised to JSON as the operation's text, until a success text overrides it.
87
+ - **Options** — the log accepts a second argument and deliberately ignores it; it is reserved for a future iteration.
88
+ - **Operations log** — offers `log`, `all`, `since` and `latest`. The query methods return copies, never the internal buffer.
89
89
 
90
90
  ## Development
91
91
 
package/dist/index.mjs CHANGED
@@ -36,20 +36,17 @@ var LEVELS = {
36
36
  failure: "error"
37
37
  };
38
38
 
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 : "";
39
+ // src/model/private/formatData.ts
40
+ function formatData(data) {
41
+ return data ? JSON.stringify(data) : "";
46
42
  }
47
43
 
48
44
  // src/model/createGenericOperation.ts
49
- function createGenericOperation(name, data) {
45
+ function createGenericOperation(name, data, toText) {
50
46
  const ts = Date.now();
51
- function message() {
52
- return readInputUri(data);
47
+ const resolveToText = toText ?? formatData;
48
+ function readText() {
49
+ return resolveToText(data);
53
50
  }
54
51
  const pending = {
55
52
  operation: name,
@@ -57,11 +54,10 @@ function createGenericOperation(name, data) {
57
54
  outcome: "pending",
58
55
  level: LEVELS.pending,
59
56
  data,
60
- message,
57
+ text: readText,
61
58
  timing() {
62
59
  return Number.NaN;
63
- },
64
- text: message
60
+ }
65
61
  };
66
62
  return Object.freeze(pending);
67
63
  }
@@ -106,20 +102,19 @@ function createOperationFailure(pending, error, options) {
106
102
  level: LEVELS.failure,
107
103
  data: pending.data,
108
104
  error: rawError,
109
- message: report,
105
+ text: report,
110
106
  timing() {
111
107
  return finishedTs - pending.ts;
112
108
  },
113
- text: report,
114
109
  errorSerialized
115
110
  };
116
111
  return Object.freeze(failure);
117
112
  }
118
113
 
119
114
  // src/model/createOperationSuccess.ts
120
- function createOperationSuccess(pending, message) {
115
+ function createOperationSuccess(pending, text) {
121
116
  const finishedTs = Date.now();
122
- const givenText = message ?? pending.message();
117
+ const givenText = text ?? pending.text();
123
118
  function report() {
124
119
  return givenText;
125
120
  }
@@ -130,11 +125,10 @@ function createOperationSuccess(pending, message) {
130
125
  outcome: "success",
131
126
  level: LEVELS.success,
132
127
  data: pending.data,
133
- message: report,
128
+ text: report,
134
129
  timing() {
135
130
  return finishedTs - pending.ts;
136
- },
137
- text: report
131
+ }
138
132
  };
139
133
  return Object.freeze(success);
140
134
  }
@@ -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;;;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;;;ACjCO,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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,MAAM;AAAA,IACN;AAAA,EACD;AAEA,SAAO,OAAO,OAAO,OAAO;AAC7B;;;ACnCO,SAAS,uBACf,SACA,SACmB;AACnB,QAAM,aAAa,KAAK,IAAI;AAC5B,QAAM,YAAY,WAAW,QAAQ,QAAQ;AAE7C,WAAS,SAAiB;AACzB,WAAO;AAAA,EACR;AAEA,QAAM,UAA4B;AAAA,IACjC,WAAW,QAAQ;AAAA,IACnB,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/log/private/isFinished.ts", "../src/log/createOperationsLog.ts", "../src/model/private/constants.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 { AnyFinishedOperation, LoggableOperation } from '../types.js';\n\nexport function isFinished(operation: LoggableOperation): operation is AnyFinishedOperation {\n\treturn operation.outcome !== 'pending';\n}\n", "import { isFinished } from './private/isFinished.js';\nimport type {\n\tAnyFinishedOperation,\n\tLoggerInterface,\n\tOperationsLog,\n\tOperationsLogOptions,\n} from './types.js';\n\nexport function createOperationsLog(\n\tlogger: LoggerInterface,\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 formatData(data: unknown): string {\n\treturn data ? JSON.stringify(data) : '';\n}\n", "import { LEVELS } from './private/constants.js';\nimport { 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> = {\n\t\toperation: name,\n\t\tts,\n\t\toutcome: 'pending',\n\t\tlevel: LEVELS.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) as OperationPending<D> & { operation: N };\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<D>(\n\tpending: OperationPending<D>,\n\terror: unknown,\n\toptions?: { label?: string },\n): OperationFailure<D> {\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<D> = {\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\ttext: report,\n\t\ttiming(): number {\n\t\t\treturn finishedTs - pending.ts;\n\t\t},\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<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\tlevel: LEVELS.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": ";AAEO,SAAS,WAAW,WAAiE;AAC3F,SAAO,UAAU,YAAY;AAC9B;;;ACIO,SAAS,oBACf,QACA,SACgB;AAGhB,OAAK;AAEL,QAAM,mBAA2C,CAAC;AAElD,SAAO;AAAA,IACN,IAAI,WAAiB;AAC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EACD;AAEA,MAAI;AACH,WAAO,OAAO,KAAK;AAAA,EACpB,QAAQ;AACP,WAAO;AAAA,EACR;AACD;;;AClBO,SAAS,uBACf,SACA,OACA,SACsB;AACtB,QAAM,aAAa,KAAK,IAAI;AAC5B,QAAM,WAAW,oBAAoB,KAAK;AAC1C,QAAM,QAAQ,SAAS;AAEvB,WAAS,SAAiB;AACzB,WAAO;AAAA,EACR;AAEA,WAAS,kBAA0B;AAClC,WAAO,QAAQ,GAAG,KAAK,KAAK,QAAQ,KAAK;AAAA,EAC1C;AAEA,QAAM,UAA+B;AAAA,IACpC,WAAW,QAAQ;AAAA,IACnB,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,IACT,OAAO,OAAO;AAAA,IACd,MAAM,QAAQ;AAAA,IACd,OAAO;AAAA,IACP,MAAM;AAAA,IACN,SAAiB;AAChB,aAAO,aAAa,QAAQ;AAAA,IAC7B;AAAA,IACA;AAAA,EACD;AAEA,SAAO,OAAO,OAAO,OAAO;AAC7B;;;AClCO,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,OAAO,OAAO;AAAA,IACd,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
  }
@@ -1,3 +1,2 @@
1
- import type { LoggerAPI } from '@art-lib/logger';
2
- import type { OperationsLog, OperationsLogOptions } from './types.js';
3
- export declare function createOperationsLog(logger: LoggerAPI, options?: OperationsLogOptions): OperationsLog;
1
+ import type { LoggerInterface, OperationsLog, OperationsLogOptions } from './types.js';
2
+ export declare function createOperationsLog(logger: LoggerInterface, options?: OperationsLogOptions): OperationsLog;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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;",
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 { isFinished } from './private/isFinished.js';\nimport type {\n\tAnyFinishedOperation,\n\tLoggerInterface,\n\tOperationsLog,\n\tOperationsLogOptions,\n} from './types.js';\n\nexport function createOperationsLog(\n\tlogger: LoggerInterface,\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;;;ACIO,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;",
6
6
  "names": []
7
7
  }
@@ -1,11 +1,6 @@
1
1
  import type { Message } from '@art-lib/logger';
2
2
  import type { OperationFailure, OperationSuccess } from '../model/index.js';
3
3
  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
4
  export type LoggableOperation = Message & {
10
5
  outcome: string;
11
6
  };
@@ -15,4 +10,7 @@ export type OperationsLog = {
15
10
  since(timestamp: number): AnyFinishedOperation[];
16
11
  latest(count: number): AnyFinishedOperation[];
17
12
  };
13
+ export type LoggerInterface = {
14
+ log(operation: LoggableOperation): void;
15
+ };
18
16
  export type OperationsLogOptions = unknown;
@@ -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,4 @@
1
1
  import type { OperationFailure, OperationPending } from './types.js';
2
- export declare function createOperationFailure(pending: OperationPending, error: unknown, options?: {
2
+ export declare function createOperationFailure<D>(pending: OperationPending<D>, error: unknown, options?: {
3
3
  label?: string;
4
- }): OperationFailure;
4
+ }): 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>;
@@ -5,20 +5,17 @@ var LEVELS = {
5
5
  failure: "error"
6
6
  };
7
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 : "";
8
+ // src/model/private/formatData.ts
9
+ function formatData(data) {
10
+ return data ? JSON.stringify(data) : "";
15
11
  }
16
12
 
17
13
  // src/model/createGenericOperation.ts
18
- function createGenericOperation(name, data) {
14
+ function createGenericOperation(name, data, toText) {
19
15
  const ts = Date.now();
20
- function message() {
21
- return readInputUri(data);
16
+ const resolveToText = toText ?? formatData;
17
+ function readText() {
18
+ return resolveToText(data);
22
19
  }
23
20
  const pending = {
24
21
  operation: name,
@@ -26,11 +23,10 @@ function createGenericOperation(name, data) {
26
23
  outcome: "pending",
27
24
  level: LEVELS.pending,
28
25
  data,
29
- message,
26
+ text: readText,
30
27
  timing() {
31
28
  return Number.NaN;
32
- },
33
- text: message
29
+ }
34
30
  };
35
31
  return Object.freeze(pending);
36
32
  }
@@ -75,20 +71,19 @@ function createOperationFailure(pending, error, options) {
75
71
  level: LEVELS.failure,
76
72
  data: pending.data,
77
73
  error: rawError,
78
- message: report,
74
+ text: report,
79
75
  timing() {
80
76
  return finishedTs - pending.ts;
81
77
  },
82
- text: report,
83
78
  errorSerialized
84
79
  };
85
80
  return Object.freeze(failure);
86
81
  }
87
82
 
88
83
  // src/model/createOperationSuccess.ts
89
- function createOperationSuccess(pending, message) {
84
+ function createOperationSuccess(pending, text) {
90
85
  const finishedTs = Date.now();
91
- const givenText = message ?? pending.message();
86
+ const givenText = text ?? pending.text();
92
87
  function report() {
93
88
  return givenText;
94
89
  }
@@ -99,11 +94,10 @@ function createOperationSuccess(pending, message) {
99
94
  outcome: "success",
100
95
  level: LEVELS.success,
101
96
  data: pending.data,
102
- message: report,
97
+ text: report,
103
98
  timing() {
104
99
  return finishedTs - pending.ts;
105
- },
106
- text: report
100
+ }
107
101
  };
108
102
  return Object.freeze(success);
109
103
  }
@@ -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,SAAiB;AAChB,aAAO,OAAO;AAAA,IACf;AAAA,IACA,MAAM;AAAA,EACP;AAEA,SAAO,OAAO,OAAO,OAAO;AAC7B;;;ACzBO,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;;;AClBO,SAAS,uBACf,SACA,OACA,SACmB;AACnB,QAAM,aAAa,KAAK,IAAI;AAC5B,QAAM,WAAW,oBAAoB,KAAK;AAC1C,QAAM,QAAQ,SAAS;AAEvB,WAAS,SAAiB;AACzB,WAAO;AAAA,EACR;AAEA,WAAS,kBAA0B;AAClC,WAAO,QAAQ,GAAG,KAAK,KAAK,QAAQ,KAAK;AAAA,EAC1C;AAEA,QAAM,UAA4B;AAAA,IACjC,WAAW,QAAQ;AAAA,IACnB,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,IACT,OAAO,OAAO;AAAA,IACd,MAAM,QAAQ;AAAA,IACd,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAiB;AAChB,aAAO,aAAa,QAAQ;AAAA,IAC7B;AAAA,IACA,MAAM;AAAA,IACN;AAAA,EACD;AAEA,SAAO,OAAO,OAAO,OAAO;AAC7B;;;ACnCO,SAAS,uBACf,SACA,SACmB;AACnB,QAAM,aAAa,KAAK,IAAI;AAC5B,QAAM,YAAY,WAAW,QAAQ,QAAQ;AAE7C,WAAS,SAAiB;AACzB,WAAO;AAAA,EACR;AAEA,QAAM,UAA4B;AAAA,IACjC,WAAW,QAAQ;AAAA,IACnB,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/constants.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 '../types.js';\n\nexport const LEVELS: Record<OperationOutcome, MessageLevel> = {\n\tpending: 'debug',\n\tsuccess: 'info',\n\tfailure: 'error',\n};\n", "export function formatData(data: unknown): string {\n\treturn data ? JSON.stringify(data) : '';\n}\n", "import { LEVELS } from './private/constants.js';\nimport { 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> = {\n\t\toperation: name,\n\t\tts,\n\t\toutcome: 'pending',\n\t\tlevel: LEVELS.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) as OperationPending<D> & { operation: N };\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<D>(\n\tpending: OperationPending<D>,\n\terror: unknown,\n\toptions?: { label?: string },\n): OperationFailure<D> {\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<D> = {\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\ttext: report,\n\t\ttiming(): number {\n\t\t\treturn finishedTs - pending.ts;\n\t\t},\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<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\tlevel: LEVELS.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,SAAiD;AAAA,EAC7D,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AACV;;;ACRO,SAAS,WAAW,MAAuB;AACjD,SAAO,OAAO,KAAK,UAAU,IAAI,IAAI;AACtC;;;ACEO,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,UAA+B;AAAA,IACpC,WAAW;AAAA,IACX;AAAA,IACA,SAAS;AAAA,IACT,OAAO,OAAO;AAAA,IACd;AAAA,IACA,MAAM;AAAA,IACN,SAAiB;AAChB,aAAO,OAAO;AAAA,IACf;AAAA,EACD;AAEA,SAAO,OAAO,OAAO,OAAO;AAC7B;;;AC7BO,SAAS,oBAAoB,OAAwB;AAC3D,MAAI,OAAO,UAAU,UAAU;AAC9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O,OAAO,OAAO,OAAO;AAC7B;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1 @@
1
+ export declare function formatData(data: unknown): string;
@@ -5,10 +5,9 @@ export type OperationBase = {
5
5
  readonly ts: number;
6
6
  readonly finishedTs?: number;
7
7
  readonly outcome: OperationOutcome;
8
- message(): string;
8
+ text(): string;
9
9
  timing(): number;
10
10
  readonly level: MessageLevel;
11
- text(): string;
12
11
  };
13
12
  export type OperationPending<D = unknown> = OperationBase & {
14
13
  readonly outcome: 'pending';
@@ -1,3 +1,3 @@
1
1
  import type { LoggerMock } from './types.js';
2
- /** @mocks LoggerAPI */
2
+ /** @mocks the logger the operations log forwards to */
3
3
  export declare function createLoggerMock(): LoggerMock;
@@ -1,5 +1,5 @@
1
- import type { LoggerAPI, Message } from '@art-lib/logger';
1
+ import type { LoggableOperation, LoggerInterface } from '../../../log/types.js';
2
2
  export type LoggerMock = {
3
- logger: LoggerAPI;
4
- messages: Message[];
3
+ logger: LoggerInterface;
4
+ messages: LoggableOperation[];
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@art-lib/operations",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Operation outcome types and factories, and an append-only operations log that forwards every operation to the logger.",
5
5
  "keywords": [
6
6
  "library",
@@ -1 +0,0 @@
1
- export declare function readInputUri(data: unknown): string;