Skip to content

Commit 08b0e41

Browse files
authored
validate multiple portals (#52)
validate multiple portals add warning new version remove unused deps from better-auth
2 parents 15012ab + 83a5823 commit 08b0e41

20 files changed

+284
-49
lines changed

knip.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { KnipConfig } from "knip";
2+
const config: KnipConfig = {
3+
ignoreWorkspaces: ["apps/demo"],
4+
ignore: ["packages/cli/template/**"],
5+
ignoreBinaries: ["op", "vercel"],
6+
};
7+
8+
export default config;

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
"sherif": "pnpm dlx sherif@latest",
1212
"sherif:fix": "pnpm sherif --fix",
1313
"release": "pnpm build --filter='./packages/...' && changeset publish",
14-
"test": "vitest"
14+
"test": "vitest",
15+
"knip": "knip"
1516
},
1617
"devDependencies": {
1718
"@changesets/cli": "^2.29.3",
1819
"@types/node": "^22.15.32",
1920
"eslint": "^9.23.0",
21+
"knip": "^5.56.0",
2022
"prettier": "^3.5.3",
2123
"turbo": "^2.5.4",
24+
"typescript": "^5.8.3",
2225
"vitest": "^3.2.3"
2326
},
2427
"packageManager": "[email protected]",

packages/better-auth/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@
4747
"@babel/preset-react": "^7.27.1",
4848
"@babel/preset-typescript": "^7.27.1",
4949
"@commander-js/extra-typings": "^14.0.0",
50-
"@proofkit/fmdapi": "workspace:*",
5150
"@tanstack/vite-config": "^0.2.0",
5251
"better-auth": "^1.2.10",
5352
"c12": "^3.0.4",
5453
"chalk": "5.4.1",
5554
"commander": "^14.0.0",
5655
"dotenv": "^16.5.0",
57-
"execa": "^9.5.3",
5856
"fm-odata-client": "^3.0.1",
5957
"fs-extra": "^11.3.0",
6058
"prompts": "^2.4.2",

packages/fmdapi/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# @proofkit/fmdapi
22

3+
## 5.0.1
4+
5+
### Patch Changes
6+
7+
- 2ff4cd1: Update how portal validation should be passed to the fmdapi client.
8+
To update, simply re-run the `npx @proofkit/typegen@latest` command and your files will be updated to the correct syntax. If you still see errors, try with the "--reset-overrides" flag to also re-create your overrides files.
9+
310
## 5.0.0
411

512
### Major Changes

packages/fmdapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@proofkit/fmdapi",
3-
"version": "5.0.0",
3+
"version": "5.0.1",
44
"description": "FileMaker Data API client",
55
"repository": "[email protected]:proofgeist/fm-dapi.git",
66
"author": "Eric <[email protected]>",

packages/fmdapi/src/client.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type ClientObjectProps = {
3636
/**
3737
* The schema for the portal data.
3838
*/
39-
portalData?: StandardSchemaV1<GenericPortalData>;
39+
portalData?: Record<string, StandardSchemaV1<FieldData>>;
4040
};
4141
};
4242

@@ -55,7 +55,11 @@ function DataApi<
5555
: Fd;
5656
type InferredPortalData = Opts["schema"] extends object
5757
? Opts["schema"]["portalData"] extends object
58-
? StandardSchemaV1.InferOutput<Opts["schema"]["portalData"]>
58+
? {
59+
[K in keyof Opts["schema"]["portalData"]]: StandardSchemaV1.InferOutput<
60+
Opts["schema"]["portalData"][K]
61+
>;
62+
}
5963
: Pd
6064
: Pd;
6165

