@oscarpalmer/atoms 0.216.0 → 0.217.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/array/swap.d.mts +2 -1
  2. package/dist/color/constants.d.mts +2 -1
  3. package/dist/color/space/rgb.d.mts +1 -0
  4. package/dist/function/index.mjs +1 -2
  5. package/dist/herald.mjs +1 -2
  6. package/dist/index.d.mts +253 -40
  7. package/dist/index.mjs +262 -102
  8. package/dist/internal/plan/index.d.mts +7 -0
  9. package/dist/internal/plan/index.mjs +18 -0
  10. package/dist/{plan/generate.d.mts → internal/plan/plan.generate.d.mts} +2 -2
  11. package/dist/{plan/generate.mjs → internal/plan/plan.generate.mjs} +4 -4
  12. package/dist/models/color.model.d.mts +2 -1
  13. package/dist/models/function/once.model.d.mts +2 -1
  14. package/dist/models/index.d.mts +2 -1
  15. package/dist/models/plan.model.d.mts +158 -29
  16. package/dist/models/plan.model.mjs +13 -5
  17. package/dist/models/queue.model.d.mts +2 -1
  18. package/dist/models/result.model.d.mts +2 -1
  19. package/dist/models/value/value.equal.model.d.mts +2 -1
  20. package/dist/models/value/value.merge.model.d.mts +2 -1
  21. package/dist/models/value/value.misc.model.d.mts +2 -1
  22. package/dist/number.mjs +1 -2
  23. package/dist/plan/index.mjs +14 -14
  24. package/dist/plan/is.d.mts +59 -3
  25. package/dist/plan/is.mjs +82 -10
  26. package/dist/plan/misc.d.mts +51 -3
  27. package/dist/plan/misc.mjs +47 -30
  28. package/dist/plan/models.d.mts +2 -2
  29. package/dist/plan/result.d.mts +15 -3
  30. package/dist/plan/result.mjs +5 -11
  31. package/dist/plan/run.d.mts +1 -3
  32. package/dist/plan/run.mjs +5 -11
  33. package/dist/plan/use.d.mts +36 -0
  34. package/dist/plan/use.mjs +69 -0
  35. package/dist/promise/models.mjs +1 -2
  36. package/dist/result/index.mjs +1 -2
  37. package/dist/result/work/pipe.d.mts +2 -1
  38. package/dist/subscription.mjs +1 -2
  39. package/package.json +8 -10
@@ -1,39 +1,56 @@
1
1
  import { error } from "../internal/result/misc.mjs";
2
- import { PLAN_SYMBOL } from "../models/plan.model.mjs";
2
+ import { PLAN_FAILURE_ASYNC, PLAN_FAILURE_SYNC, PLAN_SUCCESS_ASYNC, PLAN_SUCCESS_SYNC, PLAN_SYMBOL } from "../models/plan.model.mjs";
3
+ import { getGenerator } from "../internal/plan/index.mjs";
3
4
  //#region src/plan/misc.ts
