@protobase/workflows 0.82.0 → 0.83.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.
@@ -39,7 +39,8 @@ const watched = (services, mailbox, actsAs, used) => {
39
39
  ...services,
40
40
  fetch,
41
41
  records: mark("records", services.records),
42
- files: mark("files", services.files)
42
+ files: mark("files", services.files),
43
+ storage: mark("storage", services.storage)
43
44
  },
44
45
  mailbox: mailbox && mark("mailbox", mailbox)
45
46
  };
@@ -10,11 +10,16 @@ export type PluginFetchInit = {
10
10
  signal?: AbortSignal;
11
11
  /** The most bytes of the answer's body read off the wire; a longer body fails. Default and maximum 10 MiB. */
12
12
  maxBytes?: number;
13
+ /**
14
+ * Gives the answer with its body unread and no limit on its size, for a step that streams it on, such as into
15
+ * storage; the step reads it as a stream, never as a whole.
16
+ */
17
+ stream?: boolean;
13
18
  };
14
19
  /**
15
20
  * The only way a plugin sends a request: it resolves the host once, refuses a private, loopback or link-local address
16
21
  * (unless the app allows them), connects to the address it checked, follows no redirect and reads at most `maxBytes`
17
- * of the body as sent, never decoding a `Content-Encoding`. The answer's body is already read.
22
+ * of the body as sent, never decoding a `Content-Encoding`. The answer's body is already read, unless `stream`.
18
23
  */
19
24
  export type PluginFetch = (url: string, init?: PluginFetchInit) => Promise<Response>;
20
25
  /** A file of the run: the handle the API gives for a file field. */
@@ -34,6 +39,34 @@ export type PluginFiles = {
34
39
  bytes: Uint8Array;
35
40
  }>;
36
41
  };
42
+ /**
43
+ * A file kept in a storage configuration: the configuration's name, the server that holds it for a local one, and its
44
+ * path there. It says where the file is, never how to reach it: no folder, bucket or key.
45
+ */
46
+ export type StoredFile = {
47
+ configuration: string;
48
+ node?: string;
49
+ path: string;
50
+ name: string;
51
+ type: string;
52
+ size: number;
53
+ };
54
+ /**
55
+ * Files in the app's storage configurations, by name, as the workflow's last editor may read them now: naming one they
56
+ * may not read fails as one that does not exist (`Storage.NotFound`).
57
+ */
58
+ export type PluginStorage = {
59
+ /** Streams `body` to `path` in the configuration, replacing what is there; it is whole or not there at all. */
60
+ put(configuration: string, path: string, body: ReadableStream<Uint8Array>, file: {
61
+ name: string;
62
+ type: string;
63
+ }): Promise<StoredFile>;
64
+ /** The bytes of a stored file, as a stream; `field` names the argument in the error. Fails as `Storage.NotFound` when it is gone. */
65
+ read(file: unknown, field: string): Promise<{
66
+ file: StoredFile;
67
+ body: ReadableStream<Uint8Array>;
68
+ }>;
69
+ };
37
70
  type Key = string | number | (string | number)[];
38
71
  type Record_ = Record<string, unknown>;
39
72
  /**
@@ -79,11 +112,12 @@ export type PluginConnection = {
79
112
  refresh?: boolean;
80
113
  }): Promise<string>;
81
114
  };
82
- /** What the app gives every hook of a plugin: its guarded requests, records, files and mail. */
115
+ /** What the app gives every hook of a plugin: its guarded requests, records, files, storage and mail. */
83
116
  export type PluginServices = {
84
117
  fetch: PluginFetch;
85
118
  records: PluginRecords;
86
119
  files: PluginFiles;
120
+ storage: PluginStorage;
87
121
  /** Undefined when the app sends no mail. */
88
122
  mail: PluginMail | undefined;
89
123
  };
@@ -1,9 +1,10 @@
1
1
  import { StepError } from "../run/errors.js";
2
- import { FileValue, JsonSchema, PluginConnection, PluginFetch, PluginFetchInit, PluginFiles, PluginMail, PluginMailMessage, PluginRecords, PluginServices, StepContext } from "./context.js";
2
+ import { FileValue, JsonSchema, PluginConnection, PluginFetch, PluginFetchInit, PluginFiles, PluginMail, PluginMailMessage, PluginRecords, PluginServices, PluginStorage, StepContext, StoredFile } from "./context.js";
3
3
  import { ConnectionDeclaration, OAuthEndpoints, Plugin, PollEvery, PollingTrigger, ReadyTrigger, StepType, TriggerContext, TriggerItem, TriggerType, WebhookEvent, WebhookItem, WebhookTrigger } from "./types.js";
