@devvit/public-api 0.11.0-next-2024-07-29-74c4bb837.0 → 0.11.0-next-2024-07-30-8f65a4fa6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,8 @@
1
1
  import type { Metadata, ValidateFormRequest } from '@devvit/protos';
2
2
  import { ValidateFormResponse } from '@devvit/protos';
3
- import type { SettingsFormField } from '../../../types/settings.js';
3
+ import type { SettingsFormField, SettingsFormFieldGroup } from '../../../types/settings.js';
4
+ type SettingsPlainField = Exclude<SettingsFormField, SettingsFormFieldGroup>;
5
+ export declare function extractSettingsFields(settings: SettingsFormField[]): SettingsPlainField[];
4
6
  export declare function onValidateFormHelper(req: ValidateFormRequest, settings: SettingsFormField[] | undefined, metadata: Metadata): Promise<ValidateFormResponse>;
7
+ export {};
5
8
  //# sourceMappingURL=settingsUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"settingsUtils.d.ts","sourceRoot":"","sources":["../../../../src/devvit/internals/helpers/settingsUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAGtD,OAAO,KAAK,EAAqB,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAGvF,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,mBAAmB,EACxB,QAAQ,EAAE,iBAAiB,EAAE,GAAG,SAAS,EACzC,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,oBAAoB,CAAC,CAoD/B"}
