@medusajs/inventory 1.0.11 → 1.1.0-20230320210331
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -1
- package/dist/index.js +21 -13
- package/dist/index.js.map +1 -1
- package/dist/initialize/index.d.ts +7 -0
- package/dist/initialize/index.js +11 -0
- package/dist/initialize/index.js.map +1 -0
- package/dist/loaders/connection.d.ts +2 -2
- package/dist/loaders/connection.js +50 -40
- package/dist/loaders/connection.js.map +1 -1
- package/dist/migrations/run-migration.d.ts +3 -0
- package/dist/migrations/run-migration.js +50 -0
- package/dist/migrations/run-migration.js.map +1 -0
- package/dist/migrations/schema-migrations/1665748086258-inventory_setup.d.ts +0 -7
- package/dist/migrations/schema-migrations/1665748086258-inventory_setup.js +81 -125
- package/dist/migrations/schema-migrations/1665748086258-inventory_setup.js.map +1 -1
- package/dist/models/inventory-item.js +60 -80
- package/dist/models/inventory-item.js.map +1 -1
- package/dist/models/inventory-level.js +42 -62
- package/dist/models/inventory-level.js.map +1 -1
- package/dist/models/reservation-item.js +38 -58
- package/dist/models/reservation-item.js.map +1 -1
- package/dist/services/inventory-item.d.ts +12 -13
- package/dist/services/inventory-item.js +130 -252
- package/dist/services/inventory-item.js.map +1 -1
- package/dist/services/inventory-level.d.ts +27 -18
- package/dist/services/inventory-level.js +251 -348
- package/dist/services/inventory-level.js.map +1 -1
- package/dist/services/inventory.d.ts +39 -28
- package/dist/services/inventory.js +319 -464
- package/dist/services/inventory.js.map +1 -1
- package/dist/services/reservation-item.d.ts +20 -17
- package/dist/services/reservation-item.js +188 -341
- package/dist/services/reservation-item.js.map +1 -1
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/query.js +21 -37
- package/dist/utils/query.js.map +1 -1
- package/package.json +10 -7
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -22,23 +22,31 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
25
28
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
30
|
};
|
|
28
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
const connection_1 = __importDefault(require("./loaders/connection"));
|
|
33
|
+
const container_1 = __importDefault(require("./loaders/container"));
|
|
34
|
+
const migrations_1 = __importDefault(require("./migrations"));
|
|
35
|
+
const run_migration_1 = require("./migrations/run-migration");
|
|
36
|
+
const InventoryModels = __importStar(require("./models"));
|
|
37
|
+
const inventory_1 = __importDefault(require("./services/inventory"));
|
|
38
|
+
const service = inventory_1.default;
|
|
39
|
+
const loaders = [container_1.default, connection_1.default];
|
|
40
|
+
const models = Object.values(InventoryModels);
|
|
41
|
+
const moduleDefinition = {
|
|
42
|
+
service,
|
|
43
|
+
migrations: migrations_1.default,
|
|
44
|
+
loaders,
|
|
45
|
+
models,
|
|
46
|
+
runMigrations: run_migration_1.runMigrations,
|
|
47
|
+
revertMigration: run_migration_1.revertMigration,
|
|
42
48
|
};
|
|
43
49
|
exports.default = moduleDefinition;
|
|
50
|
+
__exportStar(require("./initialize"), exports);
|
|
51
|
+
__exportStar(require("./types"), exports);
|
|
44
52
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sEAAiD;AACjD,oEAA+C;AAE/C,8DAAqC;AACrC,8DAA2E;AAC3E,0DAA2C;AAC3C,qEAAmD;AAInD,MAAM,OAAO,GAAG,mBAAgB,CAAA;AAChC,MAAM,OAAO,GAAG,CAAC,mBAAa,EAAE,oBAAc,CAAC,CAAA;AAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAA;AAE7C,MAAM,gBAAgB,GAAkB;IACtC,OAAO;IACP,UAAU,EAAV,oBAAU;IACV,OAAO;IACP,MAAM;IACN,aAAa,EAAb,6BAAa;IACb,eAAe,EAAf,+BAAe;CAChB,CAAA;AAED,kBAAe,gBAAgB,CAAA;AAE/B,+CAA4B;AAC5B,0CAAuB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IInventoryService } from "@medusajs/medusa";
|
|
2
|
+
import { ExternalModuleDeclaration } from "@medusajs/modules-sdk";
|
|
3
|
+
import { EventBusTypes } from "@medusajs/types";
|
|
4
|
+
import { InventoryServiceInitializeOptions } from "../types";
|
|
5
|
+
export declare const initialize: (options?: InventoryServiceInitializeOptions | ExternalModuleDeclaration, injectedDependencies?: {
|
|
6
|
+
eventBusService: EventBusTypes.IEventBusService;
|
|
7
|
+
}) => Promise<IInventoryService>;
|
|
@@ -0,0 +1,11 @@
|
|
|
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 initialize = async (options, injectedDependencies) => {
|
|
6
|
+
const serviceKey = "inventoryService";
|
|
7
|
+
const loaded = await modules_sdk_1.MedusaModule.bootstrap(serviceKey, "@medusajs/inventory", options, injectedDependencies);
|
|
8
|
+
return loaded[serviceKey];
|
|
9
|
+
};
|
|
10
|
+
exports.initialize = initialize;
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/initialize/index.ts"],"names":[],"mappings":";;;AACA,uDAI8B;AAIvB,MAAM,UAAU,GAAG,KAAK,EAC7B,OAAuE,EACvE,oBAEC,EAC2B,EAAE;IAC9B,MAAM,UAAU,GAAG,kBAAkB,CAAA;IACrC,MAAM,MAAM,GAAG,MAAM,0BAAY,CAAC,SAAS,CACzC,UAAU,EACV,qBAAqB,EACrB,OAAgE,EAChE,oBAAoB,CACrB,CAAA;IAED,OAAO,MAAM,CAAC,UAAU,CAAsB,CAAA;AAChD,CAAC,CAAA;AAfY,QAAA,UAAU,cAetB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const _default: ({
|
|
1
|
+
import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/modules-sdk";
|
|
2
|
+
declare const _default: ({ options, container }: LoaderOptions, moduleDeclaration?: InternalModuleDeclaration) => Promise<void>;
|
|
3
3
|
export default _default;
|
|
@@ -1,45 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
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]; } };
|
|
36
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;
|
|
37
24
|
};
|
|
38
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
})
|
|
26
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
27
|
+
const typeorm_1 = require("typeorm");
|
|
28
|
+
const awilix_1 = require("awilix");
|
|
29
|
+
const medusa_core_utils_1 = require("medusa-core-utils");
|
|
30
|
+
const InventoryModels = __importStar(require("../models"));
|
|
31
|
+
exports.default = async ({ options, container }, moduleDeclaration) => {
|
|
32
|
+
if (moduleDeclaration?.scope === modules_sdk_1.MODULE_SCOPE.INTERNAL &&
|
|
33
|
+
moduleDeclaration.resources === modules_sdk_1.MODULE_RESOURCE_TYPE.SHARED) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const dbData = options?.database;
|
|
37
|
+
if (!dbData) {
|
|
38
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_ARGUMENT, `Database config is not present at module config "options.database"`);
|
|
39
|
+
}
|
|
40
|
+
const entities = Object.values(InventoryModels);
|
|
41
|
+
const dataSource = new typeorm_1.DataSource({
|
|
42
|
+
type: dbData.type,
|
|
43
|
+
url: dbData.url,
|
|
44
|
+
database: dbData.database,
|
|
45
|
+
extra: dbData.extra || {},
|
|
46
|
+
schema: dbData.schema,
|
|
47
|
+
entities,
|
|
48
|
+
logging: dbData.logging,
|
|
49
|
+
});
|
|
50
|
+
await dataSource.initialize();
|
|
51
|
+
container.register({
|
|
52
|
+
manager: (0, awilix_1.asValue)(dataSource.manager),
|
|
53
|
+
});
|
|
54
|
+
};
|
|
45
55
|
//# sourceMappingURL=connection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/loaders/connection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/loaders/connection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAK8B;AAC9B,qCAAuD;AAEvD,mCAAgC;AAChC,yDAA+C;AAC/C,2DAA4C;AAG5C,kBAAe,KAAK,EAClB,EAAE,OAAO,EAAE,SAAS,EAAiB,EACrC,iBAA6C,EAC9B,EAAE;IACjB,IACE,iBAAiB,EAAE,KAAK,KAAK,0BAAY,CAAC,QAAQ;QAClD,iBAAiB,CAAC,SAAS,KAAK,kCAAoB,CAAC,MAAM,EAC3D;QACA,OAAM;KACP;IAED,MAAM,MAAM,GACV,OAAO,EAAE,QAAyD,CAAA;IAEpE,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,+BAAW,CACnB,+BAAW,CAAC,KAAK,CAAC,gBAAgB,EAClC,oEAAoE,CACrE,CAAA;KACF;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAA;IAC/C,MAAM,UAAU,GAAG,IAAI,oBAAU,CAAC;QAChC,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE;QACzB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,QAAQ;QACR,OAAO,EAAE,MAAM,CAAC,OAAO;KACH,CAAC,CAAA;IAEvB,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;IAE7B,SAAS,CAAC,QAAQ,CAAC;QACjB,OAAO,EAAE,IAAA,gBAAO,EAAC,UAAU,CAAC,OAAO,CAAC;KACrC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/modules-sdk";
|
|
2
|
+
export declare function runMigrations({ options, logger }: Omit<LoaderOptions, "container">, moduleDeclaration?: InternalModuleDeclaration): Promise<void>;
|
|
3
|
+
export declare function revertMigration({ options, logger }: Omit<LoaderOptions, "container">, moduleDeclaration?: InternalModuleDeclaration): Promise<void>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.revertMigration = exports.runMigrations = void 0;
|
|
7
|
+
const typeorm_1 = require("typeorm");
|
|
8
|
+
const index_1 = __importDefault(require("./index"));
|
|
9
|
+
function getDataSource(dbData) {
|
|
10
|
+
return new typeorm_1.DataSource({
|
|
11
|
+
type: dbData.type,
|
|
12
|
+
url: dbData.url,
|
|
13
|
+
database: dbData.database,
|
|
14
|
+
extra: dbData.extra || {},
|
|
15
|
+
migrations: index_1.default
|
|
16
|
+
.map((migration) => {
|
|
17
|
+
return Object.values(migration).filter((fn) => typeof fn === "function");
|
|
18
|
+
})
|
|
19
|
+
.flat(),
|
|
20
|
+
schema: dbData.schema,
|
|
21
|
+
logging: dbData.logging,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function runMigrations({ options, logger }, moduleDeclaration) {
|
|
25
|
+
const dbData = options?.database;
|
|
26
|
+
try {
|
|
27
|
+
const dataSource = getDataSource(dbData);
|
|
28
|
+
await dataSource.initialize();
|
|
29
|
+
await dataSource.runMigrations();
|
|
30
|
+
logger?.info("Inventory module migration executed");
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
logger?.error(`Inventory module migration failed to run - Error: ${error}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.runMigrations = runMigrations;
|
|
37
|
+
async function revertMigration({ options, logger }, moduleDeclaration) {
|
|
38
|
+
const dbData = options?.database;
|
|
39
|
+
try {
|
|
40
|
+
const dataSource = getDataSource(dbData);
|
|
41
|
+
await dataSource.initialize();
|
|
42
|
+
await dataSource.undoLastMigration();
|
|
43
|
+
logger?.info("Inventory module migration reverted");
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
logger?.error(`Inventory module migration failed to revert - Error: ${error}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.revertMigration = revertMigration;
|
|
50
|
+
//# sourceMappingURL=run-migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-migration.js","sourceRoot":"","sources":["../../src/migrations/run-migration.ts"],"names":[],"mappings":";;;;;;AACA,qCAAuD;AAGvD,oDAAgC;AAEhC,SAAS,aAAa,CACpB,MAAqD;IAErD,OAAO,IAAI,oBAAU,CAAC;QACpB,IAAI,EAAE,MAAO,CAAC,IAAI;QAClB,GAAG,EAAE,MAAO,CAAC,GAAG;QAChB,QAAQ,EAAE,MAAO,CAAC,QAAQ;QAC1B,KAAK,EAAE,MAAO,CAAC,KAAK,IAAI,EAAE;QAC1B,UAAU,EAAE,eAAU;aACnB,GAAG,CAAC,CAAC,SAAc,EAAc,EAAE;YAClC,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CACpC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,UAAU,CACnB,CAAA;QACjB,CAAC,CAAC;aACD,IAAI,EAAE;QACT,MAAM,EAAE,MAAO,CAAC,MAAM;QACtB,OAAO,EAAE,MAAO,CAAC,OAAO;KACJ,CAAC,CAAA;AACzB,CAAC;AAEM,KAAK,UAAU,aAAa,CACjC,EAAE,OAAO,EAAE,MAAM,EAAoC,EACrD,iBAA6C;IAE7C,MAAM,MAAM,GACV,OAAO,EAAE,QAAyD,CAAA;IAEpE,IAAI;QACF,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;QACxC,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;QAC7B,MAAM,UAAU,CAAC,aAAa,EAAE,CAAA;QAEhC,MAAM,EAAE,IAAI,CAAC,qCAAqC,CAAC,CAAA;KACpD;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,EAAE,KAAK,CAAC,qDAAqD,KAAK,EAAE,CAAC,CAAA;KAC5E;AACH,CAAC;AAhBD,sCAgBC;AAEM,KAAK,UAAU,eAAe,CACnC,EAAE,OAAO,EAAE,MAAM,EAAoC,EACrD,iBAA6C;IAE7C,MAAM,MAAM,GACV,OAAO,EAAE,QAAyD,CAAA;IAEpE,IAAI;QACF,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;QACxC,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;QAC7B,MAAM,UAAU,CAAC,iBAAiB,EAAE,CAAA;QAEpC,MAAM,EAAE,IAAI,CAAC,qCAAqC,CAAC,CAAA;KACpD;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,EAAE,KAAK,CACX,wDAAwD,KAAK,EAAE,CAChE,CAAA;KACF;AACH,CAAC;AAlBD,0CAkBC"}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import { ConfigModule } from "@medusajs/medusa";
|
|
2
1
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
|
3
|
-
export declare const up: ({ configModule }: {
|
|
4
|
-
configModule: ConfigModule;
|
|
5
|
-
}) => Promise<void>;
|
|
6
|
-
export declare const down: ({ configModule, }: {
|
|
7
|
-
configModule: ConfigModule;
|
|
8
|
-
}) => Promise<void>;
|
|
9
2
|
export declare class inventorySetup1665748086258 implements MigrationInterface {
|
|
10
3
|
name: string;
|
|
11
4
|
up(queryRunner: QueryRunner): Promise<void>;
|
|
@@ -1,131 +1,87 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.inventorySetup1665748086258 =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var up = function (_a) {
|
|
43
|
-
var configModule = _a.configModule;
|
|
44
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
45
|
-
var connection;
|
|
46
|
-
return __generator(this, function (_b) {
|
|
47
|
-
switch (_b.label) {
|
|
48
|
-
case 0: return [4 /*yield*/, (0, typeorm_1.createConnection)({
|
|
49
|
-
name: config_1.CONNECTION_NAME,
|
|
50
|
-
type: configModule.projectConfig.database_type,
|
|
51
|
-
url: configModule.projectConfig.database_url,
|
|
52
|
-
extra: configModule.projectConfig.database_extra || {},
|
|
53
|
-
schema: configModule.projectConfig.database_schema,
|
|
54
|
-
migrations: [inventorySetup1665748086258],
|
|
55
|
-
logging: true,
|
|
56
|
-
})];
|
|
57
|
-
case 1:
|
|
58
|
-
connection = _b.sent();
|
|
59
|
-
return [4 /*yield*/, connection.runMigrations()];
|
|
60
|
-
case 2:
|
|
61
|
-
_b.sent();
|
|
62
|
-
return [4 /*yield*/, connection.close()];
|
|
63
|
-
case 3:
|
|
64
|
-
_b.sent();
|
|
65
|
-
return [2 /*return*/];
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
exports.up = up;
|
|
71
|
-
var down = function (_a) {
|
|
72
|
-
var configModule = _a.configModule;
|
|
73
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
74
|
-
var connection;
|
|
75
|
-
return __generator(this, function (_b) {
|
|
76
|
-
switch (_b.label) {
|
|
77
|
-
case 0: return [4 /*yield*/, (0, typeorm_1.createConnection)({
|
|
78
|
-
name: config_1.CONNECTION_NAME,
|
|
79
|
-
type: configModule.projectConfig.database_type,
|
|
80
|
-
url: configModule.projectConfig.database_url,
|
|
81
|
-
extra: configModule.projectConfig.database_extra || {},
|
|
82
|
-
schema: configModule.projectConfig.database_schema,
|
|
83
|
-
migrations: [inventorySetup1665748086258],
|
|
84
|
-
logging: true,
|
|
85
|
-
})];
|
|
86
|
-
case 1:
|
|
87
|
-
connection = _b.sent();
|
|
88
|
-
return [4 /*yield*/, connection.undoLastMigration({ transaction: "all" })];
|
|
89
|
-
case 2:
|
|
90
|
-
_b.sent();
|
|
91
|
-
return [4 /*yield*/, connection.close()];
|
|
92
|
-
case 3:
|
|
93
|
-
_b.sent();
|
|
94
|
-
return [2 /*return*/];
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
exports.down = down;
|
|
100
|
-
var inventorySetup1665748086258 = /** @class */ (function () {
|
|
101
|
-
function inventorySetup1665748086258() {
|
|
3
|
+
exports.inventorySetup1665748086258 = void 0;
|
|
4
|
+
class inventorySetup1665748086258 {
|
|
5
|
+
constructor() {
|
|
102
6
|
this.name = "inventorySetup1665748086258";
|
|
103
7
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
8
|
+
async up(queryRunner) {
|
|
9
|
+
await queryRunner.query(`
|
|
10
|
+
CREATE TABLE "inventory_item" (
|
|
11
|
+
"id" character varying NOT NULL,
|
|
12
|
+
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
|
13
|
+
"updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
|
14
|
+
"deleted_at" TIMESTAMP WITH TIME ZONE,
|
|
15
|
+
"sku" text,
|
|
16
|
+
"origin_country" text,
|
|
17
|
+
"hs_code" text,
|
|
18
|
+
"mid_code" text,
|
|
19
|
+
"material" text,
|
|
20
|
+
"weight" integer,
|
|
21
|
+
"length" integer,
|
|
22
|
+
"height" integer,
|
|
23
|
+
"width" integer,
|
|
24
|
+
"requires_shipping" boolean NOT NULL DEFAULT true,
|
|
25
|
+
"metadata" jsonb,
|
|
26
|
+
CONSTRAINT "PK_inventory_item_id" PRIMARY KEY ("id")
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
CREATE UNIQUE INDEX "IDX_inventory_item_sku" ON "inventory_item" ("sku") WHERE deleted_at IS NULL;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
CREATE TABLE "reservation_item" (
|
|
33
|
+
"id" character varying NOT NULL,
|
|
34
|
+
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
|
35
|
+
"updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
|
36
|
+
"deleted_at" TIMESTAMP WITH TIME ZONE,
|
|
37
|
+
"line_item_id" text,
|
|
38
|
+
"inventory_item_id" text NOT NULL,
|
|
39
|
+
"location_id" text NOT NULL,
|
|
40
|
+
"quantity" integer NOT NULL,
|
|
41
|
+
"metadata" jsonb,
|
|
42
|
+
CONSTRAINT "PK_reservation_item_id" PRIMARY KEY ("id")
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
CREATE INDEX "IDX_reservation_item_line_item_id" ON "reservation_item" ("line_item_id") WHERE deleted_at IS NULL;
|
|
46
|
+
CREATE INDEX "IDX_reservation_item_inventory_item_id" ON "reservation_item" ("inventory_item_id") WHERE deleted_at IS NULL;
|
|
47
|
+
CREATE INDEX "IDX_reservation_item_location_id" ON "reservation_item" ("location_id") WHERE deleted_at IS NULL;
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
CREATE TABLE "inventory_level" (
|
|
51
|
+
"id" character varying NOT NULL,
|
|
52
|
+
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
|
53
|
+
"updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
|
54
|
+
"deleted_at" TIMESTAMP WITH TIME ZONE,
|
|
55
|
+
"inventory_item_id" text NOT NULL,
|
|
56
|
+
"location_id" text NOT NULL,
|
|
57
|
+
"stocked_quantity" integer NOT NULL DEFAULT 0,
|
|
58
|
+
"reserved_quantity" integer NOT NULL DEFAULT 0,
|
|
59
|
+
"incoming_quantity" integer NOT NULL DEFAULT 0,
|
|
60
|
+
"metadata" jsonb,
|
|
61
|
+
CONSTRAINT "PK_inventory_level_id" PRIMARY KEY ("id")
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
CREATE UNIQUE INDEX "UQ_inventory_level_inventory_item_id_location_id" ON "inventory_level" ("inventory_item_id", "location_id");
|
|
65
|
+
CREATE INDEX "IDX_inventory_level_inventory_item_id" ON "inventory_level" ("inventory_item_id");
|
|
66
|
+
CREATE INDEX "IDX_inventory_level_location_id" ON "inventory_level" ("location_id");
|
|
67
|
+
`);
|
|
68
|
+
}
|
|
69
|
+
async down(queryRunner) {
|
|
70
|
+
await queryRunner.query(`
|
|
71
|
+
DROP INDEX "IDX_inventory_level_location_id";
|
|
72
|
+
DROP INDEX "IDX_inventory_level_inventory_item_id";
|
|
73
|
+
DROP INDEX "UQ_inventory_level_inventory_item_id_location_id";
|
|
74
|
+
DROP TABLE "inventory_level";
|
|
75
|
+
|
|
76
|
+
DROP INDEX "IDX_reservation_item_location_id";
|
|
77
|
+
DROP INDEX "IDX_reservation_item_inventory_item_id";
|
|
78
|
+
DROP INDEX "IDX_reservation_item_line_item_id";
|
|
79
|
+
DROP TABLE "reservation_item";
|
|
80
|
+
|
|
81
|
+
DROP INDEX "IDX_inventory_item_sku";
|
|
82
|
+
DROP TABLE "inventory_item";
|
|
83
|
+
`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
130
86
|
exports.inventorySetup1665748086258 = inventorySetup1665748086258;
|
|
131
87
|
//# sourceMappingURL=1665748086258-inventory_setup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1665748086258-inventory_setup.js","sourceRoot":"","sources":["../../../src/migrations/schema-migrations/1665748086258-inventory_setup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"1665748086258-inventory_setup.js","sourceRoot":"","sources":["../../../src/migrations/schema-migrations/1665748086258-inventory_setup.ts"],"names":[],"mappings":";;;AAEA,MAAa,2BAA2B;IAAxC;QACE,SAAI,GAAG,6BAA6B,CAAA;IAgFtC,CAAC;IA9EQ,KAAK,CAAC,EAAE,CAAC,WAAwB;QACtC,MAAM,WAAW,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA0DvB,CAAC,CAAA;IACJ,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,WAAwB;QACxC,MAAM,WAAW,CAAC,KAAK,CAAC;;;;;;;;;;;;;KAavB,CAAC,CAAA;IACJ,CAAC;CACF;AAjFD,kEAiFC"}
|