@@ -473,19 +477,20 @@ function DataApi<
473477
const validatedPortalRecords: PortalsWithIds<GenericPortalData>[] =
474478
[];
475479
for (const portalRecord of portalRecords) {
476-
let portalResult = schema.portalData["~standard"].validate({
477-
[portalName]: portalRecord,
478-
});
480+
let portalResult =
481+
schema.portalData[portalName]?.["~standard"].validate(
482+
portalRecord,
483+
);
479484
if (portalResult instanceof Promise)
480485
portalResult = await portalResult;
481-
if ("value" in portalResult) {
486+
if (portalResult && "value" in portalResult) {
482487
validatedPortalRecords.push({
483-
...portalResult.value[portalName],
488+
...portalResult.value,
484489
recordId: portalRecord.recordId,
485490
modId: portalRecord.modId,
486491
});
487492
} else {
488-
portalDataIssues.push(...portalResult.issues);
493+
portalDataIssues.push(...(portalResult?.issues ?? []));
489494
}
490495
}
491496
// @ts-expect-error We know portalName is a valid key, but can't figure out the right assertions

packages/fmdapi/src/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { S, L, U } from "ts-toolbelt";
2+
import type * as z3 from "zod/v3";
3+
import type * as z4 from "zod/v4/core";
24

35
// eslint-disable-next-line @typescript-eslint/no-explicit-any
46
type TransformedFields<T extends Record<string, any>> = U.Merge<
@@ -27,3 +29,13 @@ export function removeFMTableNames<T extends Record<string, any>>(
2729
}
2830
return newObj;
2931
}
32+
33+
export type InferZodPortals<T extends Record<string, any>> = {
34+
[K in keyof T]: T[K] extends { _def: any; parse: (...args: any[]) => any }
35+
? ReturnType<T[K]["parse"]>
36+
: T[K] extends { _def: any; safeParse: (...args: any[]) => any }
37+
? T[K] extends { parse: (...args: any[]) => any }
38+
? ReturnType<T[K]["parse"]>
39+
: any
40+
: never;
41+
};

packages/fmdapi/tests/zod.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const ZPortalTable = z.object({
99
"related::related_field": z.string(),
1010
});
1111

12-
const ZCustomerPortals = z.object({
12+
const ZCustomerPortals = {
1313
PortalTable: ZPortalTable,
14-
});
14+
};
1515

1616
const client = DataApi({
1717
adapter: new OttoAdapter({
@@ -79,19 +79,22 @@ describe("zod transformation", () => {
7979
booleanField: z.coerce.boolean(),
8080
CreationTimestamp: z.coerce.date(), // this does not convert the date properly, but does test the transformation
8181
}),
82-
portalData: z.object({
82+
portalData: {
8383
test: z.object({
8484
"related::related_field": z.string(),
8585
"related::recordId": z.coerce.string(), // it's actually a number field, this tests the transformation
8686
}),
87-
}),
87+
},
8888
},
8989
});
9090
const data = await customClient.listAll();
9191
expect(typeof data[0].fieldData.booleanField).toBe("boolean");
9292
console.log(data[0].fieldData.CreationTimestamp);
9393
expect(typeof data[0].fieldData.CreationTimestamp).toBe("object");
9494
const firstPortalRecord = data[0].portalData.test[0];
95+
// @ts-expect-error - notAPortal is not a portal
96+
data[0].portalData.notAPortal;
97+
9598
console.log("test portal data, first record", firstPortalRecord);
9699
expect(typeof firstPortalRecord["related::related_field"]).toBe("string");
97100
expect(typeof firstPortalRecord["related::recordId"]).toBe("string");

packages/typegen/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# @proofkit/typegen
22

3+
## 1.0.9
4+
5+
### Patch Changes
6+
7+
- 2ff4cd1: Update how portal validation should be passed to the fmdapi client.
8+
To update, simply re-run the `npx @proofkit/typegen@latest` command and your files will be updated to the correct syntax. If you still see errors, try with the "--reset-overrides" flag to also re-create your overrides files.
9+
- Updated dependencies [2ff4cd1]
10+
- @proofkit/fmdapi@5.0.1
11+
312
## 1.0.8
413

514
### Patch Changes

packages/typegen/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@proofkit/typegen",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"description": "",
55
"type": "module",
66
"main": "dist/esm/index.js",
@@ -59,14 +59,17 @@
5959
"fs-extra": "^11.3.0",
6060
"jsonc-parser": "^3.3.1",
6161
"prettier": "^3.5.3",
62+
"semver": "^7.7.2",
6263
"ts-morph": "^26.0.0",
6364
"ts-toolbelt": "^9.6.0",
6465
"vite": "^6.3.4",
6566
"zod": "3.25.64"
6667
},
6768
"devDependencies": {
6869
"@types/fs-extra": "^11.0.4",
70+
"@types/semver": "^7.7.0",
6971
"publint": "^0.3.12",
72+
"type-fest": "^3.13.1",
7073
"typescript": "^5.8.3",
7174
"vitest": "^3.2.3"
7275
}

0 commit comments

Comments
 (0)