1
+ {"version":3,"file":"settingsUtils.d.ts","sourceRoot":"","sources":["../../../../src/devvit/internals/helpers/settingsUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAGtD,OAAO,KAAK,EAEV,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AAGpC,KAAK,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,EAAE,sBAAsB,CAAC,CAAC;AAE7E,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,iBAAiB,EAAE,GAAG,kBAAkB,EAAE,CAOzF;AAED,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,mBAAmB,EACxB,QAAQ,EAAE,iBAAiB,EAAE,GAAG,SAAS,EACzC,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,oBAAoB,CAAC,CA8C/B"}
@@ -2,6 +2,14 @@ import { ValidateFormResponse } from '@devvit/protos';
2
2
  import { makeAPIClients } from '../../../apis/makeAPIClients.js';
3
3
  import { getFormValues } from '../../../apis/ui/helpers/getFormValues.js';
4
4
  import { getContextFromMetadata } from '../context.js';
5
+ export function extractSettingsFields(settings) {
6
+ return settings.flatMap((field) => {
7
+ if (field.type === 'group') {
8
+ return extractSettingsFields(field.fields);
9
+ }
10
+ return field;
11
+ });
12
+ }
5
13
  export async function onValidateFormHelper(req, settings, metadata) {
6
14
  if (!settings) {
7
15
  throw new Error('Settings were not defined.');
@@ -11,16 +19,11 @@ export async function onValidateFormHelper(req, settings, metadata) {
11
19
  errors: {},
12
20
  });
13
21
  const formValues = getFormValues(req.fieldValues);
14
- const flattendFields = settings.flatMap((field) => {
15
- if (field.type === 'group') {
16
- return field.fields;
17
- }
18
- return field;
19
- });
22
+ const flattendFields = extractSettingsFields(settings);
20
23
  await Promise.all(flattendFields.map(async (field) => {
21
24
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
25
  const fieldName = field.name;
23
- if (fieldName && field.type !== 'group' && field.onValidate) {
26
+ if (fieldName && field.onValidate) {
24
27
  const value = formValues[fieldName];
25
28
  const validator = field.onValidate;
26
29
  const context = Object.assign(makeAPIClients({
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settingsUtils.test.d.ts","sourceRoot":"","sources":["../../../../src/devvit/internals/helpers/settingsUtils.test.ts"],"names":[],"mappings":""}
package/meta.json CHANGED
@@ -11686,7 +11686,7 @@
11686
11686
  "format": "esm"
11687
11687
  },
11688
11688
  "src/devvit/internals/helpers/settingsUtils.ts": {
11689
- "bytes": 1828,
11689
+ "bytes": 2073,
11690
11690
  "imports": [
11691
11691
  {
11692
11692
  "path": "../protos/dist/index.js",
@@ -14331,7 +14331,7 @@
14331
14331
  "bytesInOutput": 1701
14332
14332
  },
14333
14333
  "src/devvit/internals/helpers/settingsUtils.ts": {
14334
- "bytesInOutput": 1229
14334
+ "bytesInOutput": 1319
14335
14335
  },
14336
14336
  "src/devvit/internals/app-settings.ts": {
14337
14337
  "bytesInOutput": 614
@@ -14508,7 +14508,7 @@
14508
14508
  "bytesInOutput": 4358
14509
14509
  }
14510
14510
  },
14511
- "bytes": 14784775
14511
+ "bytes": 14785277
14512
14512
  }
14513
14513
  }
14514
14514
  }
package/meta.min.json CHANGED
@@ -3015,7 +3015,7 @@
3015
3015
  "format": "esm"
3016
3016
  },
3017
3017
  "src/devvit/internals/helpers/settingsUtils.ts": {
3018
- "bytes": 1828,
3018
+ "bytes": 2073,
3019
3019
  "imports": [
3020
3020
  {
3021
3021
  "path": "@devvit/protos",
@@ -4716,7 +4716,7 @@
4716
4716
  "imports": [],
4717
4717
  "exports": [],
4718
4718
  "inputs": {},
4719
- "bytes": 1185976
4719
+ "bytes": 1186306
4720
4720
  },
4721
4721
  "dist/public-api.min.js": {
4722
4722
  "imports": [
@@ -5293,7 +5293,7 @@
5293
5293
  "bytesInOutput": 33
5294
5294
  },
5295
5295
  "src/devvit/internals/helpers/settingsUtils.ts": {
5296
- "bytesInOutput": 480
5296
+ "bytesInOutput": 494
5297
5297
  },
5298
5298
  "src/devvit/internals/blocks/useChannel.ts": {
5299
5299
  "bytesInOutput": 1537
@@ -5527,7 +5527,7 @@
5527
5527
  "bytesInOutput": 2083
5528
5528
  }
5529
5529
  },
5530
- "bytes": 251828
5530
+ "bytes": 251842
5531
5531
  }
5532
5532
  }
5533
5533
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devvit/public-api",
3
- "version": "0.11.0-next-2024-07-29-74c4bb837.0",
3
+ "version": "0.11.0-next-2024-07-30-8f65a4fa6.0",
4
4
  "license": "BSD-3-Clause",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "types": "./index.d.ts",
32
32
  "dependencies": {
33
- "@devvit/protos": "0.11.0-next-2024-07-29-74c4bb837.0",
34
- "@devvit/shared-types": "0.11.0-next-2024-07-29-74c4bb837.0",
33
+ "@devvit/protos": "0.11.0-next-2024-07-30-8f65a4fa6.0",
34
+ "@devvit/shared-types": "0.11.0-next-2024-07-30-8f65a4fa6.0",
35
35
  "base64-js": "1.5.1",
36
36
  "clone-deep": "4.0.1",
37
37
  "core-js": "3.27.2",
@@ -39,9 +39,9 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@ampproject/filesize": "4.3.0",
42
- "@devvit/eslint-config": "0.11.0-next-2024-07-29-74c4bb837.0",
43
- "@devvit/repo-tools": "0.11.0-next-2024-07-29-74c4bb837.0",
44
- "@devvit/tsconfig": "0.11.0-next-2024-07-29-74c4bb837.0",
42
+ "@devvit/eslint-config": "0.11.0-next-2024-07-30-8f65a4fa6.0",
43
+ "@devvit/repo-tools": "0.11.0-next-2024-07-30-8f65a4fa6.0",
44
+ "@devvit/tsconfig": "0.11.0-next-2024-07-30-8f65a4fa6.0",
45
45
  "@microsoft/api-extractor": "7.41.0",
46
46
  "@reddit/faceplate-ui": "11.3.3",
47
47
  "@types/clone-deep": "4.0.1",
@@ -64,5 +64,5 @@
64
64
  }
65
65
  },
66
66
  "source": "./src/index.ts",
67
- "gitHead": "68efa1e336dee06ac482d1932fbb0c97c34ce058"
67
+ "gitHead": "b6e254fbefbe5506377a5892bffaff2d10ce1f9c"
68
68
  }