Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to specify flow ID when inserting new rows #125

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unocha/hpc-api-core",
"version": "6.0.0",
"version": "6.1.0",
"description": "Core libraries supporting HPC.Tools API Backend",
"license": "Apache-2.0",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion src/db/models/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const FLOW_ID = brandedType<number, FlowId>(t.number);
export default defineIDModel({
tableName: 'flow',
fields: {
generated: {
generatedCompositeKey: {
id: { kind: 'branded-integer', brand: FLOW_ID },
},
required: {
Expand Down
3 changes: 2 additions & 1 deletion src/db/util/id-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export type { FieldsWithSequelize as FieldsWithId };
export const defineIDModel =
<
F extends FieldDefinition,
IDField extends string & keyof F['generated'],
IDField extends string &
(keyof F['generated'] | keyof F['generatedCompositeKey']),
SoftDeletionEnabled extends boolean
>(opts: {
tableName: string;
Expand Down
10 changes: 9 additions & 1 deletion src/db/util/model-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export type FieldDefinition = {
* such ids that use autoIncrement.
*/
generated?: FieldSet;
/**
* Same as `generated`, but indicates that auto-incremented ID is used as
* part of a composite primary key on the table, thus we need to make it
* possible for client code to specify these IDs when inserting new rows.
*/
generatedCompositeKey?: FieldSet;
nonNullWithDefault?: FieldSet;
optional?: FieldSet;
accidentallyOptional?: FieldSet;
Expand All @@ -68,14 +74,16 @@ export type FieldValuesOfSet<Set extends FieldSet | undefined> =
export type InstanceDataOf<F extends FieldDefinition> = FieldValuesOfSet<
F['generated']
> &
FieldValuesOfSet<F['generatedCompositeKey']> &
FieldValuesOfSet<F['nonNullWithDefault']> &
FieldValuesOfSet<F['required']> &
Nullable<FieldValuesOfSet<F['optional']>> &
Nullable<FieldValuesOfSet<F['accidentallyOptional']>>;

export type UserDataOf<F extends FieldDefinition> = Partial<
FieldValuesOfSet<F['nonNullWithDefault']>
FieldValuesOfSet<F['generatedCompositeKey']>
> &
Partial<FieldValuesOfSet<F['nonNullWithDefault']>> &
FieldValuesOfSet<F['required']> &
FieldValuesOfSet<F['accidentallyOptional']> &
Partial<Nullable<FieldValuesOfSet<F['optional']>>>;