Skip to content

Commit

Permalink
added multiple schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
eluce2 committed Oct 4, 2024
1 parent f5751fb commit fc8a791
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
5 changes: 0 additions & 5 deletions .changeset/smooth-moles-sin.md

This file was deleted.

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @proofgeist/fmdapi

## 4.1.1

### Patch Changes

- Allow array of config to support multiple servers in a single config file
- f5751fb: add new option to clean out old files prior to running codegen, so removed schemas don't remain in your codebase

## 4.1.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@proofgeist/fmdapi",
"version": "4.1.0",
"version": "4.1.1",
"description": "FileMaker Data API client",
"main": "dist/index.js",
"repository": "[email protected]:proofgeist/fm-dapi.git",
Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async function runCodegen({ configLocation }: ConfigArgs) {
);
}

await generateTypedClients(config, configLocation).catch((err: unknown) => {
await generateTypedClients(config).catch((err: unknown) => {
console.error(err);
return process.exit(1);
});
Expand Down
17 changes: 13 additions & 4 deletions src/utils/typegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
type BuildSchemaArgs,
type ClientObjectProps,
type GenerateSchemaOptions,
type GenerateSchemaOptionsSingle,
} from "./types.js";
import chalk from "chalk";
import {
Expand All @@ -20,9 +21,18 @@ import { buildSchema } from "./buildSchema.js";
import { getLayoutMetadata } from "./getLayoutMetadata.js";
import { buildLayoutClient } from "./buildLayoutClient.js";

export const generateTypedClients = async (
options: GenerateSchemaOptions,
configLocation?: string,
export const generateTypedClients = async (options: GenerateSchemaOptions) => {
if (Array.isArray(options)) {
for (const option of options) {
await generateTypedClientsSingle(option);
}
} else {
await generateTypedClientsSingle(options);
}
};

const generateTypedClientsSingle = async (
options: GenerateSchemaOptionsSingle,
) => {
const {
envNames,
Expand Down Expand Up @@ -138,7 +148,6 @@ export const generateTypedClients = async (
valueLists,
type: useZod ? "zod" : "ts",
strictNumbers: item.strictNumbers,
configLocation,
webviewerScriptName: options.webviewerScriptName,
envNames: {
auth: isOttoAuth(auth)
Expand Down
9 changes: 6 additions & 3 deletions src/utils/typegen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type ClientObjectProps = OttoAdapterOptions | FetchAdapterOptions;

export type ValueListsOptions = "strict" | "allowEmpty" | "ignore";

export type GenerateSchemaOptions = {
export type GenerateSchemaOptionsSingle = {
envNames?: Partial<Omit<ClientObjectProps, "layout">>;
schemas: Array<{
layout: string;
Expand Down Expand Up @@ -63,6 +63,10 @@ export type GenerateSchemaOptions = {
clearOldFiles?: boolean;
};

export type GenerateSchemaOptions =
| GenerateSchemaOptionsSingle
| GenerateSchemaOptionsSingle[];

export type TSchema = {
name: string;
type: "string" | "fmnumber" | "valueList";
Expand All @@ -78,6 +82,5 @@ export type BuildSchemaArgs = {
envNames: Omit<ClientObjectProps, "layout" | "tokenStore">;
layoutName: string;
strictNumbers?: boolean;
configLocation?: string;
webviewerScriptName?: string;
} & Pick<GenerateSchemaOptions, "tokenStore">;
} & Pick<GenerateSchemaOptionsSingle, "tokenStore">;

0 comments on commit fc8a791

Please sign in to comment.