@ldsg/database 0.3.25 → 0.3.27

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014-present Sebastian McKenzie and other contributors
3
+ Copyright (c) 2014-present Wanxger and other contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,0CAA0C,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,sDAAsD,EAAE,uBAGpE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uDAAuD,EAAE,+BAOrE,CAAC;AAEF,eAAO,MAAM,6CAA6C,EAAE,uBAG3D,CAAC;AAEF,eAAO,MAAM,8CAA8C,EAAE,0CAG5D,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,0CAA0C,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,sDAAsD,EAAE,uBAGpE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uDAAuD,EAAE,+BAOrE,CAAC;AAEF,eAAO,MAAM,6CAA6C,EAAE,uBAG3D,CAAC;AAEF,eAAO,MAAM,8CAA8C,EAAE,0CAE5D,CAAC"}
package/dist/constants.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = void 0;
4
- const constants_1 = require("@ldsg/constants");
5
4
  /**
6
5
  * Instantiate Resource Handler General Resource Settings
7
6
  * 实例化资源处理程序普通资源配置
@@ -28,6 +27,5 @@ exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = {
28
27
  description: ''
29
28
  };
30
29
  exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = {
31
- kind: 'database',
32
- parentKind: constants_1.ROOT_RESOURCE_KIND
30
+ kind: 'database'
33
31
  };
@@ -3,6 +3,10 @@ import mongoose from 'mongoose';
3
3
  import { DatabaseSpecificResourceSettings } from './types';
4
4
  export declare class DatabaseResource extends Resource<DatabaseSpecificResourceSettings> {
5
5
  constructor(params: ResourceConstructorParams<DatabaseSpecificResourceSettings>);
6
+ getDatabaseInfo: () => {
7
+ uri: string;
8
+ connectOptions: mongoose.ConnectOptions;
9
+ };
6
10
  connect: () => Promise<typeof mongoose>;
7
11
  disconnect: () => Promise<void>;
8
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,gCAAgC,EAAE,MAAM,SAAS,CAAC;AAE3D,qBAAa,gBAAiB,SAAQ,QAAQ,CAAC,gCAAgC,CAAC;gBAClE,MAAM,EAAE,yBAAyB,CAAC,gCAAgC,CAAC;IAQ/E,OAAO,iCAUL;IAEF,UAAU,sBAER;CACH"}
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,gCAAgC,EAAE,MAAM,SAAS,CAAC;AAE3D,qBAAa,gBAAiB,SAAQ,QAAQ,CAAC,gCAAgC,CAAC;gBAClE,MAAM,EAAE,yBAAyB,CAAC,gCAAgC,CAAC;IAQ/E,eAAe;;;MAYb;IAEF,OAAO,iCAIL;IAEF,UAAU,sBAER;CACH"}
package/dist/resource.js CHANGED
@@ -9,11 +9,16 @@ const mongoose_1 = __importDefault(require("mongoose"));
9
9
  class DatabaseResource extends resource_1.Resource {
10
10
  constructor(params) {
11
11
  super(params);
12
- this.connect = () => {
13
- const { settings: { uri = process.env.MONGODB_URI, connectOptions = {} } } = this;
12
+ this.getDatabaseInfo = () => {
13
+ const { settings: { uri: settingsUri, connectOptions = {} } } = this;
14
+ const uri = settingsUri || process.env.MONGODB_URI;
14
15
  if (!uri) {
15
- throw new Error('the uri in the database resources is not defined');
16
+ throw new Error('the uri in the database resource is not defined');
16
17
  }
18
+ return { uri, connectOptions };
19
+ };
20
+ this.connect = () => {
21
+ const { uri, connectOptions } = this.getDatabaseInfo();
17
22
  return mongoose_1.default.connect(uri, connectOptions);
18
23
  };
19
24
  this.disconnect = () => {
@@ -1,13 +1,12 @@
1
- import { SpecificResourceSettings } from '@ldsg/types';
1
+ import { z } from 'zod';
2
2
  import { ConnectOptions } from 'mongoose';
3
- export interface DatabaseSpecificResourceSettings extends SpecificResourceSettings {
4
- /**
5
- * Database URI
6
- */
7
- uri: string;
8
- /**
9
- * Connect Options
10
- */
11
- connectOptions?: ConnectOptions;
12
- }
3
+ export declare const DatabaseSpecificResourceSettingsSchema: z.ZodObject<{
4
+ uri: z.ZodString;
5
+ connectOptions: z.ZodOptional<z.ZodCustom<ConnectOptions, ConnectOptions>>;
6
+ }, z.core.$catchall<z.ZodAny>>;
7
+ export declare const SpecificResourceSettingsSchema: z.ZodObject<{
8
+ uri: z.ZodString;
9
+ connectOptions: z.ZodOptional<z.ZodCustom<ConnectOptions, ConnectOptions>>;
10
+ }, z.core.$catchall<z.ZodAny>>;
11
+ export type DatabaseSpecificResourceSettings = z.infer<typeof DatabaseSpecificResourceSettingsSchema>;
13
12
  //# sourceMappingURL=specific-resource-settings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"specific-resource-settings.d.ts","sourceRoot":"","sources":["../../src/types/specific-resource-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,WAAW,gCAAiC,SAAQ,wBAAwB;IAChF;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC"}
1
+ {"version":3,"file":"specific-resource-settings.d.ts","sourceRoot":"","sources":["../../src/types/specific-resource-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,eAAO,MAAM,sCAAsC;;;8BAY/B,CAAC;AAErB,eAAO,MAAM,8BAA8B;;;8BAAyC,CAAC;AACrF,MAAM,MAAM,gCAAgC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sCAAsC,CAAC,CAAC"}
@@ -1,2 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpecificResourceSettingsSchema = exports.DatabaseSpecificResourceSettingsSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.DatabaseSpecificResourceSettingsSchema = zod_1.z
6
+ .object({
7
+ /**
8
+ * Database URI
9
+ */
10
+ uri: zod_1.z.string(),
11
+ /**
12
+ * Connect Options
13
+ */
14
+ connectOptions: zod_1.z.custom().optional()
15
+ })
16
+ .catchall(zod_1.z.any());
17
+ exports.SpecificResourceSettingsSchema = exports.DatabaseSpecificResourceSettingsSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ldsg/database",
3
- "version": "0.3.25",
3
+ "version": "0.3.27",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -12,11 +12,12 @@
12
12
  ],
13
13
  "dependencies": {
14
14
  "mongoose": "^8.14.3",
15
- "@ldsg/constants": "0.3.25",
16
- "@ldsg/resource-definition": "0.3.25",
17
- "@ldsg/handler": "0.3.25",
18
- "@ldsg/types": "0.3.25",
19
- "@ldsg/resource": "0.3.25"
15
+ "zod": "^4.1.11",
16
+ "@ldsg/constants": "0.3.27",
17
+ "@ldsg/handler": "0.3.27",
18
+ "@ldsg/resource": "0.3.27",
19
+ "@ldsg/resource-definition": "0.3.27",
20
+ "@ldsg/types": "0.3.27"
20
21
  },
21
22
  "devDependencies": {
22
23
  "@types/jest": "^29.5.2",
@@ -34,6 +35,6 @@
34
35
  "scripts": {
35
36
  "build": "tsc --project tsconfig.build.json",
36
37
  "clean": "rm -rf dist",
37
- "test": "jest --passWithNoTests"
38
+ "test": "jest"
38
39
  }
39
40
  }