@vercel/sandbox 2.0.0-beta.2 → 2.0.0-beta.20

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 (208) hide show
  1. package/README.md +48 -1
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  3. package/dist/api-client/api-client.cjs +445 -0
  4. package/dist/api-client/api-client.cjs.map +1 -0
  5. package/dist/api-client/api-client.d.cts +6235 -0
  6. package/dist/api-client/api-client.d.ts +6229 -706
  7. package/dist/api-client/api-client.js +436 -472
  8. package/dist/api-client/api-client.js.map +1 -1
  9. package/dist/api-client/api-error.cjs +32 -0
  10. package/dist/api-client/api-error.cjs.map +1 -0
  11. package/dist/api-client/api-error.d.cts +29 -0
  12. package/dist/api-client/api-error.d.ts +21 -16
  13. package/dist/api-client/api-error.js +28 -32
  14. package/dist/api-client/api-error.js.map +1 -1
  15. package/dist/api-client/base-client.cjs +126 -0
  16. package/dist/api-client/base-client.cjs.map +1 -0
  17. package/dist/api-client/base-client.d.cts +38 -0
  18. package/dist/api-client/base-client.d.ts +31 -36
  19. package/dist/api-client/base-client.js +114 -118
  20. package/dist/api-client/base-client.js.map +1 -1
  21. package/dist/api-client/file-writer.cjs +62 -0
  22. package/dist/api-client/file-writer.cjs.map +1 -0
  23. package/dist/api-client/file-writer.d.cts +66 -0
  24. package/dist/api-client/file-writer.d.ts +56 -42
  25. package/dist/api-client/file-writer.js +57 -61
  26. package/dist/api-client/file-writer.js.map +1 -1
  27. package/dist/api-client/index.cjs +2 -0
  28. package/dist/api-client/index.d.ts +2 -2
  29. package/dist/api-client/index.js +4 -21
  30. package/dist/api-client/validators.cjs +229 -0
  31. package/dist/api-client/validators.cjs.map +1 -0
  32. package/dist/api-client/validators.d.cts +26885 -0
  33. package/dist/api-client/validators.d.ts +26732 -3706
  34. package/dist/api-client/validators.js +198 -191
  35. package/dist/api-client/validators.js.map +1 -1
  36. package/dist/api-client/with-retry.cjs +89 -0
  37. package/dist/api-client/with-retry.cjs.map +1 -0
  38. package/dist/api-client/with-retry.d.cts +10 -0
  39. package/dist/api-client/with-retry.d.ts +9 -13
  40. package/dist/api-client/with-retry.js +81 -102
  41. package/dist/api-client/with-retry.js.map +1 -1
  42. package/dist/auth/api.cjs +29 -0
  43. package/dist/auth/api.cjs.map +1 -0
  44. package/dist/auth/api.js +26 -25
  45. package/dist/auth/api.js.map +1 -1
  46. package/dist/auth/error.cjs +13 -0
  47. package/dist/auth/error.cjs.map +1 -0
  48. package/dist/auth/error.js +11 -11
  49. package/dist/auth/error.js.map +1 -1
  50. package/dist/auth/file.cjs +64 -0
  51. package/dist/auth/file.cjs.map +1 -0
  52. package/dist/auth/file.d.cts +26 -0
  53. package/dist/auth/file.d.ts +19 -15
  54. package/dist/auth/file.js +49 -64
  55. package/dist/auth/file.js.map +1 -1
  56. package/dist/auth/index.cjs +11 -0
  57. package/dist/auth/index.d.cts +5 -0
  58. package/dist/auth/index.d.ts +5 -6
  59. package/dist/auth/index.js +6 -27
  60. package/dist/auth/linked-project.cjs +38 -0
  61. package/dist/auth/linked-project.cjs.map +1 -0
  62. package/dist/auth/linked-project.js +30 -64
  63. package/dist/auth/linked-project.js.map +1 -1
  64. package/dist/auth/oauth.cjs +205 -0
  65. package/dist/auth/oauth.cjs.map +1 -0
  66. package/dist/auth/oauth.d.cts +135 -0
  67. package/dist/auth/oauth.d.ts +113 -109
  68. package/dist/auth/oauth.js +185 -252
  69. package/dist/auth/oauth.js.map +1 -1
  70. package/dist/auth/poll-for-token.cjs +82 -0
  71. package/dist/auth/poll-for-token.cjs.map +1 -0
  72. package/dist/auth/poll-for-token.d.cts +28 -0
  73. package/dist/auth/poll-for-token.d.ts +23 -15
  74. package/dist/auth/poll-for-token.js +79 -64
  75. package/dist/auth/poll-for-token.js.map +1 -1
  76. package/dist/auth/project.cjs +178 -0
  77. package/dist/auth/project.cjs.map +1 -0
  78. package/dist/auth/project.d.cts +40 -0
  79. package/dist/auth/project.d.ts +19 -19
  80. package/dist/auth/project.js +169 -72
  81. package/dist/auth/project.js.map +1 -1
  82. package/dist/auth/zod.cjs +22 -0
  83. package/dist/auth/zod.cjs.map +1 -0
  84. package/dist/auth/zod.js +18 -17
  85. package/dist/auth/zod.js.map +1 -1
  86. package/dist/command.cjs +328 -0
  87. package/dist/command.cjs.map +1 -0
  88. package/dist/command.d.cts +289 -0
  89. package/dist/command.d.ts +265 -171
  90. package/dist/command.js +323 -226
  91. package/dist/command.js.map +1 -1
  92. package/dist/constants.d.cts +5 -0
  93. package/dist/constants.d.ts +5 -1
  94. package/dist/filesystem.cjs +499 -0
  95. package/dist/filesystem.cjs.map +1 -0
  96. package/dist/filesystem.d.cts +258 -0
  97. package/dist/filesystem.d.ts +258 -0
  98. package/dist/filesystem.js +497 -0
  99. package/dist/filesystem.js.map +1 -0
  100. package/dist/index.cjs +15 -0
  101. package/dist/index.d.cts +8 -0
  102. package/dist/index.d.ts +8 -6
  103. package/dist/index.js +8 -17
  104. package/dist/network-policy.d.cts +156 -0
  105. package/dist/network-policy.d.ts +88 -28
  106. package/dist/sandbox.cjs +816 -0
  107. package/dist/sandbox.cjs.map +1 -0
  108. package/dist/sandbox.d.cts +2847 -0
  109. package/dist/sandbox.d.ts +2834 -628
  110. package/dist/sandbox.js +808 -557
  111. package/dist/sandbox.js.map +1 -1
  112. package/dist/session.cjs +527 -0
  113. package/dist/session.cjs.map +1 -0
  114. package/dist/session.d.cts +410 -0
  115. package/dist/session.d.ts +403 -368
  116. package/dist/session.js +524 -489
  117. package/dist/session.js.map +1 -1
  118. package/dist/snapshot.cjs +204 -0
  119. package/dist/snapshot.cjs.map +1 -0
  120. package/dist/snapshot.d.cts +161 -0
  121. package/dist/snapshot.d.ts +152 -92
  122. package/dist/snapshot.js +201 -114
  123. package/dist/snapshot.js.map +1 -1
  124. package/dist/utils/array.cjs +17 -0
  125. package/dist/utils/array.cjs.map +1 -0
  126. package/dist/utils/array.js +12 -15
  127. package/dist/utils/array.js.map +1 -1
  128. package/dist/utils/consume-readable.cjs +18 -0
  129. package/dist/utils/consume-readable.cjs.map +1 -0
  130. package/dist/utils/consume-readable.js +13 -12
  131. package/dist/utils/consume-readable.js.map +1 -1
  132. package/dist/utils/decode-base64-url.cjs +15 -0
  133. package/dist/utils/decode-base64-url.cjs.map +1 -0
  134. package/dist/utils/decode-base64-url.js +10 -9
  135. package/dist/utils/decode-base64-url.js.map +1 -1
  136. package/dist/utils/dev-credentials.cjs +142 -0
  137. package/dist/utils/dev-credentials.cjs.map +1 -0
  138. package/dist/utils/dev-credentials.js +126 -184
  139. package/dist/utils/dev-credentials.js.map +1 -1
  140. package/dist/utils/get-credentials.cjs +123 -0
  141. package/dist/utils/get-credentials.cjs.map +1 -0
  142. package/dist/utils/get-credentials.d.cts +21 -0
  143. package/dist/utils/get-credentials.d.ts +19 -61
  144. package/dist/utils/get-credentials.js +106 -140
  145. package/dist/utils/get-credentials.js.map +1 -1
  146. package/dist/utils/log.cjs +25 -0
  147. package/dist/utils/log.cjs.map +1 -0
  148. package/dist/utils/log.js +15 -17
  149. package/dist/utils/log.js.map +1 -1
  150. package/dist/utils/network-policy.cjs +49 -0
  151. package/dist/utils/network-policy.cjs.map +1 -0
  152. package/dist/utils/network-policy.js +42 -77
  153. package/dist/utils/network-policy.js.map +1 -1
  154. package/dist/utils/normalizePath.cjs +27 -0
  155. package/dist/utils/normalizePath.cjs.map +1 -0
  156. package/dist/utils/normalizePath.js +21 -28
  157. package/dist/utils/normalizePath.js.map +1 -1
  158. package/dist/utils/paginator.cjs +41 -0
  159. package/dist/utils/paginator.cjs.map +1 -0
  160. package/dist/utils/paginator.d.cts +16 -0
  161. package/dist/utils/paginator.d.ts +16 -0
  162. package/dist/utils/paginator.js +40 -0
  163. package/dist/utils/paginator.js.map +1 -0
  164. package/dist/utils/resolveSignal.cjs +20 -0
  165. package/dist/utils/resolveSignal.cjs.map +1 -0
  166. package/dist/utils/resolveSignal.d.cts +15 -0
  167. package/dist/utils/resolveSignal.d.ts +12 -10
  168. package/dist/utils/resolveSignal.js +14 -17
  169. package/dist/utils/resolveSignal.js.map +1 -1
  170. package/dist/utils/sandbox-snapshot.cjs +14 -0
  171. package/dist/utils/sandbox-snapshot.cjs.map +1 -0
  172. package/dist/utils/sandbox-snapshot.d.cts +10 -0
  173. package/dist/utils/sandbox-snapshot.d.ts +11 -0
  174. package/dist/utils/sandbox-snapshot.js +14 -0
  175. package/dist/utils/sandbox-snapshot.js.map +1 -0
  176. package/dist/utils/types.cjs +13 -0
  177. package/dist/utils/types.cjs.map +1 -0
  178. package/dist/utils/types.d.cts +11 -0
  179. package/dist/utils/types.d.ts +5 -7
  180. package/dist/utils/types.js +8 -8
  181. package/dist/utils/types.js.map +1 -1
  182. package/dist/version.cjs +7 -0
  183. package/dist/version.cjs.map +1 -0
  184. package/dist/version.js +5 -5
  185. package/dist/version.js.map +1 -1
  186. package/package.json +23 -3
  187. package/dist/api-client/index.js.map +0 -1
  188. package/dist/auth/api.d.ts +0 -6
  189. package/dist/auth/error.d.ts +0 -11
  190. package/dist/auth/index.js.map +0 -1
  191. package/dist/auth/linked-project.d.ts +0 -10
  192. package/dist/auth/zod.d.ts +0 -5
  193. package/dist/constants.js +0 -3
  194. package/dist/constants.js.map +0 -1
  195. package/dist/index.js.map +0 -1
  196. package/dist/network-policy.js +0 -3
  197. package/dist/network-policy.js.map +0 -1
  198. package/dist/utils/array.d.ts +0 -9
  199. package/dist/utils/consume-readable.d.ts +0 -5
  200. package/dist/utils/convert-sandbox.d.ts +0 -6
  201. package/dist/utils/convert-sandbox.js +0 -14
  202. package/dist/utils/convert-sandbox.js.map +0 -1
  203. package/dist/utils/decode-base64-url.d.ts +0 -7
  204. package/dist/utils/dev-credentials.d.ts +0 -37
  205. package/dist/utils/log.d.ts +0 -2
  206. package/dist/utils/network-policy.d.ts +0 -7
  207. package/dist/utils/normalizePath.d.ts +0 -17
  208. package/dist/version.d.ts +0 -1
