@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
@@ -1,111 +1,19 @@
1
- declare const _default: import("@medusajs/utils").DmlEntity<{
2
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
3
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
4
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
5
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
6
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<() => import("@medusajs/utils").DmlEntity<{
7
- iso_2: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/text").TextProperty>;
8
- iso_3: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
9
- num_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
10
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
11
- display_name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
12
- region: import("@medusajs/utils/dist/dml/relations/nullable").NullableModifier<() => import("@medusajs/utils").DmlEntity<any & {
13
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
14
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
15
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
16
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
17
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<any>;
18
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
19
- } & {} & 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<any & {
20
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
21
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
22
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
23
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
24
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<any>;
25
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
26
- } & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, "region">>>;
27
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
28
- } & {
29
- iso_2: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/text").TextProperty>;
30
- iso_3: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
31
- num_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
32
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
33
- display_name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
34
- region: import("@medusajs/utils/dist/dml/relations/nullable").NullableModifier<() => import("@medusajs/utils").DmlEntity<any & {
35
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
36
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
37
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
38
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
39
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<any>;
40
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
41
- } & {} & 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<any & {
42
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
43
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
44
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
45
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
46
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<any>;
47
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
48
- } & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, "region">>>;
49
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
50
- } & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, {
51
- readonly name: "Country";
52
- readonly tableName: "region_country";
53
- }>>;
54
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
55
- } & {
56
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
57
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
58
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
59
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
60
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<() => import("@medusajs/utils").DmlEntity<{
61
- iso_2: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/text").TextProperty>;
62
- iso_3: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
63
- num_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
64
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
65
- display_name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
66
- region: import("@medusajs/utils/dist/dml/relations/nullable").NullableModifier<() => import("@medusajs/utils").DmlEntity<{
67
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
68
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
69
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
70
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
71
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<any>;
72
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
73
- } & any & {} & 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<{
74
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
75
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
76
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
77
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
78
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<any>;
79
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
80
- } & any & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, "region">>>;
81
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
82
- } & {
83
- iso_2: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/text").TextProperty>;
84
- iso_3: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
85
- num_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
86
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
87
- display_name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
88
- region: import("@medusajs/utils/dist/dml/relations/nullable").NullableModifier<() => import("@medusajs/utils").DmlEntity<{
89
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
90
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
91
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
92
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
93
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<any>;
94
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
95
- } & any & {} & 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<{
96
- id: import("@medusajs/utils/dist/dml/properties/primary-key").PrimaryKeyModifier<string, import("@medusajs/utils/dist/dml/properties/id").IdProperty>;
97
- name: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
98
- currency_code: import("@medusajs/utils/dist/dml/properties/text").TextProperty;
99
- automatic_taxes: import("@medusajs/utils/dist/dml/properties/boolean").BooleanProperty;
100
- countries: import("@medusajs/utils/dist/dml/relations/has-many").HasMany<any>;
101
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
102
- } & any & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, "region">>>;
103
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
104
- } & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, {
105
- readonly name: "Country";
106
- readonly tableName: "region_country";
107
- }>>;
108
- metadata: import("@medusajs/utils/dist/dml/properties/nullable").NullableModifier<Record<string, unknown>, import("@medusajs/utils/dist/dml/properties/json").JSONProperty>;
109
- } & {} & import("@medusajs/utils/dist/dml/helpers/entity-builder/create-default-properties").DMLSchemaDefaults, "region">;
110
- export default _default;
111
- //# sourceMappingURL=region.d.ts.map
1
+ import { DAL } from "@medusajs/types";
2
+ import { Collection, OptionalProps } from "@mikro-orm/core";
3
+ import Country from "./country";
4
+ type RegionOptionalProps = "countries" | DAL.SoftDeletableEntityDateColumns;
5
+ export default class Region {
6
+ [OptionalProps]?: RegionOptionalProps;
7
+ id: string;
8
+ name: string;
9
+ currency_code: string;
10
+ automatic_taxes: boolean;
11
+ countries: Collection<Country, object>;
12
+ metadata: Record<string, unknown> | null;
13
+ created_at: Date;
14
+ updated_at: Date;
15
+ deleted_at: Date | null;
16
+ onCreate(): void;
17
+ onInit(): void;
18
+ }
19
+ export {};
@@ -1,15 +1,96 @@
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 });
6
15
  const utils_1 = require("@medusajs/utils");
