mirror of
https://github.com/zhigang1992/pocketbase-typegen.git
synced 2026-04-29 12:45:19 +08:00
add IsoDateString type as an alias
This commit is contained in:
3
src/constants.ts
Normal file
3
src/constants.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const EXPORT_COMMENT = `// This file was @generated using pocketbase-typegen`
|
||||
export const DATE_STRING_TYPE_NAME = `IsoDateString`
|
||||
export const DATE_STRING_TYPE_DEFINITION = `export type ${DATE_STRING_TYPE_NAME} = string`
|
||||
12
src/lib.ts
12
src/lib.ts
@@ -1,4 +1,9 @@
|
||||
import { CollectionRecord, FieldSchema, RecordOptions } from "./types"
|
||||
import { CollectionRecord, FieldSchema } from "./types"
|
||||
import {
|
||||
DATE_STRING_TYPE_DEFINITION,
|
||||
DATE_STRING_TYPE_NAME,
|
||||
EXPORT_COMMENT,
|
||||
} from "./constants"
|
||||
import { fieldNameToGeneric, getGenericArgString } from "./generics"
|
||||
import { sanitizeFieldName, toPascalCase } from "./utils"
|
||||
|
||||
@@ -8,7 +13,7 @@ const pbSchemaTypescriptMap = {
|
||||
bool: "boolean",
|
||||
email: "string",
|
||||
url: "string",
|
||||
date: "string",
|
||||
date: DATE_STRING_TYPE_NAME,
|
||||
select: (fieldSchema: FieldSchema) =>
|
||||
fieldSchema.options.values
|
||||
? fieldSchema.options.values.map((val) => `"${val}"`).join(" | ")
|
||||
@@ -34,7 +39,8 @@ export function generate(results: Array<CollectionRecord>) {
|
||||
const sortedCollectionNames = collectionNames.sort()
|
||||
|
||||
const fileParts = [
|
||||
`// This file was @generated using pocketbase-typegen`,
|
||||
EXPORT_COMMENT,
|
||||
DATE_STRING_TYPE_DEFINITION,
|
||||
createCollectionEnum(sortedCollectionNames),
|
||||
...recordTypes.sort(),
|
||||
createCollectionRecord(sortedCollectionNames),
|
||||
|
||||
@@ -29,6 +29,8 @@ exports[`createRecordType handles file fields with multiple files 1`] = `
|
||||
exports[`generate generates correct output given db input 1`] = `
|
||||
"// This file was @generated using pocketbase-typegen
|
||||
|
||||
export type IsoDateString = string
|
||||
|
||||
export enum Collections {
|
||||
Books = "books",
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ describe("createTypeField", () => {
|
||||
name: "dateField",
|
||||
type: "date",
|
||||
})
|
||||
).toEqual("\tdateField: string\n")
|
||||
).toEqual("\tdateField: IsoDateString\n")
|
||||
expect(
|
||||
createTypeField({
|
||||
...defaultFieldSchema,
|
||||
|
||||
Reference in New Issue
Block a user