diff --git a/package.json b/package.json index be01076e..a0daf565 100644 --- a/package.json +++ b/package.json @@ -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, diff --git a/src/db/models/flow.ts b/src/db/models/flow.ts index 74e35b6e..18b36cd1 100644 --- a/src/db/models/flow.ts +++ b/src/db/models/flow.ts @@ -12,7 +12,7 @@ export const FLOW_ID = brandedType(t.number); export default defineIDModel({ tableName: 'flow', fields: { - generated: { + generatedCompositeKey: { id: { kind: 'branded-integer', brand: FLOW_ID }, }, required: { diff --git a/src/db/util/id-model.ts b/src/db/util/id-model.ts index c21fa044..ea0af2e1 100644 --- a/src/db/util/id-model.ts +++ b/src/db/util/id-model.ts @@ -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; diff --git a/src/db/util/model-definition.ts b/src/db/util/model-definition.ts index 9da4ab1c..b4829d26 100644 --- a/src/db/util/model-definition.ts +++ b/src/db/util/model-definition.ts @@ -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; @@ -68,14 +74,16 @@ export type FieldValuesOfSet = export type InstanceDataOf = FieldValuesOfSet< F['generated'] > & + FieldValuesOfSet & FieldValuesOfSet & FieldValuesOfSet & Nullable> & Nullable>; export type UserDataOf = Partial< - FieldValuesOfSet + FieldValuesOfSet > & + Partial> & FieldValuesOfSet & FieldValuesOfSet & Partial>>;