@@ -1,17 +1,24 @@
1
- import type { SnapshotMetadata } from "./api-client";
2
- import { APIClient } from "./api-client";
3
- import { WithFetchOptions } from "./api-client/api-client";
4
- import { Credentials } from "./utils/get-credentials";
1
+ import { Paginator } from "./utils/paginator.js";
2
+ import { SnapshotMetadata } from "./api-client/validators.js";
3
+ import { APIClient, WithFetchOptions } from "./api-client/api-client.js";
4
+ import "./api-client/index.js";
5
+ import { Credentials } from "./utils/get-credentials.js";
6
+ import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
7
+
8
+ //#region src/snapshot.d.ts
9
+ interface SerializedSnapshot {
10
+ snapshot: SnapshotMetadata;
11
+ }
5
12
  /** @inline */
6
13
  interface GetSnapshotParams {
7
- /**
8
- * Unique identifier of the snapshot.
9
- */
10
- snapshotId: string;
11
- /**
12
- * An AbortSignal to cancel the operation.
13
- */
14
- signal?: AbortSignal;
14
+ /**
15
+ * Unique identifier of the snapshot.
16
+ */
17
+ snapshotId: string;
18
+ /**
19
+ * An AbortSignal to cancel the operation.
20
+ */
21
+ signal?: AbortSignal;
15
22
  }
