@devvit/shared-types 0.10.23-next-2024-06-20-020b1b212.0 → 0.10.23-next-2024-06-24-e5fe20712.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devvit/shared-types",
3
- "version": "0.10.23-next-2024-06-20-020b1b212.0",
3
+ "version": "0.10.23-next-2024-06-24-e5fe20712.0",
4
4
  "license": "BSD-3-Clause",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,12 +23,12 @@
23
23
  },
24
24
  "types": "./index.d.ts",
25
25
  "dependencies": {
26
- "@devvit/protos": "0.10.23-next-2024-06-20-020b1b212.0"
26
+ "@devvit/protos": "0.10.23-next-2024-06-24-e5fe20712.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@devvit/eslint-config": "0.10.22",
30
30
  "@devvit/repo-tools": "0.10.22",
31
- "@devvit/tsconfig": "0.10.23-next-2024-06-20-020b1b212.0",
31
+ "@devvit/tsconfig": "0.10.23-next-2024-06-24-e5fe20712.0",
32
32
  "@types/redis-mock": "0.17.1",
33
33
  "eslint": "8.9.0",
34
34
  "lit": "2.2.8",
@@ -41,5 +41,5 @@
41
41
  "directory": "dist"
42
42
  },
43
43
  "source": "./src/index.ts",
44
- "gitHead": "081ef92f2f37dd4445b9538a0238ab088b3b24fa"
44
+ "gitHead": "d462560e356ba87b125508422afce4943a36a200"
45
45
  }
package/useForm.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /** A unique key generated by `Devvit.createForm` or the `useForm` hook. */
2
+ export type FormKey = `form.${number}` | `form.hook.${string}.${number}`;
3
+ export declare function formKeyToHookId(formKey: string | FormKey): string;
4
+ //# sourceMappingURL=useForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../src/useForm.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,MAAM,OAAO,GAAG,QAAQ,MAAM,EAAE,GAAG,aAAa,MAAM,IAAI,MAAM,EAAE,CAAC;AAEzE,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAWjE"}
package/useForm.js ADDED
@@ -0,0 +1,8 @@
1
+ export function formKeyToHookId(formKey) {
2
+ // extract the hook id from the form key with a regex
3
+ const match = formKey.match(/form\.hook\.(.+)\.0/);
4
+ if (!match?.[1]) {
5
+ throw new Error(`Could not parse a hook ref from form key '${formKey}'. Please make sure you are passing in a string that starts with 'form.hook.'`);
6
+ }
7
+ return match[1];
8
+ }