chore: export DML builders + fix default undefined values in SQL (#7776)
* chore: export dml builders through utils * chore: fix undefined sql error * chore: upgrade to ts 5 * chore: use isDefined
This commit is contained in:
@@ -37,6 +37,6 @@
|
||||
"form-data": "^4.0.0",
|
||||
"jest": "^29.7.0",
|
||||
"jest-environment-node": "^29.7.0",
|
||||
"typescript": "^4.1.3"
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,6 @@
|
||||
"@swc/jest": "^0.2.36",
|
||||
"jest": "^29.7.0",
|
||||
"jest-environment-node": "^29.7.0",
|
||||
"typescript": "^4.1.3"
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,6 @@
|
||||
"@swc/jest": "^0.2.36",
|
||||
"jest": "^29.7.0",
|
||||
"jest-environment-node": "^29.7.0",
|
||||
"typescript": "^4.1.3"
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"typescript": "^4.9.5"
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/utils": "^1.11.2",
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"@swc/jest": "^0.2.36",
|
||||
"cross-env": "^7.0.3",
|
||||
"jest": "^29.7.0",
|
||||
"typescript": "^4.4.4"
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"homepage": "https://github.com/medusajs/medusa/tree/master/packages/medusa-dev-cli#readme",
|
||||
"keywords": [
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
export * as ApiKeyUtils from "./api-key"
|
||||
export * as DALUtils from "./dal"
|
||||
export * as DecoratorUtils from "./decorators"
|
||||
export * as DefaultsUtils from "./defaults"
|
||||
export * as DMLUtils from "./dml"
|
||||
export * as EventBusUtils from "./event-bus"
|
||||
export * as FeatureFlagUtils from "./feature-flags"
|
||||
export * as FulfillmentUtils from "./fulfillment"
|
||||
export * as InventoryUtils from "./inventory"
|
||||
export * as LinkUtils from "./link"
|
||||
export * as ModulesSdkUtils from "./modules-sdk"
|
||||
export * as OrchestrationUtils from "./orchestration"
|
||||
export * as OrderUtils from "./order"
|
||||
@@ -12,6 +16,3 @@ export * as PromotionUtils from "./promotion"
|
||||
export * as SearchUtils from "./search"
|
||||
export * as ShippingProfileUtils from "./shipping"
|
||||
export * as UserUtils from "./user"
|
||||
export * as InventoryUtils from "./inventory"
|
||||
export * as LinkUtils from "./link"
|
||||
export * as ApiKeyUtils from "./api-key"
|
||||
|
||||
@@ -1,39 +1,40 @@
|
||||
import {
|
||||
Enum,
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
OneToMany,
|
||||
Property,
|
||||
OneToOne,
|
||||
Enum,
|
||||
Filter,
|
||||
ManyToMany,
|
||||
ManyToOne,
|
||||
Filter,
|
||||
PrimaryKey,
|
||||
BeforeCreate,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
OnInit,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DmlEntity } from "../entity"
|
||||
import { DALUtils } from "../../bundles"
|
||||
import {
|
||||
pluralize,
|
||||
camelToSnakeCase,
|
||||
createPsqlIndexStatementHelper,
|
||||
toCamelCase,
|
||||
generateEntityId,
|
||||
isDefined,
|
||||
pluralize,
|
||||
toCamelCase,
|
||||
} from "../../common"
|
||||
import { upperCaseFirst } from "../../common/upper-case-first"
|
||||
import { DmlEntity } from "../entity"
|
||||
import { HasMany } from "../relations/has-many"
|
||||
import { HasOne } from "../relations/has-one"
|
||||
import { ManyToMany as DmlManyToMany } from "../relations/many-to-many"
|
||||
import type {
|
||||
Infer,
|
||||
PropertyType,
|
||||
EntityCascades,
|
||||
EntityConstructor,
|
||||
Infer,
|
||||
KnownDataTypes,
|
||||
PropertyMetadata,
|
||||
RelationshipType,
|
||||
EntityConstructor,
|
||||
PropertyType,
|
||||
RelationshipMetadata,
|
||||
RelationshipType,
|
||||
} from "../types"
|
||||
import { DALUtils } from "../../bundles"
|
||||
import { HasOne } from "../relations/has-one"
|
||||
import { HasMany } from "../relations/has-many"
|
||||
import { ManyToMany as DmlManyToMany } from "../relations/many-to-many"
|
||||
|
||||
/**
|
||||
* DML entity data types to PostgreSQL data types via
|
||||
@@ -169,7 +170,12 @@ export function createMikrORMEntity() {
|
||||
Enum({
|
||||
items: () => field.dataType.options!.choices,
|
||||
nullable: field.nullable,
|
||||
default: field.defaultValue,
|
||||
/**
|
||||
* MikroORM does not ignore undefined values for default when generating
|
||||
* the database schema SQL. Conditionally add it here to prevent undefined
|
||||
* from being set as default value in SQL.
|
||||
*/
|
||||
...(isDefined(field.defaultValue) && { default: field.defaultValue }),
|
||||
})(MikroORMEntity.prototype, field.fieldName)
|
||||
return
|
||||
}
|
||||
@@ -217,7 +223,12 @@ export function createMikrORMEntity() {
|
||||
columnType,
|
||||
type: propertyType,
|
||||
nullable: field.nullable,
|
||||
default: field.defaultValue,
|
||||
/**
|
||||
* MikroORM does not ignore undefined values for default when generating
|
||||
* the database schema SQL. Conditionally add it here to prevent undefined
|
||||
* from being set as default value in SQL.
|
||||
*/
|
||||
...(isDefined(field.defaultValue) && { default: field.defaultValue }),
|
||||
})(MikroORMEntity.prototype, field.fieldName)
|
||||
}
|
||||
|
||||
|
||||
2
packages/core/utils/src/dml/index.ts
Normal file
2
packages/core/utils/src/dml/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./entity-builder"
|
||||
export * from "./helpers/create-mikro-orm-entity"
|
||||
@@ -1,15 +1,20 @@
|
||||
export * from "./api-key"
|
||||
export * from "./auth"
|
||||
export * from "./bundles"
|
||||
export * from "./common"
|
||||
export * from "./dal"
|
||||
export * from "./decorators"
|
||||
export * from "./defaults"
|
||||
export * from "./dml"
|
||||
export * from "./event-bus"
|
||||
export * from "./exceptions"
|
||||
export * from "./feature-flags"
|
||||
export * from "./file"
|
||||
export * from "./fulfillment"
|
||||
export * from "./inventory"
|
||||
export * from "./link"
|
||||
export * from "./modules-sdk"
|
||||
export * from "./notification"
|
||||
export * from "./orchestration"
|
||||
export * from "./order"
|
||||
export * from "./payment"
|
||||
@@ -21,9 +26,5 @@ export * from "./shipping"
|
||||
export * from "./totals"
|
||||
export * from "./totals/big-number"
|
||||
export * from "./user"
|
||||
export * from "./api-key"
|
||||
export * from "./link"
|
||||
export * from "./file"
|
||||
export * from "./notification"
|
||||
|
||||
export const MedusaModuleType = Symbol.for("MedusaModule")
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
"rimraf": "^5.0.1",
|
||||
"supertest": "^4.0.2",
|
||||
"ts-jest": "^29.1.1",
|
||||
"typescript": "^4.4.4"
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"scripts": {
|
||||
"watch": "tsc --build --watch",
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"typescript": "^4.9.5"
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/utils": "^1.11.7",
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"typescript": "^4.9.5"
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/utils": "^1.11.7"
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"typescript": "^4.9.5"
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.556.0",
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"typescript": "^4.9.5"
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/utils": "^1.11.7",
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"typescript": "^4.9.5"
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/utils": "^1.11.7"
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"typescript": "^4.9.5"
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/utils": "^1.11.7",
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"typescript": "^4.9.5"
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@medusajs/medusa": "^1.12.0"
|
||||
|
||||
30
yarn.lock
30
yarn.lock
@@ -4256,7 +4256,7 @@ __metadata:
|
||||
jest: ^29.7.0
|
||||
rimraf: ^5.0.1
|
||||
scrypt-kdf: ^2.0.1
|
||||
typescript: ^4.9.5
|
||||
typescript: ^5.3.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -4527,7 +4527,7 @@ __metadata:
|
||||
cross-env: ^5.2.1
|
||||
jest: ^29.7.0
|
||||
rimraf: ^5.0.1
|
||||
typescript: ^4.9.5
|
||||
typescript: ^5.3.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -4542,7 +4542,7 @@ __metadata:
|
||||
cross-env: ^5.2.1
|
||||
jest: ^29.7.0
|
||||
rimraf: ^5.0.1
|
||||
typescript: ^4.9.5
|
||||
typescript: ^5.3.3
|
||||
ulid: ^2.3.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
@@ -4585,7 +4585,7 @@ __metadata:
|
||||
express: ^4.17.1
|
||||
jest: ^29.7.0
|
||||
rimraf: ^5.0.1
|
||||
typescript: ^4.9.5
|
||||
typescript: ^5.3.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -4755,7 +4755,7 @@ __metadata:
|
||||
rimraf: ^5.0.1
|
||||
semver: ^7.3.8
|
||||
stack-trace: ^0.0.10
|
||||
typescript: ^4.9.5
|
||||
typescript: ^5.3.3
|
||||
ulid: ^2.3.0
|
||||
winston: ^3.8.2
|
||||
yargs: ^15.3.1
|
||||
@@ -4849,7 +4849,7 @@ __metadata:
|
||||
rimraf: ^5.0.1
|
||||
supertest: ^4.0.2
|
||||
ts-jest: ^29.1.1
|
||||
typescript: ^4.4.4
|
||||
typescript: ^5.3.3
|
||||
uuid: ^9.0.0
|
||||
zod: 3.22.4
|
||||
languageName: unknown
|
||||
@@ -4885,7 +4885,7 @@ __metadata:
|
||||
cross-env: ^5.2.1
|
||||
jest: ^29.7.0
|
||||
rimraf: ^5.0.1
|
||||
typescript: ^4.9.5
|
||||
typescript: ^5.3.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -4900,7 +4900,7 @@ __metadata:
|
||||
cross-env: ^5.2.1
|
||||
jest: ^29.7.0
|
||||
rimraf: ^5.0.1
|
||||
typescript: ^4.9.5
|
||||
typescript: ^5.3.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -4993,7 +4993,7 @@ __metadata:
|
||||
jest: ^29.7.0
|
||||
rimraf: ^5.0.1
|
||||
stripe: latest
|
||||
typescript: ^4.9.5
|
||||
typescript: ^5.3.3
|
||||
peerDependencies:
|
||||
"@medusajs/medusa": ^1.12.0
|
||||
languageName: unknown
|
||||
@@ -18385,7 +18385,7 @@ __metadata:
|
||||
jest-environment-node: ^29.7.0
|
||||
pg: ^8.11.0
|
||||
typeorm: ^0.3.16
|
||||
typescript: ^4.1.3
|
||||
typescript: ^5.3.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -18421,7 +18421,7 @@ __metadata:
|
||||
jest-environment-node: ^29.7.0
|
||||
medusa-test-utils: "workspace:*"
|
||||
pg: ^8.11.0
|
||||
typescript: ^4.1.3
|
||||
typescript: ^5.3.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -18458,7 +18458,7 @@ __metadata:
|
||||
medusa-test-utils: "workspace:*"
|
||||
pg: ^8.11.0
|
||||
typeorm: ^0.3.16
|
||||
typescript: ^4.1.3
|
||||
typescript: ^5.3.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -21276,7 +21276,7 @@ __metadata:
|
||||
jest: ^29.7.0
|
||||
lodash: ^4.17.21
|
||||
signal-exit: ^3.0.7
|
||||
typescript: ^4.4.4
|
||||
typescript: ^5.3.3
|
||||
verdaccio: ^4.10.0
|
||||
yargs: ^15.4.1
|
||||
bin:
|
||||
@@ -28598,7 +28598,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"typescript@npm:4.9.5, typescript@npm:^4.1.3, typescript@npm:^4.4.4, typescript@npm:^4.9.5":
|
||||
"typescript@npm:4.9.5, typescript@npm:^4.1.3":
|
||||
version: 4.9.5
|
||||
resolution: "typescript@npm:4.9.5"
|
||||
bin:
|
||||
@@ -28648,7 +28648,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"typescript@patch:typescript@4.9.5#~builtin<compat/typescript>, typescript@patch:typescript@^4.1.3#~builtin<compat/typescript>, typescript@patch:typescript@^4.4.4#~builtin<compat/typescript>, typescript@patch:typescript@^4.9.5#~builtin<compat/typescript>":
|
||||
"typescript@patch:typescript@4.9.5#~builtin<compat/typescript>, typescript@patch:typescript@^4.1.3#~builtin<compat/typescript>":
|
||||
version: 4.9.5
|
||||
resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin<compat/typescript>::version=4.9.5&hash=7ad353"
|
||||
bin:
|
||||
|
||||
Reference in New Issue
Block a user