4
- function PlanFailure(generator) {
5
- this[PLAN_SYMBOL] = { generator };
6
- }
7
- PlanFailure.prototype[Symbol.iterator] = function() {
8
- return this[PLAN_SYMBOL].generator();
9
- };
10
- function PlanSuccess(generator) {
11
- this[PLAN_SYMBOL] = { generator };
12
- }
13
- PlanSuccess.prototype[Symbol.iterator] = function() {
14
- return this[PLAN_SYMBOL].generator();
15
- };
16
- /**
17
- * Create an immediately failing plan
18
- *
19
- * @param value Failure value
20
- * @returns Plan failure
21
- */
5
+ function AsyncFailure(generator) {
6
+ this[PLAN_SYMBOL] = {
7
+ generator,
8
+ type: PLAN_FAILURE_ASYNC
9
+ };
10
+ }
11
+ AsyncFailure.prototype[Symbol.asyncIterator] = getGenerator;
12
+ function AsyncSuccess(generator) {
13
+ this[PLAN_SYMBOL] = {
14
+ generator,
15
+ type: PLAN_SUCCESS_ASYNC
16
+ };
17
+ }
18
+ AsyncSuccess.prototype[Symbol.asyncIterator] = getGenerator;
19
+ function Failure(generator) {
20
+ this[PLAN_SYMBOL] = {
21
+ generator,
22
+ type: PLAN_FAILURE_SYNC
23
+ };
24
+ }
25
+ Failure.prototype[Symbol.iterator] = getGenerator;
26
+ function Success(generator) {
27
+ this[PLAN_SYMBOL] = {
28
+ generator,
29
+ type: PLAN_SUCCESS_SYNC
30
+ };
31
+ }
32
+ Success.prototype[Symbol.iterator] = getGenerator;
33
+ function asyncFail(value) {
34
+ return new AsyncFailure(async function* () {
35
+ yield error(await (typeof value === "function" ? value() : value));
36
+ });
37
+ }
38
+ function asyncSucceed(value) {
39
+ return new AsyncSuccess(async function* () {
40
+ return typeof value === "function" ? value() : value;
41
+ });
42
+ }
22
43
  function fail(value) {
23
- return new PlanFailure(function* () {
24
- yield error(value);
44
+ return new Failure(function* () {
45
+ yield error(typeof value === "function" ? value() : value);
25
46
  });
26
47
  }
27
- /**
28
- * Create an immediately succeeding plan
29
- *
30
- * @param value Success value
31
- * @returns Plan success
32
- */
33
48
  function succeed(value) {
34
- return new PlanSuccess(function* () {
35
- return value;
49
+ return new Success(function* () {
50
+ return typeof value === "function" ? value() : value;
36
51
  });
37
52
  }
53
+ fail.async = asyncFail;
54
+ succeed.async = asyncSucceed;
38
55
  //#endregion
39
- export { fail, succeed };
56
+ export { asyncFail, asyncSucceed, fail, succeed };
@@ -1,2 +1,2 @@
1
- import { AsyncPlan, Plan, PlanFailure, PlanResult, PlanSuccess } from "../models/plan.model.mjs";
2
- export type { AsyncPlan, Plan, PlanFailure, PlanResult, PlanSuccess };
1
+ import { AsyncFailure, AsyncPlan, AsyncPlanned, AsyncStep, AsyncSuccess, Failure, Plan, PlanError, PlanOk, PlanReturned, Planned, Step, Success } from "../models/plan.model.mjs";
2
+ export type { AsyncFailure, AsyncPlan, AsyncPlanned, AsyncStep, AsyncSuccess, Failure, Plan, PlanError, PlanOk, PlanReturned, Planned, Step, Success };
@@ -1,11 +1,14 @@
1
1
  import { Result } from "../models/result.model.mjs";
2
- import { AsyncPlan, InternalPlan, Plan, PlanError, PlanOk } from "../models/plan.model.mjs";
2
+ import { AsyncPlan, Plan, PlanError, PlanOk } from "../models/plan.model.mjs";
3
3
  //#region src/plan/result.d.ts
4
4
  /**
5
5
  * Attempt to run the generator to completion
6
6
  *
7
7
  * _Returns a promised {@link Result} instead of a raw value or throwing an error_
8
8
  *
9
+ * @param generator Generator to run
10
+ * @param parameters Parameters for starting the run
11
+ * @param signal Optional abort signal
9
12
  * @returns Promised result
10
13
  */
11
14
  export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned>, parameters: Parameters, signal?: AbortSignal): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
@@ -14,6 +17,8 @@ export declare function asyncAttemptRun<Yielded, Returned, Parameters extends un
14
17
  *
15
18
  * _Returns a promised {@link Result} instead of a raw value or throwing an error_
16
19
  *
20
+ * @param generator Generator to run
21
+ * @param signal Optional abort signal
17
22
  * @returns Promised result
18
23
  */
19
24
  export declare function asyncAttemptRun<Yielded, Returned>(generator: () => AsyncGenerator<Yielded, Returned>, signal?: AbortSignal): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
@@ -22,6 +27,9 @@ export declare function asyncAttemptRun<Yielded, Returned>(generator: () => Asyn
22
27
  *
23
28
  * _Returns a promised {@link Result} instead of a raw value or throwing an error_
24
29
  *
30
+ * @param plan Plan to run
31
+ * @param parameters Parameters for starting the run
32
+ * @param signal Optional abort signal
25
33
  * @returns Promised result
26
34
  */
27
35
  export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(plan: AsyncPlan<Yielded, Returned, Parameters>, parameters: Parameters, signal?: AbortSignal): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
@@ -30,6 +38,8 @@ export declare function asyncAttemptRun<Yielded, Returned, Parameters extends un
30
38
  *
31
39
  * _Returns a promised {@link Result} instead of a raw value or throwing an error_
32
40
  *
41
+ * @param plan Plan to run
42
+ * @param signal Optional abort signal
33
43
  * @returns Promised result
34
44
  */
35
45
  export declare function asyncAttemptRun<Yielded, Returned>(plan: AsyncPlan<Yielded, Returned, []>, signal?: AbortSignal): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
@@ -38,6 +48,8 @@ export declare function asyncAttemptRun<Yielded, Returned>(plan: AsyncPlan<Yield
38
48
  *
39
49
  * _Returns a {@link Result} instead of a raw value or throwing an error_
40
50
  *
51
+ * @param generator Generator to run
52
+ * @param parameters Parameters for starting the run
41
53
  * @returns Result
42
54
  */
43
55
  export declare function attemptRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => Generator<Yielded, Returned>, ...parameters: Parameters): Result<PlanOk<Returned>, PlanError<Yielded, Returned>>;
@@ -46,11 +58,11 @@ export declare function attemptRun<Yielded, Returned, Parameters extends unknown
46
58
  *
47
59
  * _Returns a {@link Result} instead of a raw value or throwing an error_
48
60
  *
61
+ * @param plan Plan to run
62
+ * @param parameters Parameters for starting the run
49
63
  * @returns Result
50
64
  */
51
65
  export declare function attemptRun<Yielded, Returned, Parameters extends unknown[]>(plan: Plan<Yielded, Returned, Parameters>, ...parameters: Parameters): Result<PlanOk<Returned>, PlanError<Yielded, Returned>>;
52
- export declare function attemptRunAsyncPlan(this: never, first: never, second: never): Promise<unknown>;
53
- export declare function attemptRunPlan(this: InternalPlan, ...parameters: unknown[]): unknown;
54
66
  export declare namespace attemptRun {
55
67
  export var async: typeof asyncAttemptRun;
56
68
  }
@@ -1,28 +1,22 @@
1
1
  import { asyncAttempt, attempt } from "../internal/result/attempt.mjs";
2
2
  import { PLAN_MESSAGE_RUN_INPUT, PLAN_SYMBOL } from "../models/plan.model.mjs";
3
- import { isAsyncGenerator, isAsyncPlan, isGenerator, isPlan } from "./is.mjs";
4
- import { asyncGenerate, generate } from "./generate.mjs";
3
+ import { asyncGenerate, generate } from "../internal/plan/plan.generate.mjs";
4
+ import { isAsyncGeneratorFunction, isAsyncPlan, isGeneratorFunction, isPlan } from "./is.mjs";
5
5
  //#region src/plan/result.ts
6
6
  function asyncAttemptRun(input, first, second) {
7
7
  let generator;
8
8
  if (isAsyncPlan(input)) generator = input[PLAN_SYMBOL];
9
- else if (isAsyncGenerator(input)) generator = input;
9
+ else if (isAsyncGeneratorFunction(input)) generator = input;
10
10
  if (generator == null) throw new Error(PLAN_MESSAGE_RUN_INPUT);
11
11
  return asyncAttempt(() => asyncGenerate(generator, true, first, second));
12
12
  }
13
13
  function attemptRun(input, ...parameters) {
14
14
  let generator;
15
15
  if (isPlan(input)) generator = input[PLAN_SYMBOL];
16
- else if (isGenerator(input)) generator = input;
16
+ else if (isGeneratorFunction(input)) generator = input;
17
17
  if (generator == null) throw new Error(PLAN_MESSAGE_RUN_INPUT);
18
18
  return attempt(() => generate(generator, parameters, true));
19
19
  }
20
- function attemptRunAsyncPlan(first, second) {
21
- return asyncAttemptRun(this, first, second);
22
- }
23
- function attemptRunPlan(...parameters) {
24
- return attempt(() => generate(this[PLAN_SYMBOL], parameters, true));
25
- }
26
20
  attemptRun.async = asyncAttemptRun;
27
21
  //#endregion
28
- export { asyncAttemptRun, attemptRun, attemptRunAsyncPlan, attemptRunPlan };
22
+ export { asyncAttemptRun, attemptRun };
@@ -1,4 +1,4 @@
1
- import { AsyncPlan, InternalAsyncPlan, InternalPlan, Plan, PlanReturned } from "../models/plan.model.mjs";
1
+ import { AsyncPlan, Plan, PlanReturned } from "../models/plan.model.mjs";
2
2
  import { asyncAttemptRun, attemptRun } from "./result.mjs";
3
3
  //#region src/plan/run.d.ts
4
4
  /**
@@ -51,8 +51,6 @@ export declare function run<Yielded, Returned, Parameters extends unknown[]>(gen
51
51
  * @returns Result
52
52
  */
53
53
  export declare function run<Yielded, Returned, Parameters extends unknown[]>(plan: Plan<Yielded, Returned, Parameters>, ...parameters: Parameters): PlanReturned<Returned>;
54
- export declare function runAsyncPlan(this: InternalAsyncPlan, first: never, second: never): Promise<unknown>;
55
- export declare function runPlan(this: InternalPlan, ...parameters: unknown[]): unknown;
56
54
  export declare namespace asyncRun {
57
55
  export var attempt: typeof asyncAttemptRun;
58
56
  }
package/dist/plan/run.mjs CHANGED
@@ -1,26 +1,20 @@
1
1
  import { PLAN_MESSAGE_RUN_INPUT, PLAN_SYMBOL } from "../models/plan.model.mjs";
2
- import { isAsyncGenerator, isAsyncPlan, isGenerator, isPlan } from "./is.mjs";
3
- import { asyncGenerate, generate } from "./generate.mjs";
2
+ import { asyncGenerate, generate } from "../internal/plan/plan.generate.mjs";
3
+ import { isAsyncGeneratorFunction, isAsyncPlan, isGeneratorFunction, isPlan } from "./is.mjs";
4
4
  import { asyncAttemptRun, attemptRun } from "./result.mjs";
5
5
  //#region src/plan/run.ts
6
6
  function asyncRun(input, first, second) {
7
7
  if (isAsyncPlan(input)) return asyncGenerate(input[PLAN_SYMBOL], false, first, second);
8
- if (isAsyncGenerator(input)) return asyncGenerate(input, false, first, second);
8
+ if (isAsyncGeneratorFunction(input)) return asyncGenerate(input, false, first, second);
9
9
  throw new Error(PLAN_MESSAGE_RUN_INPUT);
10
10
  }
11
11
  function run(input, ...parameters) {
12
12
  if (isPlan(input)) return input.run(...parameters);
13
- if (isGenerator(input)) return generate(input, parameters, false);
13
+ if (isGeneratorFunction(input)) return generate(input, parameters, false);
14
14
  throw new Error(PLAN_MESSAGE_RUN_INPUT);
15
15
  }
16
- function runAsyncPlan(first, second) {
17
- return asyncGenerate(this[PLAN_SYMBOL], false, first, second);
18
- }
19
- function runPlan(...parameters) {
20
- return generate(this[PLAN_SYMBOL], parameters, false);
21
- }
22
16
  asyncRun.attempt = asyncAttemptRun;
23
17
  run.async = asyncRun;
24
18
  run.attempt = attemptRun;
25
19
  //#endregion
26
- export { asyncRun, run, runAsyncPlan, runPlan };
20
+ export { asyncRun, run };
@@ -0,0 +1,36 @@
1
+ import { AsyncStep, AsyncStepValue, Step, StepValue } from "../models/plan.model.mjs";
2
+ //#region src/plan/use.d.ts
3
+ /**
4
+ * Create an asynchronous step from a callback
5
+ *
6
+ * @param callback Callback
7
+ * @returns An asynchronous step
8
+ */
9
+ export declare function asyncUse<Value>(callback: () => Value & AsyncStepValue<Value>): AsyncStep<Value>;
10
+ /**
11
+ * Create an asynchronous step from a value
12
+ *
13
+ * @param value Value
14
+ * @returns An asynchronous step
15
+ */
16
+ export declare function asyncUse<Value>(value: Value & AsyncStepValue<Value>): AsyncStep<Value>;
17
+ /**
18
+ * Create a step from a callback
19
+ *
20
+ * @param callback Callback
21
+ * @returns A step
22
+ * @throws Error If the input is invalid
23
+ */
24
+ export declare function use<Value>(callback: () => Value & StepValue<Value>): Step<Value>;
25
+ /**
26
+ * Create a step from a value
27
+ *
28
+ * @param value Value
29
+ * @returns A step
30
+ * @throws Error If the input is invalid
31
+ */
32
+ export declare function use<Value>(value: Value & StepValue<Value>): Step<Value>;
33
+ export declare namespace use {
34
+ export var async: typeof asyncUse;
35
+ }
36
+ //#endregion
@@ -0,0 +1,69 @@
1
+ import { isError, isOk } from "../internal/result/misc.mjs";
2
+ import { PLAN_STEP_ASYNC, PLAN_STEP_SYNC, PLAN_SYMBOL } from "../models/plan.model.mjs";
3
+ import { getGenerator } from "../internal/plan/index.mjs";
4
+ import { isAsyncFailure, isAsyncGenerator, isAsyncGeneratorFunction, isAsyncPlan, isAsyncStep, isAsyncSuccess, isGenerator } from "./is.mjs";
5
+ import { fail } from "./misc.mjs";
6
+ //#region src/plan/use.ts
7
+ function AsyncStep(generator) {
8
+ this[PLAN_SYMBOL] = {
9
+ generator,
10
+ type: PLAN_STEP_ASYNC
11
+ };
12
+ }
13
+ AsyncStep.prototype[Symbol.asyncIterator] = getGenerator;
14
+ function Step(generator) {
15
+ this[PLAN_SYMBOL] = {
16
+ generator,
17
+ type: PLAN_STEP_SYNC
18
+ };
19
+ }
20
+ Step.prototype[Symbol.iterator] = getGenerator;
21
+ function asyncUse(value) {
22
+ return new AsyncStep(async function* () {
23
+ let actual = value;
24
+ if (typeof actual === "function") actual = actual();
25
+ actual = await actual;
26
+ if (typeof actual === "function") throw new Error();
27
+ if (typeof actual === "object" && actual !== null && PLAN_SYMBOL in actual) return yield* actual;
28
+ if (isAsyncGenerator(actual) || isGenerator(actual)) return yield* actual;
29
+ if (isError(actual)) {
30
+ yield* fail(actual.error);
31
+ return;
32
+ }
33
+ if (isOk(actual)) return actual.value;
34
+ if (actual instanceof Error) {
35
+ yield* fail(actual);
36
+ return;
37
+ }
38
+ return actual;
39
+ });
40
+ }
41
+ function use(value) {
42
+ validateUseInput(value, false);
43
+ return new Step(function* () {
44
+ let actual = value;
45
+ if (typeof actual === "function") {
46
+ actual = actual();
47
+ validateUseInput(actual, true);
48
+ }
49
+ if (typeof actual === "object" && actual !== null && PLAN_SYMBOL in actual) return yield* actual;
50
+ if (isGenerator(actual)) return yield* actual;
51
+ if (isError(actual)) {
52
+ yield* fail(actual.error);
53
+ return;
54
+ }
55
+ if (isOk(actual)) return actual.value;
56
+ if (actual instanceof Error) {
57
+ yield* fail(actual);
58
+ return;
59
+ }
60
+ return actual;
61
+ });
62
+ }
63
+ function validateUseInput(value, resolved) {
64
+ if (value instanceof Promise || isAsyncFailure(value) || isAsyncGenerator(value) || isAsyncGeneratorFunction(value) || isAsyncPlan(value) || isAsyncStep(value) || isAsyncSuccess(value)) throw new Error();
65
+ if (resolved && typeof value === "function") throw new Error();
66
+ }
67
+ use.async = asyncUse;
68
+ //#endregion
69
+ export { asyncUse, use };
@@ -1,2 +1 @@
1
- import { CancelablePromise, PromiseTimeoutError } from "../models/promise.model.mjs";
2
- export { CancelablePromise, PromiseTimeoutError };
1
+ export { CancelablePromise, PromiseTimeoutError } from "../models/promise.model.mjs";
@@ -1,2 +1 @@
1
- import { asyncAttempt, attempt } from "../internal/result/attempt.mjs";
2
- export { asyncAttempt, attempt };
1
+ export { asyncAttempt, attempt } from "../internal/result/attempt.mjs";
@@ -181,4 +181,5 @@ export declare function attemptPipe<Initial>(initial: GenericCallback | Initial
181
181
  export declare namespace attemptPipe {
182
182
  export var async: typeof attemptAsyncPipe;
183
183
  }
184
- //#endregion
184
+ //#endregion
185
+ export {};
@@ -1,2 +1 @@
1
- import { isSubscription, isSubscriptions, subscriptions } from "./internal/subscription.mjs";
2
- export { isSubscription, isSubscriptions, subscriptions };
1
+ export { isSubscription, isSubscriptions, subscriptions } from "./internal/subscription.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oscarpalmer/atoms",
3
- "version": "0.216.0",
3
+ "version": "0.217.0",
4
4
  "description": "Atomic utilities for making your JavaScript better.",
5
5
  "keywords": [
6
6
  "array",
@@ -173,6 +173,10 @@
173
173
  "types": "./dist/plan/run.d.mts",
174
174
  "default": "./dist/plan/run.mjs"
175
175
  },
176
+ "./plan/use": {
177
+ "types": "./dist/plan/use.d.mts",
178
+ "default": "./dist/plan/use.mjs"
179
+ },
176
180
  "./promise": {
177
181
  "types": "./dist/promise/index.d.mts",
178
182
  "default": "./dist/promise/index.mjs"
@@ -313,18 +317,12 @@
313
317
  },
314
318
  "devDependencies": {
315
319
  "@types/node": "^26.6",
316
- "@vitest/coverage-istanbul": "5.0.1",
317
- "eslint": "^10.12",
320
+ "@vitest/coverage-istanbul": "^5",
321
+ "eslint": "^10.13",
318
322
  "jsdom": "^30.1",
319
323
  "tsdown": "^0.23",
320
324
  "typescript": "^7",
321
- "vite": "npm:@voidzero-dev/vite-plus-core@1.0.0",
322
- "vite-plus": "1.0.0",
323
- "vitest": "5.0.1"
324
- },
325
- "overrides": {
326
- "vite": "npm:@voidzero-dev/vite-plus-core@1.0.0",
327
- "vitest": "5.0.1"
325
+ "vite-plus": "^1.2"
328
326
  },
329
327
  "packageManager": "npm@11.11.1"
330
328
  }