@webamoki/web-svelte 2.4.0 → 2.5.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.
@@ -0,0 +1,8 @@
1
+ import type { RemoteCommand } from '@sveltejs/kit';
2
+ import { ResponseResult } from './remote.js';
3
+ export declare class CommandAction<S, O> {
4
+ #private;
5
+ get submitting(): boolean;
6
+ constructor(remote: RemoteCommand<S, Promise<ResponseResult<O>>>);
7
+ execute(input: Parameters<RemoteCommand<S, Promise<ResponseResult<O>>>>[0]): Promise<O>;
8
+ }
@@ -0,0 +1,22 @@
1
+ // Client side handling
2
+ import { ResponseResult } from './remote.js';
3
+ export class CommandAction {
4
+ get submitting() {
5
+ return this.#submitCount > 0;
6
+ }
7
+ #remote;
8
+ #submitCount = $state(0);
9
+ constructor(remote) {
10
+ this.#remote = remote;
11
+ }
12
+ async execute(input) {
13
+ this.#submitCount++;
14
+ try {
15
+ const result = await this.#remote(input);
16
+ return ResponseResult.unwrap(result);
17
+ }
18
+ finally {
19
+ this.#submitCount--;
20
+ }
21
+ }
22
+ }
@@ -1,6 +1,6 @@
1
1
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2
- import { type InvalidField, type RemoteCommand, type RemoteForm, type RemoteFormInput, type RemoteQueryFunction } from '@sveltejs/kit';
3
2
  import { Result } from './functional/index.js';
3
+ import { type InvalidField, type RemoteCommand, type RemoteForm, type RemoteFormInput, type RemoteQueryFunction } from '@sveltejs/kit';
4
4
  export type CheckFunction = () => Promise<CheckResult>;
5
5
  export type CheckResult = Result<void, ResponseError>;
6
6
  export declare const CheckResult: {
@@ -1,6 +1,6 @@
1
1
  import { command, form, query } from '$app/server';
2
- import { error } from '@sveltejs/kit';
3
2
  import { Result } from './functional/index.js';
3
+ import { error } from '@sveltejs/kit';
4
4
  export const CheckResult = {
5
5
  /* Helper function for ok check result. */
6
6
  ok() {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public",
5
5
  "provenance": true
6
6
  },
7
- "version": "2.4.0",
7
+ "version": "2.5.0",
8
8
  "license": "MIT",
9
9
  "repository": {
10
10
  "type": "git",
@@ -57,6 +57,10 @@
57
57
  "./utils/remote": {
58
58
  "types": "./dist/shared/utils/remote.d.ts",
59
59
  "import": "./dist/shared/utils/remote.js"
60
+ },
61
+ "./utils/command": {
62
+ "types": "./dist/shared/utils/command.d.ts",
63
+ "import": "./dist/shared/utils/command.js"
60
64
  }
61
65
  },
62
66
  "peerDependencies": {