16
+ const core_1 = require("@mikro-orm/core");
7
17
  const country_1 = __importDefault(require("./country"));
8
- exports.default = utils_1.model.define("region", {
9
- id: utils_1.model.id({ prefix: "reg" }).primaryKey(),
10
- name: utils_1.model.text().searchable(),
11
- currency_code: utils_1.model.text().searchable(),
12
- automatic_taxes: utils_1.model.boolean().default(true),
13
- countries: utils_1.model.hasMany(() => country_1.default),
14
- metadata: utils_1.model.json().nullable(),
15
- });
18
+ let Region = class Region {
19
+ constructor() {
20
+ this.automatic_taxes = true;
21
+ this.countries = new core_1.Collection(this);
22
+ this.metadata = null;
23
+ this.deleted_at = null;
24
+ }
25
+ onCreate() {
26
+ this.id = (0, utils_1.generateEntityId)(this.id, "reg");
27
+ }
28
+ onInit() {
29
+ this.id = (0, utils_1.generateEntityId)(this.id, "reg");
30
+ }
31
+ };
32
+ __decorate([
33
+ (0, core_1.PrimaryKey)({ columnType: "text" }),
34
+ __metadata("design:type", String)
35
+ ], Region.prototype, "id", void 0);
36
+ __decorate([
37
+ (0, utils_1.Searchable)(),
38
+ (0, core_1.Property)({ columnType: "text" }),
39
+ __metadata("design:type", String)
40
+ ], Region.prototype, "name", void 0);
41
+ __decorate([
42
+ (0, utils_1.Searchable)(),
43
+ (0, core_1.Property)({ columnType: "text" }),
44
+ __metadata("design:type", String)
45
+ ], Region.prototype, "currency_code", void 0);
46
+ __decorate([
47
+ (0, core_1.Property)({ columnType: "boolean" }),
48
+ __metadata("design:type", Object)
49
+ ], Region.prototype, "automatic_taxes", void 0);
50
+ __decorate([
51
+ (0, core_1.OneToMany)(() => country_1.default, (country) => country.region),
52
+ __metadata("design:type", Object)
53
+ ], Region.prototype, "countries", void 0);
54
+ __decorate([
55
+ (0, core_1.Property)({ columnType: "jsonb", nullable: true }),
56
+ __metadata("design:type", Object)
57
+ ], Region.prototype, "metadata", void 0);
58
+ __decorate([
59
+ (0, core_1.Property)({
60
+ onCreate: () => new Date(),
61
+ columnType: "timestamptz",
62
+ defaultRaw: "now()",
63
+ }),
64
+ __metadata("design:type", Date)
65
+ ], Region.prototype, "created_at", void 0);
66
+ __decorate([
67
+ (0, core_1.Property)({
68
+ onCreate: () => new Date(),
69
+ onUpdate: () => new Date(),
70
+ columnType: "timestamptz",
71
+ defaultRaw: "now()",
72
+ }),
73
+ __metadata("design:type", Date)
74
+ ], Region.prototype, "updated_at", void 0);
75
+ __decorate([
76
+ (0, core_1.Index)({ name: "IDX_region_deleted_at" }),
77
+ (0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
78
+ __metadata("design:type", Object)
79
+ ], Region.prototype, "deleted_at", void 0);
80
+ __decorate([
81
+ (0, core_1.BeforeCreate)(),
82
+ __metadata("design:type", Function),
83
+ __metadata("design:paramtypes", []),
84
+ __metadata("design:returntype", void 0)
85
+ ], Region.prototype, "onCreate", null);
86
+ __decorate([
87
+ (0, core_1.OnInit)(),
88
+ __metadata("design:type", Function),
89
+ __metadata("design:paramtypes", []),
90
+ __metadata("design:returntype", void 0)
91
+ ], Region.prototype, "onInit", null);
92
+ Region = __decorate([
93
+ (0, core_1.Entity)({ tableName: "region" }),
94
+ (0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
95
+ ], Region);
96
+ exports.default = Region;
@@ -0,0 +1,4 @@
1
+ import { ModuleExports } from "@medusajs/types";
2
+ export declare const runMigrations: ({ options, logger, }?: Pick<import("@medusajs/types").LoaderOptions<import("@medusajs/types").ModuleServiceInitializeOptions>, "options" | "logger"> | undefined) => Promise<void>;
3
+ export declare const revertMigration: ({ options, logger, }?: Pick<import("@medusajs/types").LoaderOptions<import("@medusajs/types").ModuleServiceInitializeOptions>, "options" | "logger"> | undefined) => Promise<void>;
4
+ export declare const moduleDefinition: ModuleExports;
@@ -0,0 +1,51 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.moduleDefinition = exports.revertMigration = exports.runMigrations = void 0;
30
+ const services_1 = require("./services");
31
+ const modules_sdk_1 = require("@medusajs/modules-sdk");
32
+ const utils_1 = require("@medusajs/utils");
33
+ const RegionModels = __importStar(require("./models"));
34
+ const connection_1 = __importDefault(require("./loaders/connection"));
35
+ const container_1 = __importDefault(require("./loaders/container"));
36
+ const defaults_1 = __importDefault(require("./loaders/defaults"));
37
+ const migrationScriptOptions = {
38
+ moduleName: modules_sdk_1.Modules.REGION,
39
+ models: RegionModels,
40
+ pathToMigrations: __dirname + "/migrations",
41
+ };
42
+ exports.runMigrations = utils_1.ModulesSdkUtils.buildMigrationScript(migrationScriptOptions);
43
+ exports.revertMigration = utils_1.ModulesSdkUtils.buildRevertMigrationScript(migrationScriptOptions);
44
+ const service = services_1.RegionModuleService;
45
+ const loaders = [container_1.default, connection_1.default, defaults_1.default];
46
+ exports.moduleDefinition = {
47
+ service,
48
+ loaders,
49
+ runMigrations: exports.runMigrations,
50
+ revertMigration: exports.revertMigration,
51
+ };
@@ -0,0 +1 @@
1
+ export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseRepository = void 0;
4
+ var utils_1 = require("@medusajs/utils");
5
+ Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return utils_1.MikroOrmBaseRepository; } });
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ declare const _default: Promise<void>;
3
+ export default _default;
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ const modules_sdk_1 = require("@medusajs/modules-sdk");
28
+ const utils_1 = require("@medusajs/utils");
29
+ const RegionModels = __importStar(require("../../models"));
30
+ const os_1 = require("os");
31
+ const seed_utils_1 = require("../seed-utils");
32
+ const args = process.argv;
33
+ const path = args.pop();
34
+ exports.default = (async () => {
35
+ const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
36
+ config();
37
+ if (!path) {
38
+ throw new Error(`filePath is required.${os_1.EOL}Example: medusa-region-seed <filePath>`);
39
+ }
40
+ const run = utils_1.ModulesSdkUtils.buildSeedScript({
41
+ moduleName: modules_sdk_1.Modules.REGION,
42
+ models: RegionModels,
43
+ pathToMigrations: __dirname + "/../../migrations",
44
+ seedHandler: async ({ manager, data }) => {
45
+ const { regionData } = data;
46
+ await (0, seed_utils_1.createRegions)(manager, regionData);
47
+ },
48
+ });
49
+ await run({ path });
50
+ })();
@@ -0,0 +1,4 @@
1
+ import { RequiredEntityData } from "@mikro-orm/core";
2
+ import { SqlEntityManager } from "@mikro-orm/postgresql";
3
+ import { Region } from "../models";
4
+ export declare function createRegions(manager: SqlEntityManager, data: RequiredEntityData<Region>[]): Promise<Region[]>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRegions = void 0;
4
+ const _models_1 = require("../models");
5
+ async function createRegions(manager, data) {
6
+ const regions = data.map((region) => {
7
+ return manager.create(_models_1.Region, region);
8
+ });
9
+ await manager.persistAndFlush(regions);
10
+ return regions;
11
+ }
12
+ exports.createRegions = createRegions;
@@ -1,2 +1 @@
1
1
  export { default as RegionModuleService } from "./region-module";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,36 +1,32 @@