4
4
  import { ConnectionError } from "./connection-error.js";
5
5
  import { definePlugin, pluginApi } from "./define-plugin.js";
6
6
  import { AddressRefusedError, ResponseTooLargeError, fetchMaxBytes } from "./fetch-errors.js";
7
7
  import { isFileValue } from "./file-value.js";
8
+ import { isStoredFile } from "./stored-file.js";
8
9
  import { webhookBodyCeiling, webhookBodyDefault, webhookInputCheck, webhookInputProperties } from "./webhook-input.js";
9
- export { AddressRefusedError, type ConnectionDeclaration, ConnectionError, type FileValue, type JsonSchema, type OAuthEndpoints, type Plugin, type PluginConnection, type PluginFetch, type PluginFetchInit, type PluginFiles, type PluginMail, type PluginMailMessage, type PluginRecords, type PluginServices, type PollEvery, type PollingTrigger, type ReadyTrigger, ResponseTooLargeError, type StepContext, StepError, type StepType, type TriggerContext, type TriggerItem, type TriggerType, type WebhookEvent, type WebhookItem, type WebhookTrigger, definePlugin, fetchMaxBytes, isFileValue, pluginApi, webhookBodyCeiling, webhookBodyDefault, webhookInputCheck, webhookInputProperties };
10
+ export { AddressRefusedError, type ConnectionDeclaration, ConnectionError, type FileValue, type JsonSchema, type OAuthEndpoints, type Plugin, type PluginConnection, type PluginFetch, type PluginFetchInit, type PluginFiles, type PluginMail, type PluginMailMessage, type PluginRecords, type PluginServices, type PluginStorage, type PollEvery, type PollingTrigger, type ReadyTrigger, ResponseTooLargeError, type StepContext, StepError, type StepType, type StoredFile, type TriggerContext, type TriggerItem, type TriggerType, type WebhookEvent, type WebhookItem, type WebhookTrigger, definePlugin, fetchMaxBytes, isFileValue, isStoredFile, pluginApi, webhookBodyCeiling, webhookBodyDefault, webhookInputCheck, webhookInputProperties };
@@ -3,5 +3,6 @@ import { definePlugin, pluginApi } from "./define-plugin.js";
3
3
  import { ConnectionError } from "./connection-error.js";
4
4
  import { AddressRefusedError, ResponseTooLargeError, fetchMaxBytes } from "./fetch-errors.js";
5
5
  import { isFileValue } from "./file-value.js";
6
+ import { isStoredFile } from "./stored-file.js";
6
7
  import { webhookBodyCeiling, webhookBodyDefault, webhookInputCheck, webhookInputProperties } from "./webhook-input.js";
7
- export { AddressRefusedError, ConnectionError, ResponseTooLargeError, StepError, definePlugin, fetchMaxBytes, isFileValue, pluginApi, webhookBodyCeiling, webhookBodyDefault, webhookInputCheck, webhookInputProperties };
8
+ export { AddressRefusedError, ConnectionError, ResponseTooLargeError, StepError, definePlugin, fetchMaxBytes, isFileValue, isStoredFile, pluginApi, webhookBodyCeiling, webhookBodyDefault, webhookInputCheck, webhookInputProperties };
@@ -0,0 +1,5 @@
1
+ import { StoredFile } from "./context.js";
2
+ //#region src/plugin/stored-file.d.ts
3
+ /** Whether a value has a stored file's shape: its configuration, path, name, type and size, and a text node if any. */
4
+ export declare const isStoredFile: (value: unknown) => value is StoredFile;
5
+ //#endregion
@@ -0,0 +1,9 @@
1
+ //#region src/plugin/stored-file.ts
2
+ /** Whether a value has a stored file's shape: its configuration, path, name, type and size, and a text node if any. */
3
+ const isStoredFile = (value) => {
4
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
5
+ const { configuration, node, path, name, type, size } = value;
6
+ return typeof configuration === "string" && typeof path === "string" && typeof name === "string" && typeof type === "string" && typeof size === "number" && (node === void 0 || typeof node === "string");
7
+ };
8
+ //#endregion
9
+ export { isStoredFile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/workflows",
3
- "version": "0.82.0",
3
+ "version": "0.83.0",
4
4
  "description": "Workflows as state machines with JSONata expressions: their check, a runner that saves only what a run needs to go on and traces every step, and the plugin interface for trigger and step types.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {