Skip to content

Commit 5277d09

Browse files
committed
New utilities and improved types
* Add new high-level utilities * Improve types of entities related to fields (their type now depends on the actual field type)
1 parent 51532ec commit 5277d09

111 files changed

Lines changed: 6509 additions & 107 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

generate/extractInfoFromSchema.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,20 @@ async function schemaToTs(schema: any) {
429429
return result.replace(/export interface ([^ ]+) {/g, 'export type $1 = {');
430430
}
431431

432+
function convertFieldTypesToRaw(typings: string) {
433+
return typings
434+
.replace('export type Field ', 'export type RawField ')
435+
.replace('export type FieldAttributes ', 'export type RawFieldAttributes ')
436+
.replace(
437+
'export type FieldCreateSchema ',
438+
'export type RawFieldCreateSchema ',
439+
)
440+
.replace(
441+
'export type FieldUpdateSchema ',
442+
'export type RawFieldUpdateSchema ',
443+
);
444+
}
445+
432446
export default async function extractInfoFromSchema(
433447
hyperschemaUrl: string,
434448
isCma: boolean,
@@ -452,7 +466,9 @@ export default async function extractInfoFromSchema(
452466
generateResourceInfo(isCma, resource, schema),
453467
)
454468
.filter((resourceInfo) => resourceInfo.endpoints.length > 0),
455-
simpleTypings: await schemaToTs(simplifiedRawSchema),
456-
typings: typings,
469+
simpleTypings: convertFieldTypesToRaw(
470+
await schemaToTs(simplifiedRawSchema),
471+
),
472+
typings: convertFieldTypesToRaw(typings),
457473
};
458474
}

generate/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,21 @@ async function generate(prefix: string, hyperschemaUrl: string) {
7575

7676
await writeTemplate(
7777
'SchemaTypes.ts',
78-
{ typings: schemaInfo.typings },
78+
{
79+
typings: schemaInfo.typings,
80+
simpleVariant: false,
81+
isCma: prefix === 'cma',
82+
},
7983
`./packages/${prefix}-client/src/generated/SchemaTypes.ts`,
8084
);
8185

8286
await writeTemplate(
8387
'SchemaTypes.ts',
84-
{ typings: schemaInfo.simpleTypings },
88+
{
89+
typings: schemaInfo.simpleTypings,
90+
simpleVariant: true,
91+
isCma: prefix === 'cma',
92+
},
8593
`./packages/${prefix}-client/src/generated/SimpleSchemaTypes.ts`,
8694
);
8795

0 commit comments

Comments
 (0)