1
- import { Context, CreateRegionDTO, DAL, FilterableRegionProps, InferEntityType, InternalModuleDeclaration, IRegionModuleService, ModulesSdkTypes, RegionCountryDTO, RegionDTO, SoftDeleteReturn, UpdateRegionDTO, UpsertRegionDTO } from "@medusajs/types";
1
+ import { Context, CreateRegionDTO, DAL, FilterableRegionProps, InternalModuleDeclaration, IRegionModuleService, ModuleJoinerConfig, ModulesSdkTypes, RegionCountryDTO, RegionDTO, UpdateRegionDTO, UpsertRegionDTO } from "@medusajs/types";
2
+ import { ModulesSdkUtils } from "@medusajs/utils";
2
3
  import { Country, Region } from "../models";
3
4
  import { UpdateRegionInput } from "../types";
4
5
  type InjectedDependencies = {
5
6
  baseRepository: DAL.RepositoryService;
6
- regionService: ModulesSdkTypes.IMedusaInternalService<any>;
7
- countryService: ModulesSdkTypes.IMedusaInternalService<any>;
7
+ regionService: ModulesSdkTypes.InternalModuleService<any>;
8
+ countryService: ModulesSdkTypes.InternalModuleService<any>;
8
9
  };
9
- declare const RegionModuleService_base: import("@medusajs/utils/dist/modules-sdk/types/medusa-service").MedusaServiceReturnType<{
10
- Region: {
11
- dto: RegionDTO;
12
- model: typeof Region;
13
- };
10
+ declare const RegionModuleService_base: new (container: InjectedDependencies) => ModulesSdkUtils.AbstractModuleService<InjectedDependencies, RegionDTO, {
14
11
  Country: {
15
12
  dto: RegionCountryDTO;
16
- model: typeof Country;
17
13
  };
18
14
  }>;
19
- export default class RegionModuleService extends RegionModuleService_base implements IRegionModuleService {
15
+ export default class RegionModuleService<TRegion extends Region = Region, TCountry extends Country = Country> extends RegionModuleService_base implements IRegionModuleService {
20
16
  protected readonly moduleDeclaration: InternalModuleDeclaration;
21
17
  protected baseRepository_: DAL.RepositoryService;
22
- protected readonly regionService_: ModulesSdkTypes.IMedusaInternalService<typeof Region>;
23
- protected readonly countryService_: ModulesSdkTypes.IMedusaInternalService<typeof Country>;
18
+ protected readonly regionService_: ModulesSdkTypes.InternalModuleService<TRegion>;
19
+ protected readonly countryService_: ModulesSdkTypes.InternalModuleService<TCountry>;
24
20
  constructor({ baseRepository, regionService, countryService }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
25
- createRegions(data: CreateRegionDTO[], sharedContext?: Context): Promise<RegionDTO[]>;
26
- createRegions(data: CreateRegionDTO, sharedContext?: Context): Promise<RegionDTO>;
27
- createRegions_(data: CreateRegionDTO[], sharedContext?: Context): Promise<InferEntityType<typeof Region>[]>;
28
- softDeleteRegions(ids: string | object | string[] | object[], config?: SoftDeleteReturn<string>, sharedContext?: Context): Promise<Record<string, string[]> | void>;
29
- upsertRegions(data: UpsertRegionDTO[], sharedContext?: Context): Promise<RegionDTO[]>;
30
- upsertRegions(data: UpsertRegionDTO, sharedContext?: Context): Promise<RegionDTO>;
31
- updateRegions(id: string, data: UpdateRegionDTO, sharedContext?: Context): Promise<RegionDTO>;
32
- updateRegions(selector: FilterableRegionProps, data: UpdateRegionDTO, sharedContext?: Context): Promise<RegionDTO[]>;
33
- protected updateRegions_(data: UpdateRegionInput[], sharedContext?: Context): Promise<InferEntityType<typeof Region>[]>;
21
+ __joinerConfig(): ModuleJoinerConfig;
22
+ create(data: CreateRegionDTO[], sharedContext?: Context): Promise<RegionDTO[]>;
23
+ create(data: CreateRegionDTO, sharedContext?: Context): Promise<RegionDTO>;
24
+ create_(data: CreateRegionDTO[], sharedContext?: Context): Promise<Region[]>;
25
+ upsert(data: UpsertRegionDTO[], sharedContext?: Context): Promise<RegionDTO[]>;
26
+ upsert(data: UpsertRegionDTO, sharedContext?: Context): Promise<RegionDTO>;
27
+ update(id: string, data: UpdateRegionDTO, sharedContext?: Context): Promise<RegionDTO>;
28
+ update(selector: FilterableRegionProps, data: UpdateRegionDTO, sharedContext?: Context): Promise<RegionDTO[]>;
29
+ protected update_(data: UpdateRegionInput[], sharedContext?: Context): Promise<Region[]>;
34
30
  private static normalizeInput;
35
31
  /**
36
32
  * Validate that countries can be assigned to a region.
@@ -43,4 +39,3 @@ export default class RegionModuleService extends RegionModuleService_base implem
43
39
  private validateCountries;
44
40
  }
45
41
  export {};
46
- //# sourceMappingURL=region-module.d.ts.map
@@ -14,7 +14,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const utils_1 = require("@medusajs/utils");
16
16
  const _models_1 = require("../models");
17
- class RegionModuleService extends (0, utils_1.MedusaService)({ Region: _models_1.Region, Country: _models_1.Country }) {
17
+ const joiner_config_1 = require("../joiner-config");
18
+ const generateMethodForModels = [_models_1.Country];
19
+ class RegionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFactory(_models_1.Region, generateMethodForModels, joiner_config_1.entityNameToLinkableKeysMap) {
18
20
  constructor({ baseRepository, regionService, countryService }, moduleDeclaration) {
19
21
  // @ts-ignore
20
22
  super(...arguments);
@@ -23,12 +25,15 @@ class RegionModuleService extends (0, utils_1.MedusaService)({ Region: _models_1
23
25
  this.regionService_ = regionService;
24
26
  this.countryService_ = countryService;
25
27
  }
26
- async createRegions(data, sharedContext = {}) {
28
+ __joinerConfig() {
29
+ return joiner_config_1.joinerConfig;
30
+ }
31
+ async create(data, sharedContext = {}) {
27
32
  const input = Array.isArray(data) ? data : [data];
28
- const result = await this.createRegions_(input, sharedContext);
33
+ const result = await this.create_(input, sharedContext);
29
34
  return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0]);
30
35
  }
31
- async createRegions_(data, sharedContext = {}) {
36
+ async create_(data, sharedContext = {}) {
32
37
  let normalizedInput = RegionModuleService.normalizeInput(data);
33
38
  let normalizedDbRegions = normalizedInput.map((region) => (0, utils_1.removeUndefined)({
34
39
  ...region,
@@ -46,31 +51,21 @@ class RegionModuleService extends (0, utils_1.MedusaService)({ Region: _models_1
46
51
  }
47
52
  return result;
48
53
  }
49
- // @ts-ignore
50
- async softDeleteRegions(ids, config, sharedContext = {}) {
51
- const result = await super.softDeleteRegions(ids, config, sharedContext);
52
- // Note: You cannot revert the state of a region by simply restoring it. The association with countries is lost.
53
- await super.updateCountries({
54
- selector: { region_id: ids },
55
- data: { region_id: null },
56
- }, sharedContext);
57
- return result;
58
- }
59
- async upsertRegions(data, sharedContext = {}) {
54
+ async upsert(data, sharedContext = {}) {
60
55
  const input = Array.isArray(data) ? data : [data];
61
56
  const forUpdate = input.filter((region) => !!region.id);
62
57
  const forCreate = input.filter((region) => !region.id);
63
58
  const operations = [];
64
59
  if (forCreate.length) {
65
- operations.push(this.createRegions_(forCreate, sharedContext));
60
+ operations.push(this.create_(forCreate, sharedContext));
66
61
  }
67
62
  if (forUpdate.length) {
68
- operations.push(this.updateRegions_(forUpdate, sharedContext));
63
+ operations.push(this.update_(forUpdate, sharedContext));
69
64
  }
70
65
  const result = (await (0, utils_1.promiseAll)(operations)).flat();
71
66
  return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0]);
72
67
  }
73
- async updateRegions(idOrSelector, data, sharedContext = {}) {
68
+ async update(idOrSelector, data, sharedContext = {}) {
74
69
  let normalizedInput = [];
75
70
  if ((0, utils_1.isString)(idOrSelector)) {
76
71
  normalizedInput = [{ id: idOrSelector, ...data }];
@@ -82,11 +77,11 @@ class RegionModuleService extends (0, utils_1.MedusaService)({ Region: _models_1
82
77
  ...data,
83
78
  }));
84
79
  }
85
- const updateResult = await this.updateRegions_(normalizedInput, sharedContext);
80
+ const updateResult = await this.update_(normalizedInput, sharedContext);
86
81
  const regions = await this.baseRepository_.serialize(updateResult);
87
82
  return (0, utils_1.isString)(idOrSelector) ? regions[0] : regions;
88
83
  }
89
- async updateRegions_(data, sharedContext = {}) {
84
+ async update_(data, sharedContext = {}) {
90
85
  const normalizedInput = RegionModuleService.normalizeInput(data);
91
86
  // If countries are being updated for a region, first make previously set countries' region to null to get to a clean slate.
92
87
  // Somewhat less efficient, but region operations will be very rare, so it is better to go with a simple solution
@@ -148,7 +143,6 @@ class RegionModuleService extends (0, utils_1.MedusaService)({ Region: _models_1
148
143
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Countries with codes: "${missingCountries.join(", ")}" do not exist`);
149
144
  }
150
145
  // Countries that already have a region already assigned to them
151
- // @ts-ignore
152
146
  const countriesWithRegion = countriesInDb.filter((c) => !!c.region_id);
153
147
  if (countriesWithRegion.length) {
154
148
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Countries with codes: "${countriesWithRegion
@@ -165,41 +159,32 @@ __decorate([
165
159
  __metadata("design:type", Function),
166
160
  __metadata("design:paramtypes", [Object, Object]),
167
161
  __metadata("design:returntype", Promise)
168
- ], RegionModuleService.prototype, "createRegions", null);
162
+ ], RegionModuleService.prototype, "create", null);
169
163
  __decorate([
170
164
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
171
165
  __param(1, (0, utils_1.MedusaContext)()),
172
166
  __metadata("design:type", Function),
173
167
  __metadata("design:paramtypes", [Array, Object]),
174
168
  __metadata("design:returntype", Promise)
175
- ], RegionModuleService.prototype, "createRegions_", null);
176
- __decorate([
177
- (0, utils_1.InjectManager)("baseRepository_")
178
- // @ts-ignore
179
- ,
180
- __param(2, (0, utils_1.MedusaContext)()),
181
- __metadata("design:type", Function),
182
- __metadata("design:paramtypes", [Object, Object, Object]),
183
- __metadata("design:returntype", Promise)
184
- ], RegionModuleService.prototype, "softDeleteRegions", null);
169
+ ], RegionModuleService.prototype, "create_", null);
185
170
  __decorate([
186
171
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
187
172
  __param(1, (0, utils_1.MedusaContext)()),
188
173
  __metadata("design:type", Function),
189
174
  __metadata("design:paramtypes", [Object, Object]),
190
175
  __metadata("design:returntype", Promise)
191
- ], RegionModuleService.prototype, "upsertRegions", null);
176
+ ], RegionModuleService.prototype, "upsert", null);
192
177
  __decorate([
193
178
  (0, utils_1.InjectManager)("baseRepository_"),
194
179
  __param(2, (0, utils_1.MedusaContext)()),
195
180
  __metadata("design:type", Function),
196
181
  __metadata("design:paramtypes", [Object, Object, Object]),
197
182
  __metadata("design:returntype", Promise)
198
- ], RegionModuleService.prototype, "updateRegions", null);
183
+ ], RegionModuleService.prototype, "update", null);
199
184
  __decorate([
200
185
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
201
186
  __param(1, (0, utils_1.MedusaContext)()),
202
187
  __metadata("design:type", Function),
203
188
  __metadata("design:paramtypes", [Array, Object]),
204
189
  __metadata("design:returntype", Promise)
205
- ], RegionModuleService.prototype, "updateRegions_", null);
190
+ ], RegionModuleService.prototype, "update_", null);
@@ -16,4 +16,3 @@ export type CreateCountryDTO = {
16
16
  export type UpdateRegionInput = UpdateRegionDTO & {
17
17
  id: string;
18
18
  };
19
- //# sourceMappingURL=index.d.ts.map