chore: joiner config entity property (#9084)
This commit is contained in:
committed by
GitHub
parent
28dc8d4d17
commit
fdd0543011
@@ -61,57 +61,57 @@ describe("joiner-config-builder", () => {
|
||||
alias: [
|
||||
{
|
||||
name: ["fulfillment_set", "fulfillment_sets"],
|
||||
entity: FulfillmentSet.name,
|
||||
args: {
|
||||
entity: FulfillmentSet.name,
|
||||
methodSuffix: "FulfillmentSets",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["shipping_option", "shipping_options"],
|
||||
entity: ShippingOption.name,
|
||||
args: {
|
||||
entity: ShippingOption.name,
|
||||
methodSuffix: "ShippingOptions",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["shipping_profile", "shipping_profiles"],
|
||||
entity: ShippingProfile.name,
|
||||
args: {
|
||||
entity: ShippingProfile.name,
|
||||
methodSuffix: "ShippingProfiles",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["fulfillment", "fulfillments"],
|
||||
entity: Fulfillment.name,
|
||||
args: {
|
||||
entity: Fulfillment.name,
|
||||
methodSuffix: "Fulfillments",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["fulfillment_provider", "fulfillment_providers"],
|
||||
entity: FulfillmentProvider.name,
|
||||
args: {
|
||||
entity: FulfillmentProvider.name,
|
||||
methodSuffix: "FulfillmentProviders",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["service_zone", "service_zones"],
|
||||
entity: ServiceZone.name,
|
||||
args: {
|
||||
entity: ServiceZone.name,
|
||||
methodSuffix: "ServiceZones",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["geo_zone", "geo_zones"],
|
||||
entity: GeoZone.name,
|
||||
args: {
|
||||
entity: GeoZone.name,
|
||||
methodSuffix: "GeoZones",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["shipping_option_rule", "shipping_option_rules"],
|
||||
entity: ShippingOptionRule.name,
|
||||
args: {
|
||||
entity: ShippingOptionRule.name,
|
||||
methodSuffix: "ShippingOptionRules",
|
||||
},
|
||||
},
|
||||
@@ -124,8 +124,8 @@ describe("joiner-config-builder", () => {
|
||||
alias: [
|
||||
{
|
||||
name: ["custom", "customs"],
|
||||
entity: "Custom",
|
||||
args: {
|
||||
entity: "Custom",
|
||||
methodSuffix: "Customs",
|
||||
},
|
||||
},
|
||||
@@ -140,8 +140,8 @@ describe("joiner-config-builder", () => {
|
||||
alias: [
|
||||
{
|
||||
name: ["custom", "customs"],
|
||||
entity: "Custom",
|
||||
args: {
|
||||
entity: "Custom",
|
||||
methodSuffix: "Customs",
|
||||
},
|
||||
},
|
||||
@@ -164,8 +164,8 @@ describe("joiner-config-builder", () => {
|
||||
alias: [
|
||||
{
|
||||
name: ["custom", "customs"],
|
||||
entity: "Custom",
|
||||
args: {
|
||||
entity: "Custom",
|
||||
methodSuffix: "Customs",
|
||||
},
|
||||
},
|
||||
@@ -189,64 +189,64 @@ describe("joiner-config-builder", () => {
|
||||
alias: [
|
||||
{
|
||||
name: ["custom", "customs"],
|
||||
entity: "Custom",
|
||||
args: {
|
||||
entity: "Custom",
|
||||
methodSuffix: "Customs",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["fulfillment_set", "fulfillment_sets"],
|
||||
entity: FulfillmentSet.name,
|
||||
args: {
|
||||
entity: FulfillmentSet.name,
|
||||
methodSuffix: "FulfillmentSets",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["shipping_option", "shipping_options"],
|
||||
entity: ShippingOption.name,
|
||||
args: {
|
||||
entity: ShippingOption.name,
|
||||
methodSuffix: "ShippingOptions",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["shipping_profile", "shipping_profiles"],
|
||||
entity: ShippingProfile.name,
|
||||
args: {
|
||||
entity: ShippingProfile.name,
|
||||
methodSuffix: "ShippingProfiles",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["fulfillment", "fulfillments"],
|
||||
entity: Fulfillment.name,
|
||||
args: {
|
||||
entity: Fulfillment.name,
|
||||
methodSuffix: "Fulfillments",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["fulfillment_provider", "fulfillment_providers"],
|
||||
entity: FulfillmentProvider.name,
|
||||
args: {
|
||||
entity: FulfillmentProvider.name,
|
||||
methodSuffix: "FulfillmentProviders",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["service_zone", "service_zones"],
|
||||
entity: ServiceZone.name,
|
||||
args: {
|
||||
entity: ServiceZone.name,
|
||||
methodSuffix: "ServiceZones",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["geo_zone", "geo_zones"],
|
||||
entity: GeoZone.name,
|
||||
args: {
|
||||
entity: GeoZone.name,
|
||||
methodSuffix: "GeoZones",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["shipping_option_rule", "shipping_option_rules"],
|
||||
entity: ShippingOptionRule.name,
|
||||
args: {
|
||||
entity: ShippingOptionRule.name,
|
||||
methodSuffix: "ShippingOptionRules",
|
||||
},
|
||||
},
|
||||
@@ -259,9 +259,8 @@ describe("joiner-config-builder", () => {
|
||||
alias: [
|
||||
{
|
||||
name: ["custom", "customs"],
|
||||
args: {
|
||||
entity: "Custom",
|
||||
},
|
||||
entity: "Custom",
|
||||
args: {},
|
||||
},
|
||||
],
|
||||
})
|
||||
@@ -274,8 +273,8 @@ describe("joiner-config-builder", () => {
|
||||
alias: [
|
||||
{
|
||||
name: ["custom", "customs"],
|
||||
entity: "Custom",
|
||||
args: {
|
||||
entity: "Custom",
|
||||
methodSuffix: "Customs",
|
||||
},
|
||||
},
|
||||
@@ -283,14 +282,14 @@ describe("joiner-config-builder", () => {
|
||||
})
|
||||
})
|
||||
|
||||
it("should return a full joiner configuration with custom aliases overriding defaults", () => {
|
||||
it.only("should return a full joiner configuration with custom aliases overriding defaults", () => {
|
||||
const joinerConfig = defineJoinerConfig(Modules.FULFILLMENT, {
|
||||
models: [FulfillmentSet],
|
||||
alias: [
|
||||
{
|
||||
name: ["fulfillment_set", "fulfillment_sets"],
|
||||
entity: "FulfillmentSet",
|
||||
args: {
|
||||
entity: "FulfillmentSet",
|
||||
methodSuffix: "fulfillmentSetCustom",
|
||||
},
|
||||
},
|
||||
@@ -307,8 +306,8 @@ describe("joiner-config-builder", () => {
|
||||
alias: [
|
||||
{
|
||||
name: ["fulfillment_set", "fulfillment_sets"],
|
||||
entity: "FulfillmentSet",
|
||||
args: {
|
||||
entity: "FulfillmentSet",
|
||||
methodSuffix: "fulfillmentSetCustom",
|
||||
},
|
||||
},
|
||||
@@ -349,57 +348,57 @@ describe("joiner-config-builder", () => {
|
||||
alias: [
|
||||
{
|
||||
name: ["fulfillment_set", "fulfillment_sets"],
|
||||
entity: FulfillmentSet.name,
|
||||
args: {
|
||||
entity: FulfillmentSet.name,
|
||||
methodSuffix: "FulfillmentSets",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["shipping_option", "shipping_options"],
|
||||
entity: ShippingOption.name,
|
||||
args: {
|
||||
entity: ShippingOption.name,
|
||||
methodSuffix: "ShippingOptions",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["shipping_profile", "shipping_profiles"],
|
||||
entity: ShippingProfile.name,
|
||||
args: {
|
||||
entity: ShippingProfile.name,
|
||||
methodSuffix: "ShippingProfiles",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["fulfillment", "fulfillments"],
|
||||
entity: Fulfillment.name,
|
||||
args: {
|
||||
entity: Fulfillment.name,
|
||||
methodSuffix: "Fulfillments",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["fulfillment_provider", "fulfillment_providers"],
|
||||
entity: FulfillmentProvider.name,
|
||||
args: {
|
||||
entity: FulfillmentProvider.name,
|
||||
methodSuffix: "FulfillmentProviders",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["service_zone", "service_zones"],
|
||||
entity: ServiceZone.name,
|
||||
args: {
|
||||
entity: ServiceZone.name,
|
||||
methodSuffix: "ServiceZones",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["geo_zone", "geo_zones"],
|
||||
entity: GeoZone.name,
|
||||
args: {
|
||||
entity: GeoZone.name,
|
||||
methodSuffix: "GeoZones",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["shipping_option_rule", "shipping_option_rules"],
|
||||
entity: ShippingOptionRule.name,
|
||||
args: {
|
||||
entity: ShippingOptionRule.name,
|
||||
methodSuffix: "ShippingOptionRules",
|
||||
},
|
||||
},
|
||||
@@ -518,6 +517,7 @@ describe("joiner-config-builder", () => {
|
||||
car: {
|
||||
id: {
|
||||
field: "car",
|
||||
entity: "Car",
|
||||
linkable: "car_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "myService",
|
||||
@@ -527,6 +527,7 @@ describe("joiner-config-builder", () => {
|
||||
user: {
|
||||
id: {
|
||||
field: "user",
|
||||
entity: "User",
|
||||
linkable: "user_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "myService",
|
||||
@@ -537,12 +538,14 @@ describe("joiner-config-builder", () => {
|
||||
|
||||
expect(linkConfig.car.toJSON()).toEqual({
|
||||
field: "car",
|
||||
entity: "Car",
|
||||
linkable: "car_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "myService",
|
||||
})
|
||||
expect(linkConfig.user.toJSON()).toEqual({
|
||||
field: "user",
|
||||
entity: "User",
|
||||
linkable: "user_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "myService",
|
||||
@@ -559,6 +562,7 @@ describe("joiner-config-builder", () => {
|
||||
user: {
|
||||
id: {
|
||||
field: "user",
|
||||
entity: "User",
|
||||
linkable: "user_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "myService",
|
||||
@@ -568,6 +572,7 @@ describe("joiner-config-builder", () => {
|
||||
currency: {
|
||||
code: {
|
||||
field: "currency",
|
||||
entity: "Currency",
|
||||
linkable: "currency_code",
|
||||
primaryKey: "code",
|
||||
serviceName: "myService",
|
||||
@@ -578,12 +583,14 @@ describe("joiner-config-builder", () => {
|
||||
|
||||
expect(linkConfig.user.toJSON()).toEqual({
|
||||
field: "user",
|
||||
entity: "User",
|
||||
linkable: "user_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "myService",
|
||||
})
|
||||
expect(linkConfig.currency.toJSON()).toEqual({
|
||||
field: "currency",
|
||||
entity: "Currency",
|
||||
linkable: "currency_code",
|
||||
primaryKey: "code",
|
||||
serviceName: "myService",
|
||||
@@ -645,12 +652,14 @@ describe("joiner-config-builder", () => {
|
||||
expect(linkConfig.user.id).toEqual({
|
||||
serviceName: "myService",
|
||||
field: "user",
|
||||
entity: "User",
|
||||
linkable: "user_id",
|
||||
primaryKey: "id",
|
||||
})
|
||||
expect(linkConfig.car.number_plate).toEqual({
|
||||
serviceName: "myService",
|
||||
field: "car",
|
||||
entity: "Car",
|
||||
linkable: "car_number_plate",
|
||||
primaryKey: "number_plate",
|
||||
})
|
||||
@@ -658,12 +667,14 @@ describe("joiner-config-builder", () => {
|
||||
expect(linkConfig.car.toJSON()).toEqual({
|
||||
serviceName: "myService",
|
||||
field: "car",
|
||||
entity: "Car",
|
||||
linkable: "car_number_plate",
|
||||
primaryKey: "number_plate",
|
||||
})
|
||||
expect(linkConfig.user.toJSON()).toEqual({
|
||||
serviceName: "myService",
|
||||
field: "user",
|
||||
entity: "User",
|
||||
linkable: "user_id",
|
||||
primaryKey: "id",
|
||||
})
|
||||
|
||||
@@ -13,6 +13,8 @@ export interface DefineLinkExport {
|
||||
type InputSource = {
|
||||
serviceName: string
|
||||
field: string
|
||||
entity?: string
|
||||
alias?: string
|
||||
linkable: string
|
||||
primaryKey: string
|
||||
}
|
||||
@@ -44,7 +46,9 @@ type DefineLinkInputSource = InputSource | InputOptions | CombinedSource
|
||||
|
||||
type ModuleLinkableKeyConfig = {
|
||||
module: string
|
||||
entity?: string
|
||||
key: string
|
||||
field: string
|
||||
isList?: boolean
|
||||
deleteCascade?: boolean
|
||||
primaryKey: string
|
||||
@@ -74,11 +78,13 @@ function prepareServiceConfig(input: DefineLinkInputSource) {
|
||||
|
||||
serviceConfig = {
|
||||
key: source.linkable,
|
||||
alias: camelToSnakeCase(source.field),
|
||||
alias: source.alias ?? camelToSnakeCase(source.field),
|
||||
field: source.field,
|
||||
primaryKey: source.primaryKey,
|
||||
isList: false,
|
||||
deleteCascade: false,
|
||||
module: source.serviceName,
|
||||
entity: source.entity,
|
||||
}
|
||||
} else if (isInputOptions(input)) {
|
||||
const source = isToJSON(input.linkable)
|
||||
@@ -87,11 +93,13 @@ function prepareServiceConfig(input: DefineLinkInputSource) {
|
||||
|
||||
serviceConfig = {
|
||||
key: source.linkable,
|
||||
alias: camelToSnakeCase(source.field),
|
||||
alias: source.alias ?? camelToSnakeCase(source.field),
|
||||
field: source.field,
|
||||
primaryKey: source.primaryKey,
|
||||
isList: input.isList ?? false,
|
||||
deleteCascade: input.deleteCascade ?? false,
|
||||
module: source.serviceName,
|
||||
entity: source.entity,
|
||||
}
|
||||
} else {
|
||||
throw new Error(
|
||||
@@ -176,7 +184,7 @@ ${serviceBObj.module}: {
|
||||
let aliasAOptions =
|
||||
serviceAObj.alias ??
|
||||
serviceAAliases.find((a) => {
|
||||
return a.args?.entity == serviceAKeyEntity
|
||||
return a.entity == serviceAKeyEntity
|
||||
})?.name
|
||||
|
||||
let aliasA = aliasAOptions
|
||||
@@ -190,10 +198,11 @@ ${serviceBObj.module}: {
|
||||
)
|
||||
}
|
||||
|
||||
const serviceAObjEntryPoint = camelToSnakeCase(serviceAObj.field)
|
||||
const serviceAMethodSuffix = serviceAAliases.find((serviceAlias) => {
|
||||
return Array.isArray(serviceAlias.name)
|
||||
? serviceAlias.name.includes(aliasA)
|
||||
: serviceAlias.name === aliasA
|
||||
? serviceAlias.name.includes(serviceAObjEntryPoint)
|
||||
: serviceAlias.name === serviceAObjEntryPoint
|
||||
})?.args?.methodSuffix
|
||||
|
||||
let serviceBAliases = serviceBInfo.alias ?? []
|
||||
@@ -204,7 +213,7 @@ ${serviceBObj.module}: {
|
||||
let aliasBOptions =
|
||||
serviceBObj.alias ??
|
||||
serviceBAliases.find((a) => {
|
||||
return a.args?.entity == serviceBKeyInfo
|
||||
return a.entity == serviceBKeyInfo
|
||||
})?.name
|
||||
|
||||
let aliasB = aliasBOptions
|
||||
@@ -218,10 +227,11 @@ ${serviceBObj.module}: {
|
||||
)
|
||||
}
|
||||
|
||||
const serviceBObjEntryPoint = camelToSnakeCase(serviceBObj.field)
|
||||
const serviceBMethodSuffix = serviceBAliases.find((serviceAlias) => {
|
||||
return Array.isArray(serviceAlias.name)
|
||||
? serviceAlias.name.includes(aliasB)
|
||||
: serviceAlias.name === aliasB
|
||||
? serviceAlias.name.includes(serviceBObjEntryPoint)
|
||||
: serviceAlias.name === serviceBObjEntryPoint
|
||||
})?.args?.methodSuffix
|
||||
|
||||
const moduleAPrimaryKeys = serviceAInfo.primaryKeys ?? []
|
||||
@@ -290,6 +300,7 @@ ${serviceBObj.module}: {
|
||||
relationships: [
|
||||
{
|
||||
serviceName: serviceAObj.module,
|
||||
entity: serviceAObj.entity,
|
||||
primaryKey: serviceAPrimaryKey,
|
||||
foreignKey: serviceAObj.key,
|
||||
alias: aliasA,
|
||||
@@ -300,6 +311,7 @@ ${serviceBObj.module}: {
|
||||
},
|
||||
{
|
||||
serviceName: serviceBObj.module,
|
||||
entity: serviceBObj.entity,
|
||||
primaryKey: serviceBPrimaryKey!,
|
||||
foreignKey: serviceBObj.key,
|
||||
alias: aliasB,
|
||||
@@ -316,6 +328,7 @@ ${serviceBObj.module}: {
|
||||
[serviceBObj.isList ? pluralize(aliasB) : aliasB]: {
|
||||
path: aliasB + "_link." + aliasB,
|
||||
isList: serviceBObj.isList,
|
||||
forwardArgumentsOnPath: [aliasB + "_link." + aliasB],
|
||||
},
|
||||
},
|
||||
relationship: {
|
||||
@@ -332,6 +345,7 @@ ${serviceBObj.module}: {
|
||||
[serviceAObj.isList ? pluralize(aliasA) : aliasA]: {
|
||||
path: aliasA + "_link." + aliasA,
|
||||
isList: serviceAObj.isList,
|
||||
forwardArgumentsOnPath: [aliasA + "_link." + aliasA],
|
||||
},
|
||||
},
|
||||
relationship: {
|
||||
|
||||
@@ -193,17 +193,17 @@ export function defineJoinerConfig(
|
||||
alias: [
|
||||
...[...(alias ?? ([] as any))].map((alias) => ({
|
||||
name: alias.name,
|
||||
entity: alias.entity,
|
||||
args: {
|
||||
entity: alias.args.entity,
|
||||
methodSuffix:
|
||||
alias.args.methodSuffix ??
|
||||
pluralize(upperCaseFirst(alias.args.entity)),
|
||||
alias.args?.methodSuffix ?? pluralize(upperCaseFirst(alias.entity)),
|
||||
},
|
||||
})),
|
||||
...deduplicatedLoadedModels
|
||||
.filter((model) => {
|
||||
return (
|
||||
!alias || !alias.some((alias) => alias.args?.entity === model.name)
|
||||
!alias ||
|
||||
!alias.some((alias) => alias.entity === upperCaseFirst(model.name))
|
||||
)
|
||||
})
|
||||
.map((entity, i) => ({
|
||||
@@ -211,8 +211,8 @@ export function defineJoinerConfig(
|
||||
`${camelToSnakeCase(entity.name).toLowerCase()}`,
|
||||
`${pluralize(camelToSnakeCase(entity.name).toLowerCase())}`,
|
||||
],
|
||||
entity: upperCaseFirst(entity.name),
|
||||
args: {
|
||||
entity: upperCaseFirst(entity.name),
|
||||
methodSuffix: pluralize(upperCaseFirst(entity.name)),
|
||||
},
|
||||
})),
|
||||
@@ -378,6 +378,7 @@ export function buildLinkConfigFromModelObjects<
|
||||
primaryKey: property,
|
||||
serviceName,
|
||||
field: lowerCaseFirst(model.name),
|
||||
entity: upperCaseFirst(model.name),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -412,6 +413,7 @@ export function buildLinkConfigFromLinkableKeys<
|
||||
primaryKey: inferredReferenceProperty,
|
||||
serviceName,
|
||||
field: keyName,
|
||||
entity: upperCaseFirst(modelName),
|
||||
}
|
||||
|
||||
linkConfig[keyName] ??= {
|
||||
|
||||
Reference in New Issue
Block a user