-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support for PocketBase 0.23 with Improved expand Property Optionality Based on Texpand #107
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,18 +15,33 @@ export const ALIAS_TYPE_DEFINITIONS = `// Alias types for improved usability | |
export type ${DATE_STRING_TYPE_NAME} = string | ||
export type ${RECORD_ID_STRING_NAME} = string | ||
export type ${HTML_STRING_NAME} = string` | ||
|
||
export const IS_EXACTLY_UNKNOWN_TYPE_DEFINITION = `// Utility type to check if T is exactly unknown | ||
type IsExactlyUnknown<T> = | ||
unknown extends T | ||
? T extends unknown | ||
? keyof T extends never | ||
? true | ||
: false | ||
: false | ||
: false` | ||
export const BASE_SYSTEM_FIELDS_DEFINITION = `// System fields | ||
export type BaseSystemFields<T = never> = { | ||
\tid: ${RECORD_ID_STRING_NAME} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep the |
||
\tcollectionId: string | ||
\tcollectionName: Collections | ||
\texpand?: T | ||
}` | ||
export type BaseSystemFields<T = unknown> = IsExactlyUnknown<T> extends true | ||
? { | ||
id: ${RECORD_ID_STRING_NAME} | ||
collectionId: string | ||
collectionName: Collections | ||
expand?: unknown | ||
} | ||
: { | ||
id: ${RECORD_ID_STRING_NAME} | ||
collectionId: string | ||
collectionName: Collections | ||
expand: T | ||
};` | ||
|
||
export const AUTH_SYSTEM_FIELDS_DEFINITION = `export type AuthSystemFields<T = never> = { | ||
\temail: string | ||
\temailVisibility: boolean | ||
\tusername: string | ||
\tverified: boolean | ||
export const AUTH_SYSTEM_FIELDS_DEFINITION = `export type AuthSystemFields<T = unknown> = { | ||
email: string | ||
emailVisibility: boolean | ||
username: string | ||
verified: boolean | ||
} & BaseSystemFields<T>` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ export async function fromDatabase( | |
const result = await db.all("SELECT * FROM _collections") | ||
return result.map((collection) => ({ | ||
...collection, | ||
fields: JSON.parse(collection.fields), | ||
fields: JSON.parse(collection.schema), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why does this need to change? |
||
})) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -27,19 +27,36 @@ export type IsoDateString = string | |||||||||||||||||||||||||||||||||
export type RecordIdString = string | ||||||||||||||||||||||||||||||||||
export type HTMLString = string | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// System fields | ||||||||||||||||||||||||||||||||||
export type BaseSystemFields<T = never> = { | ||||||||||||||||||||||||||||||||||
id: RecordIdString | ||||||||||||||||||||||||||||||||||
collectionId: string | ||||||||||||||||||||||||||||||||||
collectionName: Collections | ||||||||||||||||||||||||||||||||||
expand?: T | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
// Utility type to check if T is exactly unknown | ||||||||||||||||||||||||||||||||||
type IsExactlyUnknown<T> = | ||||||||||||||||||||||||||||||||||
unknown extends T | ||||||||||||||||||||||||||||||||||
? T extends unknown | ||||||||||||||||||||||||||||||||||
? keyof T extends never | ||||||||||||||||||||||||||||||||||
? true | ||||||||||||||||||||||||||||||||||
: false | ||||||||||||||||||||||||||||||||||
: false | ||||||||||||||||||||||||||||||||||
: false | ||||||||||||||||||||||||||||||||||
Comment on lines
+30
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this just return the expected type and be joined with
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
export type AuthSystemFields<T = never> = { | ||||||||||||||||||||||||||||||||||
email: string | ||||||||||||||||||||||||||||||||||
emailVisibility: boolean | ||||||||||||||||||||||||||||||||||
username: string | ||||||||||||||||||||||||||||||||||
verified: boolean | ||||||||||||||||||||||||||||||||||
// System fields | ||||||||||||||||||||||||||||||||||
export type BaseSystemFields<T = unknown> = IsExactlyUnknown<T> extends true | ||||||||||||||||||||||||||||||||||
? { | ||||||||||||||||||||||||||||||||||
id: RecordIdString | ||||||||||||||||||||||||||||||||||
collectionId: string | ||||||||||||||||||||||||||||||||||
collectionName: Collections | ||||||||||||||||||||||||||||||||||
expand?: unknown | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
: { | ||||||||||||||||||||||||||||||||||
id: RecordIdString | ||||||||||||||||||||||||||||||||||
collectionId: string | ||||||||||||||||||||||||||||||||||
collectionName: Collections | ||||||||||||||||||||||||||||||||||
expand: T | ||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
export type AuthSystemFields<T = unknown> = { | ||||||||||||||||||||||||||||||||||
email: string | ||||||||||||||||||||||||||||||||||
emailVisibility: boolean | ||||||||||||||||||||||||||||||||||
username: string | ||||||||||||||||||||||||||||||||||
verified: boolean | ||||||||||||||||||||||||||||||||||
} & BaseSystemFields<T> | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// Record types for each collection | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these nested conditions necessary? I would keep it simple since it's really just checking for the default param