16
23
  /**
17
24
  * A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes
@@ -19,84 +26,137 @@ interface GetSnapshotParams {
19
26
  * Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.
20
27
  * @hideconstructor
21
28
  */
22
- export declare class Snapshot {
23
- private readonly client;
24
- /**
25
- * Unique ID of this snapshot.
26
- */
27
- get snapshotId(): string;
28
- /**
29
- * The ID the sandbox from which this snapshot was created.
30
- */
31
- get sourceSandboxId(): string;
32
- /**
33
- * The status of the snapshot.
34
- */
35
- get status(): SnapshotMetadata["status"];
36
- /**
37
- * The size of the snapshot in bytes, or null if not available.
38
- */
39
- get sizeBytes(): number;
40
- /**
41
- * The creation date of this snapshot.
42
- */
43
- get createdAt(): Date;
44
- /**
45
- * The expiration date of this snapshot, or undefined if it does not expire.
46
- */
47
- get expiresAt(): Date | undefined;
48
- /**
49
- * Internal metadata about this snapshot.
50
- */
51
- private snapshot;
52
- /**
53
- * Create a new Snapshot instance.
54
- *
55
- * @param client - API client used to communicate with the backend
56
- * @param snapshot - Snapshot metadata
57
- */
58
- constructor({ client, snapshot, }: {
59
- client: APIClient;
60
- snapshot: SnapshotMetadata;
61
- });
62
- /**
63
- * Allow to get a list of snapshots for a team narrowed to the given params.
64
- * It returns both the snapshots and the pagination metadata to allow getting
65
- * the next page of results.
66
- */
67
- static list(params?: Partial<Parameters<APIClient["listSnapshots"]>[0]> & Partial<Credentials> & WithFetchOptions): Promise<import("./api-client/base-client").Parsed<{
68
- pagination: {
69
- count: number;
70
- next: number | null;
71
- prev: number | null;
72
- };
73
- snapshots: {
74
- id: string;
75
- region: string;
76
- status: "failed" | "created" | "deleted";
77
- createdAt: number;
78
- updatedAt: number;
79
- sourceSandboxId: string;
80
- sizeBytes: number;
81
- expiresAt?: number | undefined;
82
- }[];
83
- }>>;
84
- /**
85
- * Retrieve an existing snapshot.
86
- *
87
- * @param params - Get parameters and optional credentials.
88
- * @returns A promise resolving to the {@link Sandbox}.
89
- */
90
- static get(params: GetSnapshotParams | (GetSnapshotParams & Credentials)): Promise<Snapshot>;
91
- /**
92
- * Delete this snapshot.
93
- *
94
- * @param opts - Optional parameters.
95
- * @param opts.signal - An AbortSignal to cancel the operation.
96
- * @returns A promise that resolves once the snapshot has been deleted.
97
- */
98
- delete(opts?: {
99
- signal?: AbortSignal;
100
- }): Promise<void>;
29
+ declare class Snapshot {
30
+ private _client;
31
+ /**
32
+ * Lazily resolve credentials and construct an API client.
33
+ * This is used in step contexts where the Snapshot was deserialized
34
+ * without a client (e.g. when crossing workflow/step boundaries).
35
+ * @internal
36
+ */
37
+ private ensureClient;
38
+ /**
39
+ * Unique ID of this snapshot.
40
+ */
41
+ get snapshotId(): string;
42
+ /**
43
+ * The ID of the session from which this snapshot was created.
44
+ */
45
+ get sourceSessionId(): string;
46
+ /**
47
+ * The status of the snapshot.
48
+ */
49
+ get status(): SnapshotMetadata["status"];
50
+ /**
51
+ * The size of the snapshot in bytes, or null if not available.
52
+ */
53
+ get sizeBytes(): number;
54
+ /**
55
+ * The creation date of this snapshot.
56
+ */
57
+ get createdAt(): Date;
58
+ /**
59
+ * The expiration date of this snapshot, or undefined if it does not expire.
60
+ */
61
+ get expiresAt(): Date | undefined;
62
+ /**
63
+ * Internal metadata about this snapshot.
64
+ */
65
+ private snapshot;
66
+ /**
67
+ * Serialize a Snapshot instance to plain data for @workflow/serde.
68
+ *
69
+ * @param instance - The Snapshot instance to serialize
70
+ * @returns A plain object containing snapshot metadata
71
+ */
72
+ static [WORKFLOW_SERIALIZE](instance: Snapshot): SerializedSnapshot;
73
+ /**
74
+ * Deserialize a Snapshot from serialized data.
75
+ *
76
+ * The deserialized instance uses the serialized metadata synchronously and
77
+ * lazily creates an API client only when methods perform API requests.
78
+ *
79
+ * @param data - The serialized snapshot data
80
+ * @returns The reconstructed Snapshot instance
81
+ */
82
+ static [WORKFLOW_DESERIALIZE](data: SerializedSnapshot): Snapshot;
83
+ constructor({
84
+ client,
85
+ snapshot
86
+ }: {
87
+ client?: APIClient;
88
+ snapshot: SnapshotMetadata;
89
+ });
90
+ /**
91
+ * Allow to get a list of snapshots for a team narrowed to the given params.
92
+ * It returns both the snapshots and the pagination metadata to allow getting
93
+ * the next page of results.
94
+ *
95
+ * The returned object is async-iterable to auto-paginate through all pages:
96
+ *
97
+ * ```ts
98
+ * const result = await Snapshot.list({ name: "my-sandbox" });
99
+ * for await (const snapshot of result) { ... }
100
+ * // or: await result.toArray();
101
+ * // or: for await (const page of result.pages()) { ... }
102
+ * ```
103
+ */
104
+ static list(params?: Partial<Parameters<APIClient["listSnapshots"]>[0]> & Partial<Credentials> & WithFetchOptions): Promise<Paginator<{
105
+ pagination: {
106
+ count: number;
107
+ next: string | null;
108
+ };
109
+ snapshots: {
110
+ status: "failed" | "created" | "deleted";
111
+ region: string;
112
+ createdAt: number;
113
+ updatedAt: number;
114
+ id: string;
115
+ sourceSessionId: string;
116
+ sizeBytes: number;
117
+ expiresAt?: number | undefined;
118
+ }[];
119
+ }, "snapshots">>;
120
+ /**
121
+ * Resolve the current snapshot ID of an existing sandbox by name.
122
+ *
123
+ * Useful to feed into {@link Sandbox.create} as `source.snapshotId` without
124
+ * having to first look up the sandbox yourself.
125
+ *
126
+ * @param name - The name of the source sandbox.
127
+ * @param opts - Optional credentials, fetch override, and abort signal.
128
+ * @returns The current snapshot ID of the named sandbox.
129
+ * @throws If the sandbox has no current snapshot.
130
+ *
131
+ * @example
132
+ * const sandbox = await Sandbox.create({
133
+ * source: {
134
+ * type: "snapshot",
135
+ * snapshotId: await Snapshot.fromSandbox("my-sandbox"),
136
+ * },
137
+ * });
138
+ */
139
+ static fromSandbox(name: string, opts?: Partial<Credentials> & WithFetchOptions & {
140
+ signal?: AbortSignal;
141
+ }): Promise<string>;
142
+ /**
143
+ * Retrieve an existing snapshot.
144
+ *
145
+ * @param params - Get parameters and optional credentials.
146
+ * @returns A promise resolving to the {@link Sandbox}.
147
+ */
148
+ static get(params: GetSnapshotParams | (GetSnapshotParams & Credentials)): Promise<Snapshot>;
149
+ /**
150
+ * Delete this snapshot.
151
+ *
152
+ * @param opts - Optional parameters.
153
+ * @param opts.signal - An AbortSignal to cancel the operation.
154
+ * @returns A promise that resolves once the snapshot has been deleted.
155
+ */
156
+ delete(opts?: {
157
+ signal?: AbortSignal;
158
+ }): Promise<void>;
101
159
  }
102
- export {};
160
+ //#endregion
161
+ export { SerializedSnapshot, Snapshot };
162
+ //# sourceMappingURL=snapshot.d.ts.map
package/dist/snapshot.js CHANGED
@@ -1,116 +1,203 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Snapshot = void 0;
4
- const api_client_1 = require("./api-client");
5
- const get_credentials_1 = require("./utils/get-credentials");
1
+ import { APIClient } from "./api-client/api-client.js";
2
+ import "./api-client/index.js";
3
+ import { getCredentials } from "./utils/get-credentials.js";
4
+ import { attachPaginator } from "./utils/paginator.js";
5
+ import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
6
+
7
+ //#region src/snapshot.ts
6
8
  /**
7
- * A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes
8
- *
9
- * Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.
10
- * @hideconstructor
11
- */
12
- class Snapshot {
13
- /**
14
- * Unique ID of this snapshot.
15
- */
16
- get snapshotId() {
17
- return this.snapshot.id;
18
- }
19
- /**
20
- * The ID the sandbox from which this snapshot was created.
21
- */
22
- get sourceSandboxId() {
23
- return this.snapshot.sourceSandboxId;
24
- }
25
- /**
26
- * The status of the snapshot.
27
- */
28
- get status() {
29
- return this.snapshot.status;
30
- }
31
- /**
32
- * The size of the snapshot in bytes, or null if not available.
33
- */
34
- get sizeBytes() {
35
- return this.snapshot.sizeBytes;
36
- }
37
- /**
38
- * The creation date of this snapshot.
39
- */
40
- get createdAt() {
41
- return new Date(this.snapshot.createdAt);
42
- }
43
- /**
44
- * The expiration date of this snapshot, or undefined if it does not expire.
45
- */
46
- get expiresAt() {
47
- if (this.snapshot.expiresAt === undefined) {
48
- return undefined;
49
- }
50
- return new Date(this.snapshot.expiresAt);
51
- }
52
- /**
53
- * Create a new Snapshot instance.
54
- *
55
- * @param client - API client used to communicate with the backend
56
- * @param snapshot - Snapshot metadata
57
- */
58
- constructor({ client, snapshot, }) {
59
- this.client = client;
60
- this.snapshot = snapshot;
61
- }
62
- /**
63
- * Allow to get a list of snapshots for a team narrowed to the given params.
64
- * It returns both the snapshots and the pagination metadata to allow getting
65
- * the next page of results.
66
- */
67
- static async list(params) {
68
- const credentials = await (0, get_credentials_1.getCredentials)(params);
69
- const client = new api_client_1.APIClient({
70
- teamId: credentials.teamId,
71
- token: credentials.token,
72
- fetch: params?.fetch,
73
- });
74
- return client.listSnapshots({
75
- ...credentials,
76
- ...params,
77
- });
78
- }
79
- /**
80
- * Retrieve an existing snapshot.
81
- *
82
- * @param params - Get parameters and optional credentials.
83
- * @returns A promise resolving to the {@link Sandbox}.
84
- */
85
- static async get(params) {
86
- const credentials = await (0, get_credentials_1.getCredentials)(params);
87
- const client = new api_client_1.APIClient({
88
- teamId: credentials.teamId,
89
- token: credentials.token,
90
- });
91
- const sandbox = await client.getSnapshot({
92
- snapshotId: params.snapshotId,
93
- signal: params.signal,
94
- });
95
- return new Snapshot({
96
- client,
97
- snapshot: sandbox.json.snapshot,
98
- });
99
- }
100
- /**
101
- * Delete this snapshot.
102
- *
103
- * @param opts - Optional parameters.
104
- * @param opts.signal - An AbortSignal to cancel the operation.
105
- * @returns A promise that resolves once the snapshot has been deleted.
106
- */
107
- async delete(opts) {
108
- const response = await this.client.deleteSnapshot({
109
- snapshotId: this.snapshot.id,
110
- signal: opts?.signal,
111
- });
112
- this.snapshot = response.json.snapshot;
113
- }
114
- }
115
- exports.Snapshot = Snapshot;
9
+ * A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes
10
+ *
11
+ * Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.
12
+ * @hideconstructor
13
+ */
14
+ var Snapshot = class Snapshot {
15
+ /**
16
+ * Lazily resolve credentials and construct an API client.
17
+ * This is used in step contexts where the Snapshot was deserialized
18
+ * without a client (e.g. when crossing workflow/step boundaries).
19
+ * @internal
20
+ */
21
+ async ensureClient() {
22
+ "use step";
23
+ if (this._client) return this._client;
24
+ const credentials = await getCredentials();
25
+ this._client = new APIClient({
26
+ teamId: credentials.teamId,
27
+ token: credentials.token
28
+ });
29
+ return this._client;
30
+ }
31
+ /**
32
+ * Unique ID of this snapshot.
33
+ */
34
+ get snapshotId() {
35
+ return this.snapshot.id;
36
+ }
37
+ /**
38
+ * The ID of the session from which this snapshot was created.
39
+ */
40
+ get sourceSessionId() {
41
+ return this.snapshot.sourceSessionId;
42
+ }
43
+ /**
44
+ * The status of the snapshot.
45
+ */
46
+ get status() {
47
+ return this.snapshot.status;
48
+ }
49
+ /**
50
+ * The size of the snapshot in bytes, or null if not available.
51
+ */
52
+ get sizeBytes() {
53
+ return this.snapshot.sizeBytes;
54
+ }
55
+ /**
56
+ * The creation date of this snapshot.
57
+ */
58
+ get createdAt() {
59
+ return new Date(this.snapshot.createdAt);
60
+ }
61
+ /**
62
+ * The expiration date of this snapshot, or undefined if it does not expire.
63
+ */
64
+ get expiresAt() {
65
+ if (this.snapshot.expiresAt === void 0) return;
66
+ return new Date(this.snapshot.expiresAt);
67
+ }
68
+ /**
69
+ * Serialize a Snapshot instance to plain data for @workflow/serde.
70
+ *
71
+ * @param instance - The Snapshot instance to serialize
72
+ * @returns A plain object containing snapshot metadata
73
+ */
74
+ static [WORKFLOW_SERIALIZE](instance) {
75
+ return { snapshot: instance.snapshot };
76
+ }
77
+ /**
78
+ * Deserialize a Snapshot from serialized data.
79
+ *
80
+ * The deserialized instance uses the serialized metadata synchronously and
81
+ * lazily creates an API client only when methods perform API requests.
82
+ *
83
+ * @param data - The serialized snapshot data
84
+ * @returns The reconstructed Snapshot instance
85
+ */
86
+ static [WORKFLOW_DESERIALIZE](data) {
87
+ return new Snapshot({ snapshot: data.snapshot });
88
+ }
89
+ constructor({ client, snapshot }) {
90
+ this._client = null;
91
+ this._client = client ?? null;
92
+ this.snapshot = snapshot;
93
+ }
94
+ /**
95
+ * Allow to get a list of snapshots for a team narrowed to the given params.
96
+ * It returns both the snapshots and the pagination metadata to allow getting
97
+ * the next page of results.
98
+ *
99
+ * The returned object is async-iterable to auto-paginate through all pages:
100
+ *
101
+ * ```ts
102
+ * const result = await Snapshot.list({ name: "my-sandbox" });
103
+ * for await (const snapshot of result) { ... }
104
+ * // or: await result.toArray();
105
+ * // or: for await (const page of result.pages()) { ... }
106
+ * ```
107
+ */
108
+ static async list(params) {
109
+ "use step";
110
+ const credentials = await getCredentials(params);
111
+ const client = new APIClient({
112
+ teamId: credentials.teamId,
113
+ token: credentials.token,
114
+ fetch: params?.fetch
115
+ });
116
+ const fetchPage = async (cursor) => {
117
+ return (await client.listSnapshots({
118
+ ...credentials,
119
+ ...params,
120
+ ...cursor !== void 0 && { cursor }
121
+ })).json;
122
+ };
123
+ return attachPaginator(await fetchPage(params?.cursor), {
124
+ itemsKey: "snapshots",
125
+ fetchNext: fetchPage,
126
+ signal: params?.signal
127
+ });
128
+ }
129
+ /**
130
+ * Resolve the current snapshot ID of an existing sandbox by name.
131
+ *
132
+ * Useful to feed into {@link Sandbox.create} as `source.snapshotId` without
133
+ * having to first look up the sandbox yourself.
134
+ *
135
+ * @param name - The name of the source sandbox.
136
+ * @param opts - Optional credentials, fetch override, and abort signal.
137
+ * @returns The current snapshot ID of the named sandbox.
138
+ * @throws If the sandbox has no current snapshot.
139
+ *
140
+ * @example
141
+ * const sandbox = await Sandbox.create({
142
+ * source: {
143
+ * type: "snapshot",
144
+ * snapshotId: await Snapshot.fromSandbox("my-sandbox"),
145
+ * },
146
+ * });
147
+ */
148
+ static async fromSandbox(name, opts) {
149
+ "use step";
150
+ const credentials = await getCredentials(opts);
151
+ const snapshotId = (await new APIClient({
152
+ teamId: credentials.teamId,
153
+ token: credentials.token,
154
+ fetch: opts?.fetch
155
+ }).getSandbox({
156
+ name,
157
+ projectId: credentials.projectId,
158
+ resume: false,
159
+ signal: opts?.signal
160
+ })).json.sandbox.currentSnapshotId;
161
+ if (!snapshotId) throw new Error(`Sandbox "${name}" has no current snapshot.`);
162
+ return snapshotId;
163
+ }
164
+ /**
165
+ * Retrieve an existing snapshot.
166
+ *
167
+ * @param params - Get parameters and optional credentials.
168
+ * @returns A promise resolving to the {@link Sandbox}.
169
+ */
170
+ static async get(params) {
171
+ "use step";
172
+ const credentials = await getCredentials(params);
173
+ const client = new APIClient({
174
+ teamId: credentials.teamId,
175
+ token: credentials.token
176
+ });
177
+ return new Snapshot({
178
+ client,
179
+ snapshot: (await client.getSnapshot({
180
+ snapshotId: params.snapshotId,
181
+ signal: params.signal
182
+ })).json.snapshot
183
+ });
184
+ }
185
+ /**
186
+ * Delete this snapshot.
187
+ *
188
+ * @param opts - Optional parameters.
189
+ * @param opts.signal - An AbortSignal to cancel the operation.
190
+ * @returns A promise that resolves once the snapshot has been deleted.
191
+ */
192
+ async delete(opts) {
193
+ "use step";
194
+ this.snapshot = (await (await this.ensureClient()).deleteSnapshot({
195
+ snapshotId: this.snapshot.id,
196
+ signal: opts?.signal
197
+ })).json.snapshot;
198
+ }
199
+ };
200
+
201
+ //#endregion
202
+ export { Snapshot };
116
203
  //# sourceMappingURL=snapshot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AAEzC,6DAAsE;AActE;;;;;GAKG;AACH,MAAa,QAAQ;IAGnB;;OAEG;IACH,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAW,eAAe;QACxB,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAClB,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAClB,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YAC1C,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3C,CAAC;IAOD;;;;;OAKG;IACH,YAAY,EACV,MAAM,EACN,QAAQ,GAIT;QACC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,CACf,MAEkB;QAElB,MAAM,WAAW,GAAG,MAAM,IAAA,gCAAc,EAAC,MAAM,CAAC,CAAC;QACjD,MAAM,MAAM,GAAG,IAAI,sBAAS,CAAC;YAC3B,MAAM,EAAE,WAAW,CAAC,MAAM;YAC1B,KAAK,EAAE,WAAW,CAAC,KAAK;YACxB,KAAK,EAAE,MAAM,EAAE,KAAK;SACrB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,aAAa,CAAC;YAC1B,GAAG,WAAW;YACd,GAAG,MAAM;SACV,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,CACd,MAA6D;QAE7D,MAAM,WAAW,GAAG,MAAM,IAAA,gCAAc,EAAC,MAAM,CAAC,CAAC;QACjD,MAAM,MAAM,GAAG,IAAI,sBAAS,CAAC;YAC3B,MAAM,EAAE,WAAW,CAAC,MAAM;YAC1B,KAAK,EAAE,WAAW,CAAC,KAAK;SACzB,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC;YACvC,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC,CAAC;QAEH,OAAO,IAAI,QAAQ,CAAC;YAClB,MAAM;YACN,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ;SAChC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,CAAC,IAA+B;QAC1C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;YAChD,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE;YAC5B,MAAM,EAAE,IAAI,EAAE,MAAM;SACrB,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;IACzC,CAAC;CACF;AAtID,4BAsIC"}
1
+ {"version":3,"file":"snapshot.js","names":[],"sources":["../src/snapshot.ts"],"sourcesContent":["import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from \"@workflow/serde\";\nimport type { WithFetchOptions } from \"./api-client/api-client.js\";\nimport type { SnapshotMetadata } from \"./api-client/index.js\";\nimport { APIClient } from \"./api-client/index.js\";\nimport { type Credentials, getCredentials } from \"./utils/get-credentials.js\";\nimport { attachPaginator } from \"./utils/paginator.js\";\n\nexport interface SerializedSnapshot {\n snapshot: SnapshotMetadata;\n}\n\n/** @inline */\ninterface GetSnapshotParams {\n /**\n * Unique identifier of the snapshot.\n */\n snapshotId: string;\n /**\n * An AbortSignal to cancel the operation.\n */\n signal?: AbortSignal;\n}\n\n/**\n * A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes\n *\n * Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.\n * @hideconstructor\n */\nexport class Snapshot {\n private _client: APIClient | null = null;\n\n /**\n * Lazily resolve credentials and construct an API client.\n * This is used in step contexts where the Snapshot was deserialized\n * without a client (e.g. when crossing workflow/step boundaries).\n * @internal\n */\n private async ensureClient(): Promise<APIClient> {\n \"use step\";\n if (this._client) return this._client;\n const credentials = await getCredentials();\n this._client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n });\n return this._client;\n }\n\n /**\n * Unique ID of this snapshot.\n */\n public get snapshotId(): string {\n return this.snapshot.id;\n }\n\n /**\n * The ID of the session from which this snapshot was created.\n */\n public get sourceSessionId(): string {\n return this.snapshot.sourceSessionId;\n }\n\n /**\n * The status of the snapshot.\n */\n public get status(): SnapshotMetadata[\"status\"] {\n return this.snapshot.status;\n }\n\n /**\n * The size of the snapshot in bytes, or null if not available.\n */\n public get sizeBytes(): number {\n return this.snapshot.sizeBytes;\n }\n\n /**\n * The creation date of this snapshot.\n */\n public get createdAt(): Date {\n return new Date(this.snapshot.createdAt);\n }\n\n /**\n * The expiration date of this snapshot, or undefined if it does not expire.\n */\n public get expiresAt(): Date | undefined {\n if (this.snapshot.expiresAt === undefined) {\n return undefined;\n }\n\n return new Date(this.snapshot.expiresAt);\n }\n\n /**\n * Internal metadata about this snapshot.\n */\n private snapshot: SnapshotMetadata;\n\n /**\n * Serialize a Snapshot instance to plain data for @workflow/serde.\n *\n * @param instance - The Snapshot instance to serialize\n * @returns A plain object containing snapshot metadata\n */\n static [WORKFLOW_SERIALIZE](instance: Snapshot): SerializedSnapshot {\n return {\n snapshot: instance.snapshot,\n };\n }\n\n /**\n * Deserialize a Snapshot from serialized data.\n *\n * The deserialized instance uses the serialized metadata synchronously and\n * lazily creates an API client only when methods perform API requests.\n *\n * @param data - The serialized snapshot data\n * @returns The reconstructed Snapshot instance\n */\n static [WORKFLOW_DESERIALIZE](data: SerializedSnapshot): Snapshot {\n return new Snapshot({\n snapshot: data.snapshot,\n });\n }\n\n constructor({\n client,\n snapshot,\n }: {\n client?: APIClient;\n snapshot: SnapshotMetadata;\n }) {\n this._client = client ?? null;\n this.snapshot = snapshot;\n }\n\n /**\n * Allow to get a list of snapshots for a team narrowed to the given params.\n * It returns both the snapshots and the pagination metadata to allow getting\n * the next page of results.\n *\n * The returned object is async-iterable to auto-paginate through all pages:\n *\n * ```ts\n * const result = await Snapshot.list({ name: \"my-sandbox\" });\n * for await (const snapshot of result) { ... }\n * // or: await result.toArray();\n * // or: for await (const page of result.pages()) { ... }\n * ```\n */\n static async list(\n params?: Partial<Parameters<APIClient[\"listSnapshots\"]>[0]> &\n Partial<Credentials> &\n WithFetchOptions,\n ) {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params?.fetch,\n });\n const fetchPage = async (cursor?: string) => {\n const response = await client.listSnapshots({\n ...credentials,\n ...params,\n ...(cursor !== undefined && { cursor }),\n });\n return response.json;\n };\n const firstPage = await fetchPage(params?.cursor);\n return attachPaginator(firstPage, {\n itemsKey: \"snapshots\",\n fetchNext: fetchPage,\n signal: params?.signal,\n });\n }\n\n /**\n * Resolve the current snapshot ID of an existing sandbox by name.\n *\n * Useful to feed into {@link Sandbox.create} as `source.snapshotId` without\n * having to first look up the sandbox yourself.\n *\n * @param name - The name of the source sandbox.\n * @param opts - Optional credentials, fetch override, and abort signal.\n * @returns The current snapshot ID of the named sandbox.\n * @throws If the sandbox has no current snapshot.\n *\n * @example\n * const sandbox = await Sandbox.create({\n * source: {\n * type: \"snapshot\",\n * snapshotId: await Snapshot.fromSandbox(\"my-sandbox\"),\n * },\n * });\n */\n static async fromSandbox(\n name: string,\n opts?: Partial<Credentials> & WithFetchOptions & { signal?: AbortSignal },\n ): Promise<string> {\n \"use step\";\n const credentials = await getCredentials(opts);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: opts?.fetch,\n });\n\n const response = await client.getSandbox({\n name,\n projectId: credentials.projectId,\n resume: false,\n signal: opts?.signal,\n });\n\n const snapshotId = response.json.sandbox.currentSnapshotId;\n if (!snapshotId) {\n throw new Error(`Sandbox \"${name}\" has no current snapshot.`);\n }\n return snapshotId;\n }\n\n /**\n * Retrieve an existing snapshot.\n *\n * @param params - Get parameters and optional credentials.\n * @returns A promise resolving to the {@link Sandbox}.\n */\n static async get(\n params: GetSnapshotParams | (GetSnapshotParams & Credentials),\n ): Promise<Snapshot> {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n });\n\n const sandbox = await client.getSnapshot({\n snapshotId: params.snapshotId,\n signal: params.signal,\n });\n\n return new Snapshot({\n client,\n snapshot: sandbox.json.snapshot,\n });\n }\n\n /**\n * Delete this snapshot.\n *\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves once the snapshot has been deleted.\n */\n async delete(opts?: { signal?: AbortSignal }): Promise<void> {\n \"use step\";\n const client = await this.ensureClient();\n const response = await client.deleteSnapshot({\n snapshotId: this.snapshot.id,\n signal: opts?.signal,\n });\n\n this.snapshot = response.json.snapshot;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA6BA,IAAa,WAAb,MAAa,SAAS;;;;;;;CASpB,MAAc,eAAmC;AAC/C;AACA,MAAI,KAAK,QAAS,QAAO,KAAK;EAC9B,MAAM,cAAc,MAAM,gBAAgB;AAC1C,OAAK,UAAU,IAAI,UAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACpB,CAAC;AACF,SAAO,KAAK;;;;;CAMd,IAAW,aAAqB;AAC9B,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,kBAA0B;AACnC,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,SAAqC;AAC9C,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,YAAoB;AAC7B,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,YAAkB;AAC3B,SAAO,IAAI,KAAK,KAAK,SAAS,UAAU;;;;;CAM1C,IAAW,YAA8B;AACvC,MAAI,KAAK,SAAS,cAAc,OAC9B;AAGF,SAAO,IAAI,KAAK,KAAK,SAAS,UAAU;;;;;;;;CAc1C,QAAQ,oBAAoB,UAAwC;AAClE,SAAO,EACL,UAAU,SAAS,UACpB;;;;;;;;;;;CAYH,QAAQ,sBAAsB,MAAoC;AAChE,SAAO,IAAI,SAAS,EAClB,UAAU,KAAK,UAChB,CAAC;;CAGJ,YAAY,EACV,QACA,YAIC;OAvGK,UAA4B;AAwGlC,OAAK,UAAU,UAAU;AACzB,OAAK,WAAW;;;;;;;;;;;;;;;;CAiBlB,aAAa,KACX,QAGA;AACA;EACA,MAAM,cAAc,MAAM,eAAe,OAAO;EAChD,MAAM,SAAS,IAAI,UAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACnB,OAAO,QAAQ;GAChB,CAAC;EACF,MAAM,YAAY,OAAO,WAAoB;AAM3C,WALiB,MAAM,OAAO,cAAc;IAC1C,GAAG;IACH,GAAG;IACH,GAAI,WAAW,UAAa,EAAE,QAAQ;IACvC,CAAC,EACc;;AAGlB,SAAO,gBADW,MAAM,UAAU,QAAQ,OAAO,EACf;GAChC,UAAU;GACV,WAAW;GACX,QAAQ,QAAQ;GACjB,CAAC;;;;;;;;;;;;;;;;;;;;;CAsBJ,aAAa,YACX,MACA,MACiB;AACjB;EACA,MAAM,cAAc,MAAM,eAAe,KAAK;EAc9C,MAAM,cAPW,MANF,IAAI,UAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACnB,OAAO,MAAM;GACd,CAAC,CAE4B,WAAW;GACvC;GACA,WAAW,YAAY;GACvB,QAAQ;GACR,QAAQ,MAAM;GACf,CAAC,EAE0B,KAAK,QAAQ;AACzC,MAAI,CAAC,WACH,OAAM,IAAI,MAAM,YAAY,KAAK,4BAA4B;AAE/D,SAAO;;;;;;;;CAST,aAAa,IACX,QACmB;AACnB;EACA,MAAM,cAAc,MAAM,eAAe,OAAO;EAChD,MAAM,SAAS,IAAI,UAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACpB,CAAC;AAOF,SAAO,IAAI,SAAS;GAClB;GACA,WAPc,MAAM,OAAO,YAAY;IACvC,YAAY,OAAO;IACnB,QAAQ,OAAO;IAChB,CAAC,EAIkB,KAAK;GACxB,CAAC;;;;;;;;;CAUJ,MAAM,OAAO,MAAgD;AAC3D;AAOA,OAAK,YALY,OADF,MAAM,KAAK,cAAc,EACV,eAAe;GAC3C,YAAY,KAAK,SAAS;GAC1B,QAAQ,MAAM;GACf,CAAC,EAEuB,KAAK"}
@@ -0,0 +1,17 @@
1
+
2
+ //#region src/utils/array.ts
3
+ /**
4
+ * Returns an array from the given item. If the item is an array it will be
5
+ * returned as a it is, otherwise it will be returned as a single item array.
6
+ * If the item is undefined or null an empty array will be returned.
7
+ *
8
+ * @param item The item to convert to an array.
9
+ * @returns An array.
10
+ */
11
+ function array(item) {
12
+ return item !== void 0 && item !== null ? Array.isArray(item) ? item : [item] : [];
13
+ }
14
+
15
+ //#endregion
16
+ exports.array = array;
17
+ //# sourceMappingURL=array.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.cjs","names":[],"sources":["../../src/utils/array.ts"],"sourcesContent":["/**\n * Returns an array from the given item. If the item is an array it will be\n * returned as a it is, otherwise it will be returned as a single item array.\n * If the item is undefined or null an empty array will be returned.\n *\n * @param item The item to convert to an array.\n * @returns An array.\n */\nexport function array<T>(item?: null | T | T[]): T[] {\n return item !== undefined && item !== null\n ? Array.isArray(item)\n ? item\n : [item]\n : [];\n}\n"],"mappings":";;;;;;;;;;AAQA,SAAgB,MAAS,MAA4B;AACnD,QAAO,SAAS,UAAa,SAAS,OAClC,MAAM,QAAQ,KAAK,GACjB,OACA,CAAC,KAAK,GACR,EAAE"}