@devvit/shared-types 0.12.0-next-2025-04-12-5721a9506.0 → 0.12.0-next-2025-04-28-276a82082.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.
- package/Header.d.ts +2 -0
- package/Header.d.ts.map +1 -1
- package/Header.js +2 -0
- package/forms/assertValidFormFields.d.ts +11 -0
- package/forms/assertValidFormFields.d.ts.map +1 -0
- package/forms/assertValidFormFields.js +29 -0
- package/forms/assertValidFormFields.test.d.ts.map +1 -0
- package/forms/getFormValues.d.ts +6 -0
- package/forms/getFormValues.d.ts.map +1 -0
- package/forms/getFormValues.js +31 -0
- package/forms/getFormValues.test.d.ts.map +1 -0
- package/forms/transformForm.d.ts +4 -0
- package/forms/transformForm.d.ts.map +1 -0
- package/forms/transformForm.js +141 -0
- package/forms/transformForm.test.d.ts.map +1 -0
- package/forms/types.d.ts +146 -0
- package/forms/types.d.ts.map +1 -0
- package/forms/types.js +5 -0
- package/package.json +6 -6
- package/webbit.d.ts +7 -0
- package/webbit.d.ts.map +1 -0
- package/webbit.js +1 -0
package/Header.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export declare const Header: Readonly<{
|
|
|
36
36
|
AppDependencies: "devvit-app-dependencies";
|
|
37
37
|
}>;
|
|
38
38
|
export type Header = (typeof Header)[keyof typeof Header];
|
|
39
|
+
/** Prefix common to all Devvit system headers. */
|
|
40
|
+
export declare const headerPrefix: string;
|
|
39
41
|
/** See DevvitGlobal and ContextDebugInfo. */
|
|
40
42
|
export declare const enum AppDebug {
|
|
41
43
|
/** Enable debug logging for blocks. */
|
package/Header.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Header.d.ts","sourceRoot":"","sources":["../src/Header.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BjB,CAAC;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;AAE1D,6CAA6C;AAC7C,0BAAkB,QAAQ;IACxB,uCAAuC;IACvC,MAAM,WAAW;IACjB;;;;OAIG;IACH,aAAa,kBAAkB;IAC/B,6BAA6B;IAC7B,SAAS,cAAc;IACvB,+DAA+D;IAC/D,QAAQ,aAAa;IACrB,6CAA6C;IAC7C,OAAO,YAAY;IACnB,8DAA8D;IAC9D,OAAO,YAAY;IACnB,2DAA2D;IAC3D,QAAQ,aAAa;IACrB,6CAA6C;IAC7C,QAAQ,aAAa;IACrB,+BAA+B;IAC/B,SAAS,cAAc;IACvB,yBAAyB;IACzB,OAAO,YAAY;CACpB"}
|
|
1
|
+
{"version":3,"file":"Header.d.ts","sourceRoot":"","sources":["../src/Header.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BjB,CAAC;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;AAE1D,kDAAkD;AAClD,eAAO,MAAM,YAAY,EAAE,MAAkB,CAAC;AAE9C,6CAA6C;AAC7C,0BAAkB,QAAQ;IACxB,uCAAuC;IACvC,MAAM,WAAW;IACjB;;;;OAIG;IACH,aAAa,kBAAkB;IAC/B,6BAA6B;IAC7B,SAAS,cAAc;IACvB,+DAA+D;IAC/D,QAAQ,aAAa;IACrB,6CAA6C;IAC7C,OAAO,YAAY;IACnB,8DAA8D;IAC9D,OAAO,YAAY;IACnB,2DAA2D;IAC3D,QAAQ,aAAa;IACrB,6CAA6C;IAC7C,QAAQ,aAAa;IACrB,+BAA+B;IAC/B,SAAS,cAAc;IACvB,yBAAyB;IACzB,OAAO,YAAY;CACpB"}
|
package/Header.js
CHANGED
|
@@ -35,6 +35,8 @@ export const Header = Object.freeze({
|
|
|
35
35
|
Traceparent: 'traceparent',
|
|
36
36
|
AppDependencies: 'devvit-app-dependencies',
|
|
37
37
|
});
|
|
38
|
+
/** Prefix common to all Devvit system headers. */
|
|
39
|
+
export const headerPrefix = 'devvit-';
|
|
38
40
|
/** See DevvitGlobal and ContextDebugInfo. */
|
|
39
41
|
export var AppDebug;
|
|
40
42
|
(function (AppDebug) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FormField } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Make sure that the form fields have unique names.
|
|
4
|
+
*
|
|
5
|
+
* This is a carbon copy of the assertValidFormFields function in the public-api package
|
|
6
|
+
* We copy it here so that webbit-client does not need to depend on public-api
|
|
7
|
+
* Any changes to this function should be reflected in the public-api version
|
|
8
|
+
*/
|
|
9
|
+
export declare function assertValidFormFields(fields: readonly FormField[], seenNames?: Set<string>): void;
|
|
10
|
+
export declare function assertAppSecretsOnly(fields: readonly FormField[]): void;
|
|
11
|
+
//# sourceMappingURL=assertValidFormFields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertValidFormFields.d.ts","sourceRoot":"","sources":["../../src/forms/assertValidFormFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,YAAY,CAAC;AAE1D;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,SAAS,GAAE,GAAG,CAAC,MAAM,CAAa,GACjC,IAAI,CAiBN;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,GAAG,IAAI,CAMvE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make sure that the form fields have unique names.
|
|
3
|
+
*
|
|
4
|
+
* This is a carbon copy of the assertValidFormFields function in the public-api package
|
|
5
|
+
* We copy it here so that webbit-client does not need to depend on public-api
|
|
6
|
+
* Any changes to this function should be reflected in the public-api version
|
|
7
|
+
*/
|
|
8
|
+
export function assertValidFormFields(fields, seenNames = new Set()) {
|
|
9
|
+
for (const field of fields) {
|
|
10
|
+
if (field.type === 'group') {
|
|
11
|
+
assertValidFormFields(field.fields, seenNames);
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
const fieldName = field.name;
|
|
16
|
+
if (seenNames.has(fieldName)) {
|
|
17
|
+
throw new Error(`Duplicate field name: ${fieldName}`);
|
|
18
|
+
}
|
|
19
|
+
seenNames.add(fieldName);
|
|
20
|
+
}
|
|
21
|
+
assertAppSecretsOnly(fields);
|
|
22
|
+
}
|
|
23
|
+
export function assertAppSecretsOnly(fields) {
|
|
24
|
+
for (const field of fields) {
|
|
25
|
+
if (field.type === 'string' && field.isSecret && field.scope !== 'app') {
|
|
26
|
+
throw `Invalid setting: only app settings can be secrets. Add "scope: SettingScope.App" to field "${field.name}"`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertValidFormFields.test.d.ts","sourceRoot":"","sources":["../../src/forms/assertValidFormFields.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFormValues.d.ts","sourceRoot":"","sources":["../../src/forms/getFormValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA2B7C,wBAAgB,aAAa,CAAC,OAAO,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAA;CAAE,GAAG,UAAU,CAMpF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FormFieldType } from '@devvit/protos';
|
|
2
|
+
function flattenFormFieldValue(value) {
|
|
3
|
+
switch (value.fieldType) {
|
|
4
|
+
case FormFieldType.STRING:
|
|
5
|
+
return value.stringValue;
|
|
6
|
+
case FormFieldType.IMAGE:
|
|
7
|
+
// the string value is the URL
|
|
8
|
+
return value.stringValue;
|
|
9
|
+
case FormFieldType.PARAGRAPH:
|
|
10
|
+
return value.stringValue;
|
|
11
|
+
case FormFieldType.NUMBER:
|
|
12
|
+
return value.numberValue;
|
|
13
|
+
case FormFieldType.BOOLEAN:
|
|
14
|
+
return value.boolValue;
|
|
15
|
+
case FormFieldType.SELECTION:
|
|
16
|
+
return value.selectionValue?.values ?? [];
|
|
17
|
+
default:
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// This is a carbon copy of the transformFormFields function in the public-api package
|
|
22
|
+
// We copy it here so that webbit-client does not need to depend on public-api
|
|
23
|
+
// Any changes to this function should be reflected in the public-api version
|
|
24
|
+
export function getFormValues(results) {
|
|
25
|
+
return Object.keys(results).reduce((acc, key) => {
|
|
26
|
+
const val = flattenFormFieldValue(results[key]);
|
|
27
|
+
if (val !== undefined)
|
|
28
|
+
acc[key] = val;
|
|
29
|
+
return acc;
|
|
30
|
+
}, {});
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFormValues.test.d.ts","sourceRoot":"","sources":["../../src/forms/getFormValues.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformForm.d.ts","sourceRoot":"","sources":["../../src/forms/transformForm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,cAAc,EAAiB,MAAM,gBAAgB,CAAC;AAE5E,OAAO,KAAK,EAEV,SAAS,EAOV,MAAM,YAAY,CAAC;AAKpB,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,GAAG,cAAc,EAAE,CAqBlF"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { FormField as FormFieldProto, FormFieldType } from '@devvit/protos';
|
|
2
|
+
// This is a carbon copy of the transformFormFields function in the public-api package
|
|
3
|
+
// We copy it here so that webbit-client does not need to depend on public-api
|
|
4
|
+
// Any changes to this function should be reflected in the public-api version
|
|
5
|
+
export function transformFormFields(fields) {
|
|
6
|
+
return fields.map((field) => {
|
|
7
|
+
switch (field.type) {
|
|
8
|
+
case 'string':
|
|
9
|
+
return transformStringField(field);
|
|
10
|
+
case 'image':
|
|
11
|
+
return transformImageField(field);
|
|
12
|
+
case 'paragraph':
|
|
13
|
+
return transformParagraphField(field);
|
|
14
|
+
case 'number':
|
|
15
|
+
return transformNumberField(field);
|
|
16
|
+
case 'select':
|
|
17
|
+
return transformSelectField(field);
|
|
18
|
+
case 'boolean':
|
|
19
|
+
return transformBooleanField(field);
|
|
20
|
+
case 'group':
|
|
21
|
+
return transformGroupField(field);
|
|
22
|
+
default:
|
|
23
|
+
throw new Error('Unknown field type.');
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function transformStringField(field) {
|
|
28
|
+
return {
|
|
29
|
+
defaultValue: {
|
|
30
|
+
fieldType: FormFieldType.STRING,
|
|
31
|
+
stringValue: field.defaultValue,
|
|
32
|
+
},
|
|
33
|
+
disabled: field.disabled,
|
|
34
|
+
fieldConfig: {
|
|
35
|
+
stringConfig: {
|
|
36
|
+
placeholder: field.placeholder,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
fieldId: field.name,
|
|
40
|
+
fieldType: FormFieldType.STRING,
|
|
41
|
+
helpText: field.helpText,
|
|
42
|
+
label: field.label,
|
|
43
|
+
required: field.required,
|
|
44
|
+
isSecret: field.isSecret,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function transformImageField(field) {
|
|
48
|
+
return {
|
|
49
|
+
disabled: field.disabled,
|
|
50
|
+
fieldId: field.name,
|
|
51
|
+
fieldType: FormFieldType.IMAGE,
|
|
52
|
+
helpText: field.helpText,
|
|
53
|
+
label: field.label,
|
|
54
|
+
required: field.required,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function transformParagraphField(field) {
|
|
58
|
+
return {
|
|
59
|
+
defaultValue: {
|
|
60
|
+
fieldType: FormFieldType.PARAGRAPH,
|
|
61
|
+
stringValue: field.defaultValue,
|
|
62
|
+
},
|
|
63
|
+
disabled: field.disabled,
|
|
64
|
+
fieldConfig: {
|
|
65
|
+
paragraphConfig: {
|
|
66
|
+
lineHeight: field.lineHeight,
|
|
67
|
+
placeholder: field.placeholder,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
fieldId: field.name,
|
|
71
|
+
fieldType: FormFieldType.PARAGRAPH,
|
|
72
|
+
helpText: field.helpText,
|
|
73
|
+
label: field.label,
|
|
74
|
+
required: field.required,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function transformNumberField(field) {
|
|
78
|
+
return {
|
|
79
|
+
defaultValue: {
|
|
80
|
+
fieldType: FormFieldType.NUMBER,
|
|
81
|
+
numberValue: field.defaultValue,
|
|
82
|
+
},
|
|
83
|
+
disabled: field.disabled,
|
|
84
|
+
fieldConfig: {
|
|
85
|
+
numberConfig: {},
|
|
86
|
+
},
|
|
87
|
+
fieldId: field.name,
|
|
88
|
+
fieldType: FormFieldType.NUMBER,
|
|
89
|
+
helpText: field.helpText,
|
|
90
|
+
label: field.label,
|
|
91
|
+
required: field.required,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function transformSelectField(field) {
|
|
95
|
+
return {
|
|
96
|
+
defaultValue: {
|
|
97
|
+
fieldType: FormFieldType.SELECTION,
|
|
98
|
+
selectionValue: {
|
|
99
|
+
values: field.defaultValue ?? [],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
disabled: field.disabled,
|
|
103
|
+
fieldConfig: {
|
|
104
|
+
selectionConfig: {
|
|
105
|
+
choices: field.options,
|
|
106
|
+
multiSelect: field.multiSelect,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
fieldId: field.name,
|
|
110
|
+
fieldType: FormFieldType.SELECTION,
|
|
111
|
+
helpText: field.helpText,
|
|
112
|
+
label: field.label,
|
|
113
|
+
required: field.required,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function transformBooleanField(field) {
|
|
117
|
+
return {
|
|
118
|
+
defaultValue: {
|
|
119
|
+
fieldType: FormFieldType.BOOLEAN,
|
|
120
|
+
boolValue: field.defaultValue,
|
|
121
|
+
},
|
|
122
|
+
disabled: field.disabled,
|
|
123
|
+
fieldId: field.name,
|
|
124
|
+
fieldType: FormFieldType.BOOLEAN,
|
|
125
|
+
helpText: field.helpText,
|
|
126
|
+
label: field.label,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function transformGroupField(field) {
|
|
130
|
+
return {
|
|
131
|
+
fieldId: '',
|
|
132
|
+
fieldType: FormFieldType.GROUP,
|
|
133
|
+
fieldConfig: {
|
|
134
|
+
groupConfig: {
|
|
135
|
+
fields: transformFormFields(field.fields),
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
label: field.label,
|
|
139
|
+
helpText: field.helpText,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformForm.test.d.ts","sourceRoot":"","sources":["../../src/forms/transformForm.test.ts"],"names":[],"mappings":""}
|
package/forms/types.d.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { FieldConfig_Boolean, FieldConfig_Number, FieldConfig_Paragraph, FieldConfig_Selection, FieldConfig_Selection_Item, FieldConfig_String } from '@devvit/protos';
|
|
2
|
+
import type { JSONObject } from '../json.js';
|
|
3
|
+
import type { Prettify } from '../Prettify.js';
|
|
4
|
+
export type FormValues = JSONObject;
|
|
5
|
+
export type FormOnSubmitEvent<T extends Partial<JSONObject>> = {
|
|
6
|
+
/** The form values that were submitted */
|
|
7
|
+
values: T;
|
|
8
|
+
};
|
|
9
|
+
export type BaseField<ValueType> = {
|
|
10
|
+
/**
|
|
11
|
+
* The name of the field. This will be used as the key in the `values` object
|
|
12
|
+
* when the form is submitted.
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
/** The label of the field. This will be displayed to the user */
|
|
16
|
+
label: string;
|
|
17
|
+
/** An optional help text that will be displayed below the field */
|
|
18
|
+
helpText?: string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* If true the field will be required and the user will not be able to submit
|
|
21
|
+
* the form without filling it in.
|
|
22
|
+
*/
|
|
23
|
+
required?: boolean | undefined;
|
|
24
|
+
/** If true the field will be disabled */
|
|
25
|
+
disabled?: boolean | undefined;
|
|
26
|
+
/** The default value of the field */
|
|
27
|
+
defaultValue?: ValueType | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* This indicates whether the field (setting) is an app level or install level
|
|
30
|
+
* setting. App setting values can be used by any installation.
|
|
31
|
+
*/
|
|
32
|
+
scope?: SettingScopeType | undefined;
|
|
33
|
+
};
|
|
34
|
+
export type SettingScopeType = 'installation' | 'app';
|
|
35
|
+
export declare enum SettingScope {
|
|
36
|
+
Installation = "installation",
|
|
37
|
+
App = "app"
|
|
38
|
+
}
|
|
39
|
+
/** A text field */
|
|
40
|
+
export type StringField = Prettify<BaseField<string> & Omit<FieldConfig_String, 'minLength' | 'maxLength'> & {
|
|
41
|
+
type: 'string';
|
|
42
|
+
isSecret?: boolean;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Allows a user to upload an image as part of submitting the form. The string value that's
|
|
46
|
+
* given back is the URL of the image.
|
|
47
|
+
* @experimental
|
|
48
|
+
*/
|
|
49
|
+
export type ImageField = Omit<BaseField<string>, 'defaultValue'> & {
|
|
50
|
+
type: 'image';
|
|
51
|
+
};
|
|
52
|
+
/** A paragraph or textarea field */
|
|
53
|
+
export type ParagraphField = Prettify<BaseField<string> & Omit<FieldConfig_Paragraph, 'maxCharacters'> & {
|
|
54
|
+
type: 'paragraph';
|
|
55
|
+
}>;
|
|
56
|
+
/** A number field */
|
|
57
|
+
export type NumberField = Prettify<BaseField<number> & Omit<FieldConfig_Number, 'min' | 'max' | 'step'> & {
|
|
58
|
+
type: 'number';
|
|
59
|
+
}>;
|
|
60
|
+
/** A boolean field displayed as a toggle */
|
|
61
|
+
export type BooleanField = Prettify<Omit<BaseField<boolean>, 'required'> & FieldConfig_Boolean & {
|
|
62
|
+
type: 'boolean';
|
|
63
|
+
}>;
|
|
64
|
+
/** A dropdown field that allows users to pick from a list of options */
|
|
65
|
+
export type SelectField = Prettify<BaseField<string[]> & Omit<FieldConfig_Selection, 'choices' | 'renderAsList' | 'minSelections' | 'maxSelections'> & {
|
|
66
|
+
type: 'select';
|
|
67
|
+
options: FieldConfig_Selection_Item[];
|
|
68
|
+
}>;
|
|
69
|
+
/** A grouping of fields */
|
|
70
|
+
export type FormFieldGroup = {
|
|
71
|
+
type: 'group';
|
|
72
|
+
/** The label of the group that will be displayed to the user */
|
|
73
|
+
label: string;
|
|
74
|
+
/** The fields that will be displayed in the group */
|
|
75
|
+
fields: readonly FormField[];
|
|
76
|
+
/** An optional help text that will be displayed below the group */
|
|
77
|
+
helpText?: string | undefined;
|
|
78
|
+
required?: never;
|
|
79
|
+
};
|
|
80
|
+
export type FormField = StringField | ImageField | ParagraphField | NumberField | BooleanField | SelectField | FormFieldGroup;
|
|
81
|
+
export type Form = {
|
|
82
|
+
/** The fields that will be displayed in the form */
|
|
83
|
+
fields: readonly FormField[];
|
|
84
|
+
/** An optional title for the form */
|
|
85
|
+
title?: string;
|
|
86
|
+
/** An optional description for the form */
|
|
87
|
+
description?: string;
|
|
88
|
+
/** An optional label for the submit button */
|
|
89
|
+
acceptLabel?: string;
|
|
90
|
+
/** An optional label for the cancel button */
|
|
91
|
+
cancelLabel?: string;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* A function that returns a form. You can use this to dynamically generate a form.
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* const formKey = Devvit.createForm((data) => ({
|
|
98
|
+
* fields: data.fields,
|
|
99
|
+
* title: data.title,
|
|
100
|
+
* }), callback);
|
|
101
|
+
*
|
|
102
|
+
* ...
|
|
103
|
+
*
|
|
104
|
+
* ui.showForm(formKey, {
|
|
105
|
+
* fields: [{ type: 'string', name: 'title', label: 'Title' }]
|
|
106
|
+
* title: 'My dynamic form'
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
* */
|
|
110
|
+
export type FormFunction<T extends {
|
|
111
|
+
[key: string]: any;
|
|
112
|
+
} = {
|
|
113
|
+
[key: string]: any;
|
|
114
|
+
}> = (data: T) => Form;
|
|
115
|
+
export type FormToFormValues<T extends Form | FormFunction = Form | FormFunction> = FormFieldsToFormValues<(T extends FormFunction ? ReturnType<T> : T)['fields']>;
|
|
116
|
+
/**
|
|
117
|
+
* Input is a FormField[], output is a
|
|
118
|
+
* {fieldNameA: fieldTypeA, fieldNameB: fieldTypeB}.
|
|
119
|
+
*/
|
|
120
|
+
type FormFieldsToFormValues<T extends readonly FormField[]> = T extends readonly [
|
|
121
|
+
infer Field extends FormField,
|
|
122
|
+
...infer Rest extends FormField[]
|
|
123
|
+
] ? FormFieldToFormValue<Field> & FormFieldsToFormValues<Rest> : {
|
|
124
|
+
[key: string]: any;
|
|
125
|
+
};
|
|
126
|
+
/** Input is a FormField, output is a {fieldName: fieldType}. */
|
|
127
|
+
type FormFieldToFormValue<T extends FormField> = T extends BooleanField ? {
|
|
128
|
+
[_ in T['name']]: boolean;
|
|
129
|
+
} : T extends ImageField | ParagraphField | StringField ? FormFieldToRequiredFormValue<T, string> : T extends NumberField ? FormFieldToRequiredFormValue<T, number> : T extends SelectField ? {
|
|
130
|
+
[_ in T['name']]: string[];
|
|
131
|
+
} : T extends FormFieldGroup ? FormFieldsToFormValues<T['fields']> : never;
|
|
132
|
+
/**
|
|
133
|
+
* Input is a FormField, output is a {fieldName: fieldType} or
|
|
134
|
+
* {fieldName?: fieldType}.
|
|
135
|
+
*/
|
|
136
|
+
type FormFieldToRequiredFormValue<T extends ImageField | ParagraphField | StringField | NumberField, V> = T extends {
|
|
137
|
+
required: true;
|
|
138
|
+
} | {
|
|
139
|
+
defaultValue: boolean | number | string;
|
|
140
|
+
} ? {
|
|
141
|
+
[_ in T['name']]: V;
|
|
142
|
+
} : {
|
|
143
|
+
[_ in T['name']]?: V;
|
|
144
|
+
};
|
|
145
|
+
export {};
|
|
146
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/forms/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC;AAEpC,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,OAAO,CAAC,UAAU,CAAC,IAAI;IAC7D,0CAA0C;IAC1C,MAAM,EAAE,CAAC,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,SAAS,CAAC,SAAS,IAAI;IACjC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,KAAK,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,yCAAyC;IACzC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,qCAAqC;IACrC,YAAY,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IACrC;;;OAGG;IACH,KAAK,CAAC,EAAE,gBAAg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,CAAC"}
|
package/forms/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/shared-types",
|
|
3
|
-
"version": "0.12.0-next-2025-04-
|
|
3
|
+
"version": "0.12.0-next-2025-04-28-276a82082.0",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"types": "./index.d.ts",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@devvit/protos": "0.12.0-next-2025-04-
|
|
28
|
+
"@devvit/protos": "0.12.0-next-2025-04-28-276a82082.0",
|
|
29
29
|
"jsonschema": "1.4.1",
|
|
30
30
|
"uuid": "9.0.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@devvit/repo-tools": "0.12.0-next-2025-04-
|
|
34
|
-
"@devvit/tsconfig": "0.12.0-next-2025-04-
|
|
33
|
+
"@devvit/repo-tools": "0.12.0-next-2025-04-28-276a82082.0",
|
|
34
|
+
"@devvit/tsconfig": "0.12.0-next-2025-04-28-276a82082.0",
|
|
35
35
|
"@types/redis-mock": "0.17.1",
|
|
36
36
|
"@types/uuid": "9.0.0",
|
|
37
37
|
"chokidar-cli": "3.0.0",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"redis": "4.6.6",
|
|
41
41
|
"redis-mock": "0.56.3",
|
|
42
42
|
"typescript": "5.3.2",
|
|
43
|
-
"vitest": "1.6.
|
|
43
|
+
"vitest": "1.6.1"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"directory": "dist"
|
|
47
47
|
},
|
|
48
48
|
"source": "./src/index.ts",
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "67447f61a9459bee03909b59c8889a915e2be256"
|
|
50
50
|
}
|
package/webbit.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Signed Webbit user JWT (header, payload, signature base64 strings separated by dots).
|
|
2
|
+
* Users shouldn't share their JWTs with others, but perfectly fine for a given user to see.
|
|
3
|
+
* Named WebbitToken to match GQL's definition.
|
|
4
|
+
* */
|
|
5
|
+
export type WebbitToken = `${string}.${string}.${string}`;
|
|
6
|
+
export declare const noWebbitToken: WebbitToken;
|
|
7
|
+
//# sourceMappingURL=webbit.d.ts.map
|
package/webbit.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webbit.d.ts","sourceRoot":"","sources":["../src/webbit.ts"],"names":[],"mappings":"AAAA;;;KAGK;AACL,MAAM,MAAM,WAAW,GAAG,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;AAC1D,eAAO,MAAM,aAAa,EAAE,WAAqB,CAAC"}
|
package/webbit.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const noWebbitToken = `0.0.0`;
|