@medusajs/region 0.1.2-snapshot-20240718073308 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. package/dist/index.d.ts +4 -36
  2. package/dist/index.js +19 -9
  3. package/dist/initialize/index.d.ts +4 -0
  4. package/dist/initialize/index.js +17 -0
  5. package/dist/joiner-config.d.ts +8 -0
  6. package/dist/joiner-config.js +33 -0
  7. package/dist/loaders/connection.d.ts +4 -0
  8. package/dist/loaders/connection.js +41 -0
  9. package/dist/loaders/container.d.ts +2 -0
  10. package/dist/loaders/container.js +34 -0
  11. package/dist/loaders/defaults.d.ts +0 -1
  12. package/dist/loaders/defaults.js +3 -2
  13. package/dist/loaders/index.d.ts +2 -1
  14. package/dist/loaders/index.js +2 -0
  15. package/dist/migrations/{Migration20240205173216.d.ts → RegionModuleSetup20240205173216.d.ts} +0 -1
  16. package/dist/migrations/{Migration20240205173216.js → RegionModuleSetup20240205173216.js} +1 -1
  17. package/dist/models/country.d.ts +10 -166
  18. package/dist/models/country.js +62 -20
  19. package/dist/models/index.d.ts +0 -1
  20. package/dist/models/region.d.ts +19 -111
  21. package/dist/models/region.js +89 -8
  22. package/dist/module-definition.d.ts +4 -0
  23. package/dist/module-definition.js +51 -0
  24. package/dist/repositories/index.d.ts +1 -0
  25. package/dist/repositories/index.js +5 -0
  26. package/dist/scripts/bin/run-seed.d.ts +3 -0
  27. package/dist/scripts/bin/run-seed.js +50 -0
  28. package/dist/scripts/seed-utils.d.ts +4 -0
  29. package/dist/scripts/seed-utils.js +12 -0
  30. package/dist/services/index.d.ts +0 -1
  31. package/dist/services/region-module.d.ts +17 -22
  32. package/dist/services/region-module.js +20 -35
  33. package/dist/types/index.d.ts +0 -1
  34. package/package.json +14 -8
  35. package/dist/index.d.ts.map +0 -1
  36. package/dist/loaders/defaults.d.ts.map +0 -1
  37. package/dist/loaders/index.d.ts.map +0 -1
  38. package/dist/migrations/Migration20240205173216.d.ts.map +0 -1
  39. package/dist/migrations/Migration20240624200006.d.ts +0 -6
  40. package/dist/migrations/Migration20240624200006.d.ts.map +0 -1
  41. package/dist/migrations/Migration20240624200006.js +0 -19
  42. package/dist/models/country.d.ts.map +0 -1
  43. package/dist/models/index.d.ts.map +0 -1
  44. package/dist/models/region.d.ts.map +0 -1
  45. package/dist/services/index.d.ts.map +0 -1
  46. package/dist/services/region-module.d.ts.map +0 -1
  47. package/dist/types/index.d.ts.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,36 +1,4 @@
