@diagonal-hq/cli 0.18.0 → 0.19.1

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/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import './globals';
2
+ import type { WorkflowContext } from '@diagonal/workflow';
3
+
2
4
  import type { BrandKit } from './brand-kit.generated';
3
5
  import type { ResourceCapabilities } from './capabilities.generated';
4
6
  import type {
@@ -1199,3 +1201,113 @@ export type NotificationScheduleDefinition = UidOption & {
1199
1201
  export declare function defineNotificationSchedule<const T extends NotificationScheduleDefinition>(
1200
1202
  schedule: T
1201
1203
  ): T;
1204
+
1205
+ /**
1206
+ * The default export of `tests/<suite>/suite.ts`. Each other `.ts` file in the folder is one test
1207
+ * of the suite.
1208
+ */
1209
+ export type TestSuiteDefinition = UidOption & {
1210
+ /** Up to 255 characters. Default: the folder name, such as `Member signup` for `member-signup`. */
1211
+ name?: string;
1212
+ /** Up to 5,000 characters. */
1213
+ description?: string | null;
1214
+ };
1215
+
1216
+ export declare function defineTestSuite<const T extends TestSuiteDefinition>(suite: T): T;
1217
+
1218
+ /**
1219
+ * The config of one E2E test. The build reads it as static data. A test has no `uid`: its file
1220
+ * name is its identity in its suite.
1221
+ */
1222
+ export type TestConfig = {
1223
+ /** Up to 255 characters. Default: the file name, such as `Upcoming events` for `upcomingEvents.ts`. */
1224
+ name?: string;
1225
+ /** Up to 5,000 characters. */
1226
+ description?: string | null;
1227
+ /** A disabled test stays in the suite and does not run. Default: true. */
1228
+ enabled?: boolean;
1229
+ /** The time limit of setup, test, and assert together: 1 to 600. */
1230
+ timeoutSeconds?: number | null;
1231
+ };
1232
+
1233
+ type TestSignInTarget =
1234
+ | ({ id: string } & Record<string, unknown>)
1235
+ | { resource: string; id: string };
1236
+
1237
+ /** `Sdk` in the test function. `setup` is the object that the setup function returned. */
1238
+ export type TestSdk<S> = {
1239
+ /** The workspace that the run acts on. */
1240
+ readonly workspace: { readonly id: string; readonly name: string; readonly baseUrl: string };
1241
+ /** An absolute URL on the run's workspace. */
1242
+ url(path?: string): string;
1243
+ /** The object that setup returned, or `{}` without a setup function. */
1244
+ readonly setup: S;
1245
+ /** Signs `page` in as a record that setup returned, or as `{ resource, id }`, then opens `redirectTo` (default `/`). */
1246
+ loginAs(record: TestSignInTarget, options?: { redirectTo?: string }): Promise<void>;
1247
+ /** Opens a second browser signed in as another record and returns its page. */
1248
+ newPageAs(
1249
+ record: TestSignInTarget,
1250
+ options?: { redirectTo?: string }
1251
+ ): Promise<import('@playwright/test').Page>;
1252
+ /** The workspace's resources by name, such as `Sdk.resources.Members`. */
1253
+ readonly resources: Readonly<Record<string, string>>;
1254
+ /**
1255
+ * Simulated Stripe of the run's workspace. `redeliverEvents` sends its events through the
1256
+ * webhook handling again, oldest first, optionally only one `type`, and returns what it sent.
1257
+ */
1258
+ readonly stripe: {
1259
+ redeliverEvents(options?: {
1260
+ type?: string;
1261
+ }): Promise<Array<{ readonly id: string; readonly type: string }>>;
1262
+ };
1263
+ /** Workflow script SDK date helpers, such as `await Sdk.date.add({ date, value: 7, unit: 'days' })`. */
1264
+ readonly date: typeof import('@diagonal/workflow').date;
1265
+ /** Workflow script SDK date-time helpers. */
1266
+ readonly time: typeof import('@diagonal/workflow').time;
1267
+ /** Workflow script SDK timezone helpers. */
1268
+ readonly timezone: typeof import('@diagonal/workflow').timezone;
1269
+ /** Formats a money value as the platform does. */
1270
+ readonly money: typeof import('@diagonal/workflow').money;
1271
+ /** Formats a number as the platform does. */
1272
+ readonly number: typeof import('@diagonal/workflow').number;
1273
+ /** Formats a phone number as the platform does. */
1274
+ readonly phone: typeof import('@diagonal/workflow').phone;
1275
+ };
1276
+
1277
+ /** The values that the runner gives the test function. */
1278
+ export type TestFixtures<S> = {
1279
+ page: import('@playwright/test').Page;
1280
+ context: import('@playwright/test').BrowserContext;
1281
+ request: import('@playwright/test').APIRequestContext;
1282
+ browser: import('@playwright/test').Browser;
1283
+ expect: import('@playwright/test').Expect;
1284
+ Sdk: TestSdk<S>;
1285
+ };
1286
+
1287
+ /**
1288
+ * The functions of a test. `setup` and `assert` are workflow handlers without a config: the build
1289
+ * compiles each one as `defineWorkflow(handler)` of `@diagonal-hq/workflows/test`, and the run
1290
+ * executes it once in the test workspace as an embedded script. It runs as the acting account,
1291
+ * with no trigger, no `runAs`, and no `input` schema, so its input is fixed. To act as another
1292
+ * identity, call `workflow.run` with a workflow that sets Run As. `test` runs in the browser runner
1293
+ * as the body of a Playwright test, so it can use only its fixtures: no import or helper of its file.
1294
+ */
1295
+ export type TestHandlers<S> = {
1296
+ /** Creates the records that the test needs and returns them. Its input is `{}`. */
1297
+ setup?: (input: Record<string, never>, ctx: WorkflowContext) => S | Promise<S>;
1298
+ test: (fixtures: TestFixtures<Awaited<S>>) => Promise<void>;
1299
+ /**
1300
+ * Reads the records after the test, and calls `fail(...)` when a value is wrong. Its input is
1301
+ * the object that `setup` returned, or `{}` without a setup.
1302
+ */
1303
+ assert?: (setup: Awaited<S>, ctx: WorkflowContext) => void | Promise<void>;
1304
+ };
1305
+
1306
+ /**
1307
+ * The default export of `tests/<suite>/<key>.ts`, one E2E test of the suite in the folder. The
1308
+ * file name is the test key.
1309
+ */
1310
+ export declare function defineTest<S = Record<string, never>>(
1311
+ config: TestConfig,
1312
+ handlers: TestHandlers<S>
1313
+ ): { readonly config: TestConfig } & TestHandlers<S>;
package/dist/index.js CHANGED
@@ -44,6 +44,10 @@ export const defineEmailLayout = (layout) => layout;
44
44
 
45
45
  export const defineNotificationSchedule = (schedule) => schedule;
46
46
 
47
+ export const defineTestSuite = (suite) => suite;
48
+
49
+ export const defineTest = (config, handlers) => ({ config, ...handlers });
50
+
47
51
  export { field } from './fields.generated.js';
48
52
 
49
53
  export { SystemPermissions, SystemRoles } from './system-authorization.generated.js';
@@ -7607,8 +7607,10 @@ type SdkHooks = {
7607
7607
  /** Include every creatable field, ignoring per-field `show_on_creating` form
7608
7608
  * visibility. Still excludes system/virtual fields and respects field access. */
7609
7609
  includeAllFields?: boolean;
7610
- /** How relation fields resolve inline attach/create. Defaults to `'settings'`;
7611
- * pass `'always'` to force them on. */
7610
+ /** How relation fields resolve inline attach/create. Explicit `'settings'` uses only
7611
+ * the field's stored settings. When omitted, a relation listed in `fields` gets inline
7612
+ * attach on and inline create per its settings; without `fields` the stored settings
7613
+ * apply. `'always'` forces both on. */
7612
7614
  relationVisibility?: RelationVisibility;
7613
7615
  /** Send a booking idempotency key, kept across retries of the same values. Defaults to
7614
7616
  * `false`. Submitting throws when the resource has no booking idempotency field. */
@@ -7667,8 +7669,10 @@ type SdkHooks = {
7667
7669
  /** Include every updatable field, ignoring per-field `show_on_updating` form
7668
7670
  * visibility. Still excludes system/virtual fields and respects field access. */
7669
7671
  includeAllFields?: boolean;
7670
- /** How relation fields resolve inline attach/create. Defaults to `'settings'`;
7671
- * pass `'always'` to force them on. */
7672
+ /** How relation fields resolve inline attach/create. Explicit `'settings'` uses only
7673
+ * the field's stored settings. When omitted, a relation listed in `fields` gets inline
7674
+ * attach on and inline create per its settings; without `fields` the stored settings
7675
+ * apply. `'always'` forces both on. */
7672
7676
  relationVisibility?: RelationVisibility;
7673
7677
  onSuccess?: (record: ResourceRecord) => void;
7674
7678
  }): UseUpdateResourceRecordFormResult;
@@ -10189,8 +10193,12 @@ type CreateResourceRecordFormProps<TResource extends CreateFormResource = Create
10189
10193
  * identity may store them. */
10190
10194
  includeSystemManagedRelationKeys?: string[];
10191
10195
 
10192
- /** How relation fields resolve inline attach/create. Defaults to `'settings'`;
10193
- * pass `'always'` to force them on. */
10196
+ /** How relation fields resolve inline attach/create. Explicit `'settings'` uses only
10197
+ * the field's stored `allow_inline_*` settings. When omitted, a relation listed in
10198
+ * `fields` gets inline attach enabled; inline create still follows its settings.
10199
+ * Without `fields`, omitted visibility uses the stored settings.
10200
+ * `'always'` enables both inline attach and create. `'attach-only'` enables inline
10201
+ * attach and disables inline create. */
10194
10202
  relationVisibility?: RelationVisibility;
10195
10203
 
10196
10204
  /** Render the resource's published `created`/`saved` RecordEvent workflow inputs in the
@@ -13939,8 +13947,12 @@ type UpdateResourceRecordFormProps<TResource extends UpdateFormResource = Update
13939
13947
  * explicit `fields` are provided. */
13940
13948
  includeAllFields?: boolean;
13941
13949
 
13942
- /** How relation fields resolve inline attach/create. Defaults to `'settings'`;
13943
- * pass `'always'` to force them on. */
13950
+ /** How relation fields resolve inline attach/create. Explicit `'settings'` uses only
13951
+ * the field's stored `allow_inline_*` settings. When omitted, a relation listed in
13952
+ * `fields` gets inline attach enabled; inline create still follows its settings.
13953
+ * Without `fields`, omitted visibility uses the stored settings.
13954
+ * `'always'` enables both inline attach and create. `'attach-only'` enables inline
13955
+ * attach and disables inline create. */
13944
13956
  relationVisibility?: RelationVisibility;
13945
13957
 
13946
13958
  /** Render the resource's published `updated`/`saved` RecordEvent workflow inputs in the
@@ -60,20 +60,14 @@ export declare const data: {
60
60
  create: <R extends ResourceKey>(input: Omit<DataCreateInput, "resource" | "data"> & {
61
61
  resource: R;
62
62
  data: InputOf<R>;
63
- }) => Promise<{
64
- id: string;
65
- } & Record<string, unknown>>;
63
+ }) => Promise<RecordOf<R>>;
66
64
  find: <R extends ResourceKey>(input: Omit<DataFindInput, "resource"> & {
67
65
  resource: R;
68
- }) => Promise<{
69
- id: string;
70
- } & Record<string, unknown>>;
66
+ }) => Promise<RecordOf<R>>;
71
67
  update: <R extends ResourceKey>(input: Omit<DataUpdateInput, "resource" | "data"> & {
72
68
  resource: R;
73
69
  data: InputOf<R>;
74
- }) => Promise<{
75
- id: string;
76
- } & Record<string, unknown>>;
70
+ }) => Promise<RecordOf<R>>;
77
71
  /**
78
72
  * One page of the records that the search matches: 50 records by default, and at most 100 with
79
73
  * `pageSize`. To read every match, use `data.each`, which requests the pages for you.
@@ -84,34 +78,24 @@ export declare const data: {
84
78
  each: typeof each;
85
79
  delete: <R extends ResourceKey>(input: Omit<DataDeleteInput, "resource"> & {
86
80
  resource: R;
87
- }) => Promise<{
88
- id: string;
89
- } & Record<string, unknown>>;
81
+ }) => Promise<RecordOf<R>>;
90
82
  restore: <R extends ResourceKey>(input: Omit<DataRestoreInput, "resource"> & {
91
83
  resource: R;
92
- }) => Promise<{
93
- id: string;
94
- } & Record<string, unknown>>;
84
+ }) => Promise<RecordOf<R>>;
95
85
  count: <R extends ResourceKey>(input: Omit<DataCountInput, "resource"> & {
96
86
  resource: R;
97
87
  }) => Promise<number>;
98
88
  findOrCreate: <R extends ResourceKey>(input: Omit<DataFindOrCreateInput, "resource"> & {
99
89
  resource: R;
100
- }) => Promise<{
101
- id: string;
102
- } & Record<string, unknown>>;
90
+ }) => Promise<RecordOf<R>>;
103
91
  updateOrCreate: <R extends ResourceKey>(input: Omit<DataUpdateOrCreateInput, "resource"> & {
104
92
  resource: R;
105
- }) => Promise<{
106
- id: string;
107
- } & Record<string, unknown>>;
93
+ }) => Promise<RecordOf<R>>;
108
94
  /** Create all of `records` in one call. The call has no limit on the number of records. */
109
95
  createMany: <R extends ResourceKey>(input: Omit<DataCreateManyInput, "resource" | "records"> & {
110
96
  resource: R;
111
97
  records: Array<InputOf<R>>;
112
- }) => Promise<({
113
- id: string;
114
- } & Record<string, unknown>)[]>;
98
+ }) => Promise<Array<RecordOf<R>>>;
115
99
  deleteMany: <R extends ResourceKey>(input: Omit<DataDeleteManyInput, "resource"> & {
116
100
  resource: R;
117
101
  }) => Promise<DataDeleteManyOutput>;
@@ -1,6 +1,6 @@
1
1
  import type { ResourceKeyWith } from '../data';
2
2
  import type { ContentDocument } from '../input';
3
- export declare const SDK_VERSION = 65;
3
+ export declare const SDK_VERSION = 66;
4
4
  export interface WorkspaceSystemFields {
5
5
  "ai_custom_system_prompt": string | null;
6
6
  "brand_kit": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/cli",
3
- "version": "0.18.0",
3
+ "version": "0.19.1",
4
4
  "description": "The diagonal CLI and the configuration helpers for file-based Diagonal workspaces.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {