@medusajs/region 0.1.2-snapshot-20240718083016 → 0.1.2-snapshot-20240719080828

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 +36 -4
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +9 -19
  4. package/dist/loaders/defaults.d.ts +1 -0
  5. package/dist/loaders/defaults.d.ts.map +1 -0
  6. package/dist/loaders/defaults.js +2 -3
  7. package/dist/loaders/index.d.ts +1 -2
  8. package/dist/loaders/index.d.ts.map +1 -0
  9. package/dist/loaders/index.js +0 -2
  10. package/dist/migrations/{RegionModuleSetup20240205173216.d.ts → Migration20240205173216.d.ts} +1 -0
  11. package/dist/migrations/Migration20240205173216.d.ts.map +1 -0
  12. package/dist/migrations/{RegionModuleSetup20240205173216.js → Migration20240205173216.js} +1 -1
  13. package/dist/migrations/Migration20240624200006.d.ts +6 -0
  14. package/dist/migrations/Migration20240624200006.d.ts.map +1 -0
  15. package/dist/migrations/Migration20240624200006.js +19 -0
  16. package/dist/models/country.d.ts +166 -10
  17. package/dist/models/country.d.ts.map +1 -0
  18. package/dist/models/country.js +20 -62
  19. package/dist/models/index.d.ts +1 -0
  20. package/dist/models/index.d.ts.map +1 -0
  21. package/dist/models/region.d.ts +111 -19
  22. package/dist/models/region.d.ts.map +1 -0
  23. package/dist/models/region.js +8 -89
  24. package/dist/services/index.d.ts +1 -0
  25. package/dist/services/index.d.ts.map +1 -0
  26. package/dist/services/region-module.d.ts +22 -17
  27. package/dist/services/region-module.d.ts.map +1 -0
  28. package/dist/services/region-module.js +35 -20
  29. package/dist/types/index.d.ts +1 -0
  30. package/dist/types/index.d.ts.map +1 -0
  31. package/package.json +8 -14
  32. package/dist/initialize/index.d.ts +0 -4
  33. package/dist/initialize/index.js +0 -17
  34. package/dist/joiner-config.d.ts +0 -8
  35. package/dist/joiner-config.js +0 -33
  36. package/dist/loaders/connection.d.ts +0 -4
  37. package/dist/loaders/connection.js +0 -41
  38. package/dist/loaders/container.d.ts +0 -2
  39. package/dist/loaders/container.js +0 -34
  40. package/dist/module-definition.d.ts +0 -4
  41. package/dist/module-definition.js +0 -51
  42. package/dist/repositories/index.d.ts +0 -1
  43. package/dist/repositories/index.js +0 -5
  44. package/dist/scripts/bin/run-seed.d.ts +0 -3
  45. package/dist/scripts/bin/run-seed.js +0 -50
  46. package/dist/scripts/seed-utils.d.ts +0 -4
  47. package/dist/scripts/seed-utils.js +0 -12
@@ -1,19 +1,111 @@
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
+ 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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"region.d.ts","sourceRoot":"","sources":["../../src/models/region.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,wBAOE"}
@@ -1,96 +1,15 @@
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
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  const utils_1 = require("@medusajs/utils");
16
- const core_1 = require("@mikro-orm/core");
17
7
  const country_1 = __importDefault(require("./country"));
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;
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
+ });
@@ -1 +1,2 @@
1
1
  export { default as RegionModuleService } from "./region-module";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,32 +1,36 @@
1
- import { Context, CreateRegionDTO, DAL, FilterableRegionProps, InternalModuleDeclaration, IRegionModuleService, ModuleJoinerConfig, ModulesSdkTypes, RegionCountryDTO, RegionDTO, UpdateRegionDTO, UpsertRegionDTO } from "@medusajs/types";
2
- import { ModulesSdkUtils } from "@medusajs/utils";
1
+ import { Context, CreateRegionDTO, DAL, FilterableRegionProps, InferEntityType, InternalModuleDeclaration, IRegionModuleService, ModulesSdkTypes, RegionCountryDTO, RegionDTO, SoftDeleteReturn, UpdateRegionDTO, UpsertRegionDTO } from "@medusajs/types";
3
2
  import { Country, Region } from "../models";
4
3
  import { UpdateRegionInput } from "../types";