1
- import { RegionModuleService } from "./services";
2
- import { Modules } from "@medusajs/utils";
3
- declare const _default: import("@medusajs/types").ModuleExports<typeof RegionModuleService> & {
4
- linkable: {
5
- region: {
6
- id: {
7
- serviceName: Modules.REGION;
8
- field: "region";
9
- linkable: "region_id";
10
- primaryKey: "id";
11
- };
12
- toJSON: () => {
13
- serviceName: Modules.REGION;
14
- field: "region";
15
- linkable: "region_id";
16
- primaryKey: "id";
17
- };
18
- };
19
- country: {
20
- iso_2: {
21
- serviceName: Modules.REGION;
22
- field: "country";
23
- linkable: "country_iso_2";
24
- primaryKey: "iso_2";
25
- };
26
- toJSON: () => {
27
- serviceName: Modules.REGION;
28
- field: "country";
29
- linkable: "country_iso_2";
30
- primaryKey: "iso_2";
31
- };
32
- };
33
- };
34
- };
35
- export default _default;
36
- //# sourceMappingURL=index.d.ts.map
1
+ import { moduleDefinition, revertMigration, runMigrations } from "./module-definition";
2
+ export default moduleDefinition;
3
+ export { revertMigration, runMigrations };
4
+ export * from "./initialize";
package/dist/index.js CHANGED
@@ -1,12 +1,22 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const services_1 = require("./services");
7
- const defaults_1 = __importDefault(require("./loaders/defaults"));
8
- const utils_1 = require("@medusajs/utils");
9
- exports.default = (0, utils_1.Module)(utils_1.Modules.REGION, {
10
- service: services_1.RegionModuleService,
11
- loaders: [defaults_1.default],
12
- });
17
+ exports.runMigrations = exports.revertMigration = void 0;
18
+ const module_definition_1 = require("./module-definition");
19
+ Object.defineProperty(exports, "revertMigration", { enumerable: true, get: function () { return module_definition_1.revertMigration; } });
20
+ Object.defineProperty(exports, "runMigrations", { enumerable: true, get: function () { return module_definition_1.runMigrations; } });
21
+ exports.default = module_definition_1.moduleDefinition;
22
+ __exportStar(require("./initialize"), exports);
@@ -0,0 +1,4 @@
1
+ import { ExternalModuleDeclaration, InternalModuleDeclaration } from "@medusajs/modules-sdk";
2
+ import { IRegionModuleService, ModulesSdkTypes } from "@medusajs/types";
3
+ import { InitializeModuleInjectableDependencies } from "../types";
4
+ export declare const initialize: (options?: ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions | ExternalModuleDeclaration | InternalModuleDeclaration, injectedDependencies?: InitializeModuleInjectableDependencies) => Promise<IRegionModuleService>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initialize = void 0;
4
+ const modules_sdk_1 = require("@medusajs/modules-sdk");
5
+ const module_definition_1 = require("../module-definition");
6
+ const initialize = async (options, injectedDependencies) => {
7
+ const serviceKey = modules_sdk_1.Modules.REGION;
8
+ const loaded = await modules_sdk_1.MedusaModule.bootstrap({
9
+ moduleKey: serviceKey,
10
+ defaultPath: modules_sdk_1.MODULE_PACKAGE_NAMES[modules_sdk_1.Modules.REGION],
11
+ declaration: options,
12
+ injectedDependencies,
13
+ moduleExports: module_definition_1.moduleDefinition,
14
+ });
15
+ return loaded[serviceKey];
16
+ };
17
+ exports.initialize = initialize;
@@ -0,0 +1,8 @@
1
+ import { ModuleJoinerConfig } from "@medusajs/types";
2
+ import { MapToConfig } from "@medusajs/utils";
3
+ export declare const LinkableKeys: {
4
+ region_id: string;
5
+ country_iso: string;
6
+ };
7
+ export declare const entityNameToLinkableKeysMap: MapToConfig;
8
+ export declare const joinerConfig: ModuleJoinerConfig;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.joinerConfig = exports.entityNameToLinkableKeysMap = exports.LinkableKeys = void 0;
4
+ const modules_sdk_1 = require("@medusajs/modules-sdk");
5
+ const _models_1 = require("./models");
6
+ exports.LinkableKeys = {
7
+ region_id: _models_1.Region.name,
8
+ country_iso: _models_1.Country.name,
9
+ };
10
+ const entityLinkableKeysMap = {};
11
+ Object.entries(exports.LinkableKeys).forEach(([key, value]) => {
12
+ entityLinkableKeysMap[value] ?? (entityLinkableKeysMap[value] = []);
13
+ entityLinkableKeysMap[value].push({
14
+ mapTo: key,
15
+ valueFrom: key.split("_").pop(),
16
+ });
17
+ });
18
+ exports.entityNameToLinkableKeysMap = entityLinkableKeysMap;
19
+ exports.joinerConfig = {
20
+ serviceName: modules_sdk_1.Modules.REGION,
21
+ primaryKeys: ["id"],
22
+ linkableKeys: exports.LinkableKeys,
23
+ alias: [
24
+ {
25
+ name: ["region", "regions"],
26
+ args: { entity: _models_1.Region.name },
27
+ },
28
+ {
29
+ name: ["country", "countries"],
30
+ args: { entity: _models_1.Country.name, methodSuffix: "Countries" },
31
+ },
32
+ ],
33
+ };
@@ -0,0 +1,4 @@
1
+ import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/modules-sdk";
2
+ import { ModulesSdkTypes } from "@medusajs/types";
3
+ declare const _default: ({ options, container, logger, }: LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions>, moduleDeclaration?: InternalModuleDeclaration) => Promise<void>;
4
+ export default _default;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const modules_sdk_1 = require("@medusajs/modules-sdk");
27
+ const utils_1 = require("@medusajs/utils");
28
+ const RegionModels = __importStar(require("../models"));
29
+ exports.default = async ({ options, container, logger, }, moduleDeclaration) => {
30
+ const entities = Object.values(RegionModels);
31
+ const pathToMigrations = __dirname + "/../migrations";
32
+ await utils_1.ModulesSdkUtils.mikroOrmConnectionLoader({
33
+ moduleName: modules_sdk_1.Modules.REGION,
34
+ entities,
35
+ container,
36
+ options,
37
+ moduleDeclaration,
38
+ logger,
39
+ pathToMigrations,
40
+ });
41
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: ({ container, options }: import("@medusajs/types").LoaderOptions) => Promise<void>;
2
+ export default _default;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const utils_1 = require("@medusajs/utils");
27
+ const ModuleModels = __importStar(require("../models"));
28
+ const ModuleRepositories = __importStar(require("../repositories"));
29
+ const ModuleServices = __importStar(require("../services"));
30
+ exports.default = utils_1.ModulesSdkUtils.moduleContainerLoaderFactory({
31
+ moduleModels: ModuleModels,
32
+ moduleRepositories: ModuleRepositories,
33
+ moduleServices: ModuleServices,
34
+ });
@@ -1,4 +1,3 @@
1
1
  import { LoaderOptions } from "@medusajs/types";
2
2
  declare const _default: ({ container }: LoaderOptions) => Promise<void>;
3
3
  export default _default;
4
- //# sourceMappingURL=defaults.d.ts.map
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const utils_1 = require("@medusajs/utils");
4
+ const utils_2 = require("@medusajs/utils");
4
5
  exports.default = async ({ container }) => {
5
6
  // TODO: Add default logger to the container when running tests
6
7
  const logger = container.resolve(utils_1.ContainerRegistrationKeys.LOGGER) ?? console;
7
8
  const countryService_ = container.resolve("countryService");
8
9
  try {
9
- const normalizedCountries = utils_1.DefaultsUtils.defaultCountries.map((c) => ({
10
+ const normalizedCountries = utils_2.DefaultsUtils.defaultCountries.map((c) => ({
10
11
  iso_2: c.alpha2.toLowerCase(),
11
12
  iso_3: c.alpha3.toLowerCase(),
12
13
  num_code: c.numeric,
@@ -14,7 +15,7 @@ exports.default = async ({ container }) => {
14
15
  display_name: c.name,
15
16
  }));
16
17
  const resp = await countryService_.upsert(normalizedCountries);
17
- logger.debug(`Loaded ${resp.length} countries`);
18
+ logger.info(`Loaded ${resp.length} countries`);
18
19
  }
19
20
  catch (error) {
20
21
  logger.warn(`Failed to load countries, skipping loader. Original error: ${error.message}`);
@@ -1,2 +1,3 @@
1
+ export * from "./connection";
2
+ export * from "./container";
1
3
  export * from "./defaults";
2
- //# sourceMappingURL=index.d.ts.map
@@ -14,4 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./connection"), exports);
18
+ __exportStar(require("./container"), exports);
17
19
  __exportStar(require("./defaults"), exports);
@@ -2,4 +2,3 @@ import { Migration } from "@mikro-orm/migrations";
2
2
  export declare class RegionModuleSetup20240205173216 extends Migration {
3
3
  up(): Promise<void>;
4
4
  }
5
- //# sourceMappingURL=Migration20240205173216.d.ts.map
@@ -27,7 +27,7 @@ CREATE INDEX IF NOT EXISTS "IDX_region_deleted_at" ON "region" ("deleted_at") WH
27
27
  CREATE TABLE IF NOT EXISTS "region_country" (
28
28
  "iso_2" text NOT NULL,
29
29
  "iso_3" text NOT NULL,
30
- "num_code" text NOT NULL,
30
+ "num_code" int NOT NULL,
31
31
  "name" text NOT NULL,
32
32
  "display_name" text NOT NULL,
33
33
  "region_id" text NULL,
@@ -1,166 +1,10 @@
1
- declare const _default: import("@medusajs/utils").DmlEntity<{
2
- iso_2: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/text").TextProperty>;
3
- iso_3: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
4
- num_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
5
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
6
- display_name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
7
- region: import("@medusajs/utils/dist/dml/relations/nullable").NullableModifier<() => import("@medusajs/utils").DmlEntity<{
8
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
9
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
10
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
11
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
12
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<() => import("@medusajs/utils").DmlEntity<any & {
13
- iso_2: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/text").TextProperty>;
14
- iso_3: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
15
- num_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
16
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
17
- display_name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
18
- region: import("@medusajs/utils/dist/dml/relations/nullable").NullableModifier<any, import("@medusajs/utils/dist/dml/relations/belongs-to").BelongsTo<any>>;
19
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
20
- } & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, {
21
- readonly name: "Country";
22
- readonly tableName: "region_country";
23
- }>>;
24
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
25
- } & {
26
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
27
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
28
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
29
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
30
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<() => import("@medusajs/utils").DmlEntity<any & {
31
- iso_2: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/text").TextProperty>;
32
- iso_3: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
33
- num_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
34
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
35
- display_name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
36
- region: import("@medusajs/utils/dist/dml/relations/nullable").NullableModifier<any, import("@medusajs/utils/dist/dml/relations/belongs-to").BelongsTo<any>>;
37
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
38
- } & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, {
39
- readonly name: "Country";
40
- readonly tableName: "region_country";
41
- }>>;
42
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
43
- } & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, "region">, import("@medusajs/utils/dist/dml/relations/belongs-to").BelongsTo<() => import("@medusajs/utils").DmlEntity<{
44
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
45
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
46
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
47
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
48
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<() => import("@medusajs/utils").DmlEntity<any & {
49
- iso_2: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/text").TextProperty>;
50
- iso_3: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
51
- num_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
52
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
53
- display_name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
54
- region: import("@medusajs/utils/dist/dml/relations/nullable").NullableModifier<any, import("@medusajs/utils/dist/dml/relations/belongs-to").BelongsTo<any>>;
55
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
56
- } & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, {
57
- readonly name: "Country";
58
- readonly tableName: "region_country";
59
- }>>;
60
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
61
- } & {
62
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
63
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
64
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
65
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
66
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<() => import("@medusajs/utils").DmlEntity<any & {
67
- iso_2: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/text").TextProperty>;
68
- iso_3: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
69
- num_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
70
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
71
- display_name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
72
- region: import("@medusajs/utils/dist/dml/relations/nullable").NullableModifier<any, import("@medusajs/utils/dist/dml/relations/belongs-to").BelongsTo<any>>;
73
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
74
- } & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, {
75
- readonly name: "Country";
76
- readonly tableName: "region_country";
77
- }>>;
78
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
79
- } & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, "region">>>;
80
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
81
- } & {
82
- iso_2: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/text").TextProperty>;
83
- iso_3: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
84
- num_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
85
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
86
- display_name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
87
- region: import("@medusajs/utils/dist/dml/relations/nullable").NullableModifier<() => import("@medusajs/utils").DmlEntity<{
88
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
89
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
90
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
91
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
92
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<() => import("@medusajs/utils").DmlEntity<{
93
- iso_2: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/text").TextProperty>;
94
- iso_3: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
95
- num_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
96
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
97
- display_name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
98
- region: import("@medusajs/utils/dist/dml/relations/nullable").NullableModifier<any, import("@medusajs/utils/dist/dml/relations/belongs-to").BelongsTo<any>>;
99
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
100
- } & any & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, {
101
- readonly name: "Country";
102
- readonly tableName: "region_country";
103
- }>>;
104
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
105
- } & {
106
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
107
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
108
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
109
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
110
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<() => import("@medusajs/utils").DmlEntity<{
111
- iso_2: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/text").TextProperty>;
112
- iso_3: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
113
- num_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
114
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
115
- display_name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
116
- region: import("@medusajs/utils/dist/dml/relations/nullable").NullableModifier<any, import("@medusajs/utils/dist/dml/relations/belongs-to").BelongsTo<any>>;
117
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
118
- } & any & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, {
119
- readonly name: "Country";
120
- readonly tableName: "region_country";
121
- }>>;
122
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
123
- } & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, "region">, import("@medusajs/utils/dist/dml/relations/belongs-to").BelongsTo<() => import("@medusajs/utils").DmlEntity<{
124
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
125
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
126
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
127
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
128
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<() => import("@medusajs/utils").DmlEntity<{
129
- iso_2: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/text").TextProperty>;
130
- iso_3: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
131
- num_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
132
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
133
- display_name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
134
- region: import("@medusajs/utils/dist/dml/relations/nullable").NullableModifier<any, import("@medusajs/utils/dist/dml/relations/belongs-to").BelongsTo<any>>;
135
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
136
- } & any & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, {
137
- readonly name: "Country";
138
- readonly tableName: "region_country";
139
- }>>;
140
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
141
- } & {
142
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
143
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
144
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
145
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
146
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<() => import("@medusajs/utils").DmlEntity<{
147
- iso_2: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/text").TextProperty>;
148
- iso_3: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
149
- num_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
150
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
151
- display_name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
152
- region: import("@medusajs/utils/dist/dml/relations/nullable").NullableModifier<any, import("@medusajs/utils/dist/dml/relations/belongs-to").BelongsTo<any>>;
153
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
154
- } & any & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, {
155
- readonly name: "Country";
156
- readonly tableName: "region_country";
157
- }>>;
158
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
159
- } & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, "region">>>;
160
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
161
- } & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, {
162
- readonly name: "Country";
163
- readonly tableName: "region_country";
164
- }>;
165
- export default _default;
166
- //# sourceMappingURL=country.d.ts.map
1
+ import Region from "./region";
2
+ export default class Country {
3
+ iso_2: string;
4
+ iso_3: string;
5
+ num_code: number;
6
+ name: string;
7
+ display_name: string;
8
+ region_id?: string | null;
9
+ region?: Region | null;
10
+ }
@@ -1,27 +1,69 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ const core_1 = require("@mikro-orm/core");
6
16
  const utils_1 = require("@medusajs/utils");
7
17
  const region_1 = __importDefault(require("./region"));
8
- exports.default = utils_1.model
9
- .define({ name: "Country", tableName: "region_country" }, {
10
- iso_2: utils_1.model.text().searchable().primaryKey(),
11
- iso_3: utils_1.model.text(),
12
- num_code: utils_1.model.text(),
13
- name: utils_1.model.text().searchable(),
14
- display_name: utils_1.model.text(),
15
- region: utils_1.model
16
- .belongsTo(() => region_1.default, { mappedBy: "countries" })
17
- .nullable(),
18
- metadata: utils_1.model.json().nullable(),
19
- })
20
- .indexes([
21
- {
22
- // TODO: Remove ts-ignore when field inference takes into account the nullable property
23
- // @ts-ignore
24
- on: ["region_id", "iso_2"],
25
- unique: true,
26
- },
27
- ]);
18
+ // We don't need a partial index on deleted_at here since we don't support soft deletes on countries
19
+ const regionIdIsoIndexName = "IDX_region_country_region_id_iso_2_unique";
20
+ const RegionIdIsoIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
21
+ name: regionIdIsoIndexName,
22
+ tableName: "region_country",
23
+ columns: ["region_id", "iso_2"],
24
+ unique: true,
25
+ });
26
+ RegionIdIsoIndexStatement.MikroORMIndex();
27
+ let Country = class Country {
28
+ constructor() {
29
+ this.region_id = null;
30
+ }
31
+ };
32
+ __decorate([
33
+ (0, core_1.PrimaryKey)({ columnType: "text" }),
34
+ (0, core_1.Property)({ columnType: "text" }),
35
+ __metadata("design:type", String)
36
+ ], Country.prototype, "iso_2", void 0);
37
+ __decorate([
38
+ (0, core_1.Property)({ columnType: "text" }),
39
+ __metadata("design:type", String)
40
+ ], Country.prototype, "iso_3", void 0);
41
+ __decorate([
42
+ (0, core_1.Property)({ columnType: "int" }),
43
+ __metadata("design:type", Number)
44
+ ], Country.prototype, "num_code", void 0);
45
+ __decorate([
46
+ (0, core_1.Property)({ columnType: "text" }),
47
+ __metadata("design:type", String)
48
+ ], Country.prototype, "name", void 0);
49
+ __decorate([
50
+ (0, core_1.Property)({ columnType: "text" }),
51
+ __metadata("design:type", String)
52
+ ], Country.prototype, "display_name", void 0);
53
+ __decorate([
54
+ (0, core_1.Property)({ columnType: "text", nullable: true }),
55
+ __metadata("design:type", Object)
56
+ ], Country.prototype, "region_id", void 0);
57
+ __decorate([
58
+ (0, core_1.ManyToOne)({
59
+ entity: () => region_1.default,
60
+ fieldName: "region_id",
61
+ nullable: true,
62
+ onDelete: "set null",
63
+ }),
64
+ __metadata("design:type", Object)
65
+ ], Country.prototype, "region", void 0);
66
+ Country = __decorate([
67
+ (0, core_1.Entity)({ tableName: "region_country" })
68
+ ], Country);
69
+ exports.default = Country;
@@ -1,3 +1,2 @@
1
1
  export { default as Country } from "./country";
2
2
  export { default as Region } from "./region";
3
- //# sourceMappingURL=index.d.ts.map