5
4
  type InjectedDependencies = {
6
5
  baseRepository: DAL.RepositoryService;
7
- regionService: ModulesSdkTypes.InternalModuleService<any>;
8
- countryService: ModulesSdkTypes.InternalModuleService<any>;
6
+ regionService: ModulesSdkTypes.IMedusaInternalService<any>;
7
+ countryService: ModulesSdkTypes.IMedusaInternalService<any>;
9
8
  };
10
- declare const RegionModuleService_base: new (container: InjectedDependencies) => ModulesSdkUtils.AbstractModuleService<InjectedDependencies, RegionDTO, {
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
+ };
11
14
  Country: {
12
15
  dto: RegionCountryDTO;
16
+ model: typeof Country;
13
17
  };
14
18
  }>;
15
- export default class RegionModuleService<TRegion extends Region = Region, TCountry extends Country = Country> extends RegionModuleService_base implements IRegionModuleService {
19
+ export default class RegionModuleService extends RegionModuleService_base implements IRegionModuleService {
16
20
  protected readonly moduleDeclaration: InternalModuleDeclaration;
17
21
  protected baseRepository_: DAL.RepositoryService;
18
- protected readonly regionService_: ModulesSdkTypes.InternalModuleService<TRegion>;
19
- protected readonly countryService_: ModulesSdkTypes.InternalModuleService<TCountry>;
22
+ protected readonly regionService_: ModulesSdkTypes.IMedusaInternalService<typeof Region>;
23
+ protected readonly countryService_: ModulesSdkTypes.IMedusaInternalService<typeof Country>;
20
24
  constructor({ baseRepository, regionService, countryService }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
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[]>;
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>[]>;
30
34
  private static normalizeInput;
31
35
  /**
32
36
  * Validate that countries can be assigned to a region.
@@ -39,3 +43,4 @@ export default class RegionModuleService<TRegion extends Region = Region, TCount
39
43
  private validateCountries;
40
44
  }
41
45
  export {};
46
+ //# sourceMappingURL=region-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"region-module.d.ts","sourceRoot":"","sources":["../../src/services/region-module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,eAAe,EACf,GAAG,EACH,qBAAqB,EACrB,eAAe,EACf,yBAAyB,EACzB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,eAAe,EAChB,MAAM,iBAAiB,CAAA;AAaxB,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAE1C,KAAK,oBAAoB,GAAG;IAC1B,cAAc,EAAE,GAAG,CAAC,iBAAiB,CAAA;IACrC,aAAa,EAAE,eAAe,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAA;IAC1D,cAAc,EAAE,eAAe,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAA;CAC5D,CAAA;;YAIW;QACN,GAAG,EAAE,SAAS,CAAA;QACd,KAAK,EAAE,aAAa,CAAA;KACrB;aACQ;QACP,GAAG,EAAE,gBAAgB,CAAA;QACrB,KAAK,EAAE,cAAc,CAAA;KACtB;;AATL,MAAM,CAAC,OAAO,OAAO,mBACnB,SAAQ,wBAUR,YAAW,oBAAoB;IAY7B,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,yBAAyB;IAVjE,SAAS,CAAC,eAAe,EAAE,GAAG,CAAC,iBAAiB,CAAA;IAChD,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,eAAe,CAAC,sBAAsB,CACvE,OAAO,MAAM,CACd,CAAA;IACD,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC,sBAAsB,CACxE,OAAO,OAAO,CACf,CAAA;gBAGC,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,EAAE,oBAAoB,EACpD,iBAAiB,EAAE,yBAAyB;IAU3D,aAAa,CACjB,IAAI,EAAE,eAAe,EAAE,EACvB,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,SAAS,EAAE,CAAC;IACjB,aAAa,CACjB,IAAI,EAAE,eAAe,EACrB,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,SAAS,CAAC;IAiBf,cAAc,CAClB,IAAI,EAAE,eAAe,EAAE,EACN,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,eAAe,CAAC,OAAO,MAAM,CAAC,EAAE,CAAC;IAqCtC,iBAAiB,CACrB,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,EAC1C,MAAM,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAChB,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IAcrC,aAAa,CACjB,IAAI,EAAE,eAAe,EAAE,EACvB,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,SAAS,EAAE,CAAC;IACjB,aAAa,CACjB,IAAI,EAAE,eAAe,EACrB,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,SAAS,CAAC;IA+Bf,aAAa,CACjB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,eAAe,EACrB,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,SAAS,CAAC;IACf,aAAa,CACjB,QAAQ,EAAE,qBAAqB,EAC/B,IAAI,EAAE,eAAe,EACrB,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,SAAS,EAAE,CAAC;cAqCP,cAAc,CAC5B,IAAI,EAAE,iBAAiB,EAAE,EACR,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,eAAe,CAAC,OAAO,MAAM,CAAC,EAAE,CAAC;IA+C5C,OAAO,CAAC,MAAM,CAAC,cAAc;IAW7B;;;;;;;OAOG;YACW,iBAAiB;CAqDhC"}
@@ -14,9 +14,7 @@ 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
- 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) {
17
+ class RegionModuleService extends (0, utils_1.MedusaService)({ Region: _models_1.Region, Country: _models_1.Country }) {
20
18
  constructor({ baseRepository, regionService, countryService }, moduleDeclaration) {
21
19
  // @ts-ignore
22
20
  super(...arguments);
@@ -25,15 +23,12 @@ class RegionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceF
25
23
  this.regionService_ = regionService;
26
24
  this.countryService_ = countryService;
27
25
  }
28
- __joinerConfig() {
29
- return joiner_config_1.joinerConfig;
30
- }
31
- async create(data, sharedContext = {}) {
26
+ async createRegions(data, sharedContext = {}) {
32
27
  const input = Array.isArray(data) ? data : [data];
33
- const result = await this.create_(input, sharedContext);
28
+ const result = await this.createRegions_(input, sharedContext);
34
29
  return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0]);
35
30
  }
36
- async create_(data, sharedContext = {}) {
31
+ async createRegions_(data, sharedContext = {}) {
37
32
  let normalizedInput = RegionModuleService.normalizeInput(data);
38
33
  let normalizedDbRegions = normalizedInput.map((region) => (0, utils_1.removeUndefined)({
39
34
  ...region,
@@ -51,21 +46,31 @@ class RegionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceF
51
46
  }
52
47
  return result;
53
48
  }
54
- async upsert(data, sharedContext = {}) {
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 = {}) {
55
60
  const input = Array.isArray(data) ? data : [data];
56
61
  const forUpdate = input.filter((region) => !!region.id);
57
62
  const forCreate = input.filter((region) => !region.id);
58
63
  const operations = [];
59
64
  if (forCreate.length) {
60
- operations.push(this.create_(forCreate, sharedContext));
65
+ operations.push(this.createRegions_(forCreate, sharedContext));
61
66
  }
62
67
  if (forUpdate.length) {
63
- operations.push(this.update_(forUpdate, sharedContext));
68
+ operations.push(this.updateRegions_(forUpdate, sharedContext));
64
69
  }
65
70
  const result = (await (0, utils_1.promiseAll)(operations)).flat();
66
71
  return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0]);
67
72
  }
68
- async update(idOrSelector, data, sharedContext = {}) {
73
+ async updateRegions(idOrSelector, data, sharedContext = {}) {
69
74
  let normalizedInput = [];
70
75
  if ((0, utils_1.isString)(idOrSelector)) {
71
76
  normalizedInput = [{ id: idOrSelector, ...data }];
@@ -77,11 +82,11 @@ class RegionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceF
77
82
  ...data,
78
83
  }));
79
84
  }
80
- const updateResult = await this.update_(normalizedInput, sharedContext);
85
+ const updateResult = await this.updateRegions_(normalizedInput, sharedContext);
81
86
  const regions = await this.baseRepository_.serialize(updateResult);
82
87
  return (0, utils_1.isString)(idOrSelector) ? regions[0] : regions;
83
88
  }
84
- async update_(data, sharedContext = {}) {
89
+ async updateRegions_(data, sharedContext = {}) {
85
90
  const normalizedInput = RegionModuleService.normalizeInput(data);
86
91
  // If countries are being updated for a region, first make previously set countries' region to null to get to a clean slate.
87
92
  // Somewhat less efficient, but region operations will be very rare, so it is better to go with a simple solution
@@ -143,6 +148,7 @@ class RegionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceF
143
148
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Countries with codes: "${missingCountries.join(", ")}" do not exist`);
144
149
  }
145
150
  // Countries that already have a region already assigned to them
151
+ // @ts-ignore
146
152
  const countriesWithRegion = countriesInDb.filter((c) => !!c.region_id);
147
153
  if (countriesWithRegion.length) {
148
154
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Countries with codes: "${countriesWithRegion
@@ -159,32 +165,41 @@ __decorate([
159
165
  __metadata("design:type", Function),
160
166
  __metadata("design:paramtypes", [Object, Object]),
161
167
  __metadata("design:returntype", Promise)
162
- ], RegionModuleService.prototype, "create", null);
168
+ ], RegionModuleService.prototype, "createRegions", null);
163
169
  __decorate([
164
170
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
165
171
  __param(1, (0, utils_1.MedusaContext)()),
166
172
  __metadata("design:type", Function),
167
173
  __metadata("design:paramtypes", [Array, Object]),
168
174
  __metadata("design:returntype", Promise)
169
- ], RegionModuleService.prototype, "create_", null);
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);
170
185
  __decorate([
171
186
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
172
187
  __param(1, (0, utils_1.MedusaContext)()),
173
188
  __metadata("design:type", Function),
174
189
  __metadata("design:paramtypes", [Object, Object]),
175
190
  __metadata("design:returntype", Promise)
176
- ], RegionModuleService.prototype, "upsert", null);
191
+ ], RegionModuleService.prototype, "upsertRegions", null);
177
192
  __decorate([
178
193
  (0, utils_1.InjectManager)("baseRepository_"),
179
194
  __param(2, (0, utils_1.MedusaContext)()),
180
195
  __metadata("design:type", Function),
181
196
  __metadata("design:paramtypes", [Object, Object, Object]),
182
197
  __metadata("design:returntype", Promise)
183
- ], RegionModuleService.prototype, "update", null);
198
+ ], RegionModuleService.prototype, "updateRegions", null);
184
199
  __decorate([
185
200
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
186
201
  __param(1, (0, utils_1.MedusaContext)()),
187
202
  __metadata("design:type", Function),
188
203
  __metadata("design:paramtypes", [Array, Object]),
189
204
  __metadata("design:returntype", Promise)
190
- ], RegionModuleService.prototype, "update_", null);
205
+ ], RegionModuleService.prototype, "updateRegions_", null);
@@ -16,3 +16,4 @@ export type CreateCountryDTO = {
16
16
  export type UpdateRegionInput = UpdateRegionDTO & {
17
17
  id: string;
18
18
  };
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEzD,MAAM,MAAM,sCAAsC,GAAG;IACnD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,eAAe,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/region",
3
- "version": "0.1.2-snapshot-20240718083016",
3
+ "version": "0.1.2-snapshot-20240719080828",
4
4
  "description": "Medusa Region module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,10 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "engines": {
11
- "node": ">=16"
12
- },
13
- "bin": {
14
- "medusa-region-seed": "dist/scripts/bin/run-seed.js"
11
+ "node": ">=20"
15
12
  },
16
13
  "repository": {
17
14
  "type": "git",
@@ -37,25 +34,22 @@
37
34
  "orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
38
35
  },
39
36
  "devDependencies": {
37
+ "@medusajs/modules-sdk": "1.13.0-snapshot-20240719080828",
38
+ "@medusajs/types": "1.12.0-snapshot-20240719080828",
40
39
  "@mikro-orm/cli": "5.9.7",
41
40
  "cross-env": "^5.2.1",
42
- "jest": "^29.6.3",
43
- "medusa-test-utils": "workspace:^",
41
+ "jest": "^29.7.0",
42
+ "medusa-test-utils": "1.1.45-snapshot-20240719080828",
44
43
  "rimraf": "^3.0.2",
45
- "ts-jest": "^29.1.1",
46
44
  "ts-node": "^10.9.1",
47
45
  "tsc-alias": "^1.8.6",
48
46
  "typescript": "^5.1.6"
49
47
  },
50
48
  "dependencies": {
51
- "@medusajs/modules-sdk": "1.12.12-snapshot-20240718083016",
52
- "@medusajs/types": "1.11.17-snapshot-20240718083016",
53
- "@medusajs/utils": "1.11.10-snapshot-20240718083016",
49
+ "@medusajs/utils": "1.12.0-snapshot-20240719080828",
54
50
  "@mikro-orm/core": "5.9.7",
55
51
  "@mikro-orm/migrations": "5.9.7",
56
52
  "@mikro-orm/postgresql": "5.9.7",
57
- "awilix": "^8.0.0",
58
- "dotenv": "^16.4.5",
59
- "knex": "2.4.2"
53
+ "awilix": "^8.0.0"
60
54
  }
61
55
  }
@@ -1,4 +0,0 @@
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>;
@@ -1,17 +0,0 @@
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;
@@ -1,8 +0,0 @@
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;
@@ -1,33 +0,0 @@
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
- };
@@ -1,4 +0,0 @@
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;