@trailmix-cms/db 0.0.1

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.
Files changed (73) hide show
  1. package/dist/audited.base-collection.d.ts +26 -0
  2. package/dist/audited.base-collection.d.ts.map +1 -0
  3. package/dist/audited.base-collection.js +151 -0
  4. package/dist/audited.base-collection.js.map +1 -0
  5. package/dist/collection.decorator.d.ts +3 -0
  6. package/dist/collection.decorator.d.ts.map +1 -0
  7. package/dist/collection.decorator.js +9 -0
  8. package/dist/collection.decorator.js.map +1 -0
  9. package/dist/collection.factory.d.ts +14 -0
  10. package/dist/collection.factory.d.ts.map +1 -0
  11. package/dist/collection.factory.js +29 -0
  12. package/dist/collection.factory.js.map +1 -0
  13. package/dist/collections/audit.collection.d.ts +93 -0
  14. package/dist/collections/audit.collection.d.ts.map +1 -0
  15. package/dist/collections/audit.collection.js +69 -0
  16. package/dist/collections/audit.collection.js.map +1 -0
  17. package/dist/collections/index.d.ts +9 -0
  18. package/dist/collections/index.d.ts.map +1 -0
  19. package/dist/collections/index.js +15 -0
  20. package/dist/collections/index.js.map +1 -0
  21. package/dist/config.d.ts +13 -0
  22. package/dist/config.d.ts.map +1 -0
  23. package/dist/config.js +26 -0
  24. package/dist/config.js.map +1 -0
  25. package/dist/connection.factory.d.ts +24 -0
  26. package/dist/connection.factory.d.ts.map +1 -0
  27. package/dist/connection.factory.js +71 -0
  28. package/dist/connection.factory.js.map +1 -0
  29. package/dist/constants/index.d.ts +2 -0
  30. package/dist/constants/index.d.ts.map +1 -0
  31. package/dist/constants/index.js +18 -0
  32. package/dist/constants/index.js.map +1 -0
  33. package/dist/constants/internal-collection-names.d.ts +5 -0
  34. package/dist/constants/internal-collection-names.d.ts.map +1 -0
  35. package/dist/constants/internal-collection-names.js +7 -0
  36. package/dist/constants/internal-collection-names.js.map +1 -0
  37. package/dist/database.module.d.ts +3 -0
  38. package/dist/database.module.d.ts.map +1 -0
  39. package/dist/database.module.js +43 -0
  40. package/dist/database.module.js.map +1 -0
  41. package/dist/database.service.d.ts +17 -0
  42. package/dist/database.service.d.ts.map +1 -0
  43. package/dist/database.service.js +50 -0
  44. package/dist/database.service.js.map +1 -0
  45. package/dist/index.d.ts +8 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +47 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/utils/build-collection-token.d.ts +3 -0
  50. package/dist/utils/build-collection-token.d.ts.map +1 -0
  51. package/dist/utils/build-collection-token.js +11 -0
  52. package/dist/utils/build-collection-token.js.map +1 -0
  53. package/dist/utils/codes.d.ts +8 -0
  54. package/dist/utils/codes.d.ts.map +1 -0
  55. package/dist/utils/codes.js +62 -0
  56. package/dist/utils/codes.js.map +1 -0
  57. package/dist/utils/default.d.ts +8 -0
  58. package/dist/utils/default.d.ts.map +1 -0
  59. package/dist/utils/default.js +19 -0
  60. package/dist/utils/default.js.map +1 -0
  61. package/dist/utils/environment.d.ts +2 -0
  62. package/dist/utils/environment.d.ts.map +1 -0
  63. package/dist/utils/environment.js +5 -0
  64. package/dist/utils/environment.js.map +1 -0
  65. package/dist/utils/index.d.ts +4 -0
  66. package/dist/utils/index.d.ts.map +1 -0
  67. package/dist/utils/index.js +20 -0
  68. package/dist/utils/index.js.map +1 -0
  69. package/dist/utils/record.d.ts +19 -0
  70. package/dist/utils/record.d.ts.map +1 -0
  71. package/dist/utils/record.js +19 -0
  72. package/dist/utils/record.js.map +1 -0
  73. package/package.json +36 -0
@@ -0,0 +1,2 @@
1
+ export * from './internal-collection-names';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./internal-collection-names"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C"}
@@ -0,0 +1,5 @@
1
+ export declare const InternalCollectionName: {
2
+ readonly Audit: "audit";
3
+ };
4
+ export type InternalCollectionName = typeof InternalCollectionName[keyof typeof InternalCollectionName];
5
+ //# sourceMappingURL=internal-collection-names.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-collection-names.d.ts","sourceRoot":"","sources":["../../src/constants/internal-collection-names.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB;;CAEzB,CAAC;AAEX,MAAM,MAAM,sBAAsB,GAAG,OAAO,sBAAsB,CAAC,MAAM,OAAO,sBAAsB,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InternalCollectionName = void 0;
4
+ exports.InternalCollectionName = {
5
+ Audit: 'audit',
6
+ };
7
+ //# sourceMappingURL=internal-collection-names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-collection-names.js","sourceRoot":"","sources":["../../src/constants/internal-collection-names.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG;IAClC,KAAK,EAAE,OAAO;CACR,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare class DatabaseModule {
2
+ }
3
+ //# sourceMappingURL=database.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.module.d.ts","sourceRoot":"","sources":["../src/database.module.ts"],"names":[],"mappings":"AAWA,qBAmBa,cAAc;CAAI"}
@@ -0,0 +1,43 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.DatabaseModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const database_service_1 = require("./database.service");
12
+ const connection_factory_1 = require("./connection.factory");
13
+ const collections_1 = require("./collections");
14
+ const config_1 = require("@nestjs/config");
15
+ const config_2 = require("./config");
16
+ const collection_factory_1 = require("./collection.factory");
17
+ const constants_1 = require("./constants");
18
+ const build_collection_token_1 = require("./utils/build-collection-token");
19
+ let DatabaseModule = class DatabaseModule {
20
+ };
21
+ exports.DatabaseModule = DatabaseModule;
22
+ exports.DatabaseModule = DatabaseModule = __decorate([
23
+ (0, common_1.Module)({
24
+ imports: [
25
+ config_1.ConfigModule.forRoot({
26
+ load: [config_2.configuration],
27
+ }),
28
+ ],
29
+ providers: [
30
+ database_service_1.DatabaseService,
31
+ connection_factory_1.connectionFactory,
32
+ ...collections_1.collectionServices,
33
+ ...Object.values(constants_1.InternalCollectionName).map(collectionName => (0, collection_factory_1.collectionFactory)(collectionName))
34
+ ],
35
+ exports: [
36
+ database_service_1.DatabaseService,
37
+ connection_factory_1.connectionFactory,
38
+ ...collections_1.collectionServices,
39
+ ...Object.values(constants_1.InternalCollectionName).map(build_collection_token_1.buildCollectionToken)
40
+ ]
41
+ })
42
+ ], DatabaseModule);
43
+ //# sourceMappingURL=database.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.module.js","sourceRoot":"","sources":["../src/database.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAChD,yDAAqD;AACrD,6DAAyD;AACzD,+CAAmD;AACnD,2CAA8C;AAC9C,qCAAyC;AACzC,6DAAyD;AACzD,2CAAqD;AACrD,2EAAsE;AAsB/D,IAAM,cAAc,GAApB,MAAM,cAAc;CAAI,CAAA;AAAlB,wCAAc;yBAAd,cAAc;IAnB1B,IAAA,eAAM,EAAC;QACJ,OAAO,EAAE;YACL,qBAAY,CAAC,OAAO,CAAC;gBACjB,IAAI,EAAE,CAAC,sBAAa,CAAC;aACxB,CAAC;SACL;QACD,SAAS,EAAE;YACP,kCAAe;YACf,sCAAiB;YACjB,GAAG,gCAAkB;YACrB,GAAG,MAAM,CAAC,MAAM,CAAC,kCAAsB,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC,IAAA,sCAAiB,EAAC,cAAc,CAAC,CAAC;SACpG;QACD,OAAO,EAAE;YACL,kCAAe;YACf,sCAAiB;YACjB,GAAG,gCAAkB;YACrB,GAAG,MAAM,CAAC,MAAM,CAAC,kCAAsB,CAAC,CAAC,GAAG,CAAC,6CAAoB,CAAC;SACrE;KACJ,CAAC;GACW,cAAc,CAAI"}
@@ -0,0 +1,17 @@
1
+ import { OnApplicationShutdown } from '@nestjs/common';
2
+ import { connectionFactory } from './connection.factory';
3
+ import * as mongodb from 'mongodb';
4
+ import { ClientSession } from 'mongodb';
5
+ type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T;
6
+ export declare class DatabaseService implements OnApplicationShutdown {
7
+ private readonly connection;
8
+ readonly db: mongodb.Db;
9
+ constructor(connection: Awaited<ReturnType<typeof connectionFactory.useFactory>>);
10
+ startSession(): mongodb.ClientSession;
11
+ withTransaction<T>({ session }: {
12
+ session?: ClientSession;
13
+ }, fn: (session: ClientSession) => Promise<T>): Promise<T>;
14
+ onApplicationShutdown(signal: string): void;
15
+ }
16
+ export {};
17
+ //# sourceMappingURL=database.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.service.d.ts","sourceRoot":"","sources":["../src/database.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAElE,qBACa,eAAgB,YAAW,qBAAqB;IAGlB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAFlE,SAAgB,EAAE,EAAE,OAAO,CAAC,EAAE,CAAC;gBAEyB,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAK5H,YAAY;IAIN,eAAe,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,CAAC,EAAE,aAAa,CAAA;KAAE,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,CAAC,CAAC;IAa7G,qBAAqB,CAAC,MAAM,EAAE,MAAM;CAGvC"}
@@ -0,0 +1,50 @@
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DatabaseService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const connection_factory_1 = require("./connection.factory");
18
+ let DatabaseService = class DatabaseService {
19
+ connection;
20
+ db;
21
+ constructor(connection) {
22
+ this.connection = connection;
23
+ this.db = connection.db;
24
+ }
25
+ startSession() {
26
+ return this.connection.client.startSession();
27
+ }
28
+ async withTransaction({ session }, fn) {
29
+ if (session) {
30
+ return await fn(session);
31
+ }
32
+ session = await this.connection.client.startSession();
33
+ const result = await session.withTransaction(async () => {
34
+ const result = await fn(session);
35
+ return result;
36
+ });
37
+ await session.endSession();
38
+ return result;
39
+ }
40
+ onApplicationShutdown(signal) {
41
+ this.connection.client.close();
42
+ }
43
+ };
44
+ exports.DatabaseService = DatabaseService;
45
+ exports.DatabaseService = DatabaseService = __decorate([
46
+ (0, common_1.Injectable)(),
47
+ __param(0, (0, common_1.Inject)(connection_factory_1.connectionFactory.provide)),
48
+ __metadata("design:paramtypes", [Object])
49
+ ], DatabaseService);
50
+ //# sourceMappingURL=database.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.service.js","sourceRoot":"","sources":["../src/database.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,6DAAyD;AAQlD,IAAM,eAAe,GAArB,MAAM,eAAe;IAGgC;IAFxC,EAAE,CAAa;IAC/B,YACwD,UAAoE;QAApE,eAAU,GAAV,UAAU,CAA0D;QAExH,IAAI,CAAC,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;IAC5B,CAAC;IAED,YAAY;QACR,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,eAAe,CAAI,EAAE,OAAO,EAA+B,EAAE,EAA0C;QACzG,IAAI,OAAO,EAAE,CAAC;YACV,OAAO,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QACD,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;QACtD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,KAAK,IAAI,EAAE;YACpD,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;YACjC,OAAO,MAAM,CAAC;QAClB,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;QAC3B,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,qBAAqB,CAAC,MAAc;QAChC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACnC,CAAC;CACJ,CAAA;AA5BY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAIJ,WAAA,IAAA,eAAM,EAAC,sCAAiB,CAAC,OAAO,CAAC,CAAA;;GAH7B,eAAe,CA4B3B"}
@@ -0,0 +1,8 @@
1
+ export * from './database.module';
2
+ export * from './database.service';
3
+ export * from './audited.base-collection';
4
+ export * from './collection.decorator';
5
+ export * from './collection.factory';
6
+ export * as Collections from './collections';
7
+ export * as Utils from './utils';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AAErC,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,47 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.Utils = exports.Collections = void 0;
40
+ __exportStar(require("./database.module"), exports);
41
+ __exportStar(require("./database.service"), exports);
42
+ __exportStar(require("./audited.base-collection"), exports);
43
+ __exportStar(require("./collection.decorator"), exports);
44
+ __exportStar(require("./collection.factory"), exports);
45
+ exports.Collections = __importStar(require("./collections"));
46
+ exports.Utils = __importStar(require("./utils"));
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAAkC;AAClC,qDAAmC;AAEnC,4DAA0C;AAC1C,yDAAuC;AACvC,uDAAqC;AAErC,6DAA6C;AAC7C,iDAAiC"}
@@ -0,0 +1,3 @@
1
+ export declare function buildCollectionToken(collectionName: string): string;
2
+ export declare function buildCollectionTokens(collectionNames: string[]): string[];
3
+ //# sourceMappingURL=build-collection-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-collection-token.d.ts","sourceRoot":"","sources":["../../src/utils/build-collection-token.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,cAAc,EAAE,MAAM,UAE1D;AAED,wBAAgB,qBAAqB,CAAC,eAAe,EAAE,MAAM,EAAE,YAE9D"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildCollectionToken = buildCollectionToken;
4
+ exports.buildCollectionTokens = buildCollectionTokens;
5
+ function buildCollectionToken(collectionName) {
6
+ return `COLLECTION_${collectionName}`;
7
+ }
8
+ function buildCollectionTokens(collectionNames) {
9
+ return collectionNames.map(buildCollectionToken);
10
+ }
11
+ //# sourceMappingURL=build-collection-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-collection-token.js","sourceRoot":"","sources":["../../src/utils/build-collection-token.ts"],"names":[],"mappings":";;AAAA,oDAEC;AAED,sDAEC;AAND,SAAgB,oBAAoB,CAAC,cAAsB;IACvD,OAAO,cAAc,cAAc,EAAE,CAAC;AAC1C,CAAC;AAED,SAAgB,qBAAqB,CAAC,eAAyB;IAC3D,OAAO,eAAe,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AACrD,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare const GENERATED_TOKEN_LENGTH = 128;
2
+ export declare const SHORT_CODE_LENGTH = 6;
3
+ export declare namespace Codes {
4
+ function generateToken(length?: number): string;
5
+ function generateShortAlphaNumericCode(): string;
6
+ function generateShortNumericCode(): number;
7
+ }
8
+ //# sourceMappingURL=codes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../src/utils/codes.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAC1C,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAMnC,yBAAiB,KAAK,CAAC;IACnB,SAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,UAE5C;IAED,SAAgB,6BAA6B,WAM5C;IAED,SAAgB,wBAAwB,WAEvC;CACJ"}
@@ -0,0 +1,62 @@
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Codes = exports.SHORT_CODE_LENGTH = exports.GENERATED_TOKEN_LENGTH = void 0;
37
+ const crypto = __importStar(require("crypto"));
38
+ exports.GENERATED_TOKEN_LENGTH = 128;
39
+ exports.SHORT_CODE_LENGTH = 6;
40
+ const SHORT_CODE_CHAR_SET = '123456789abcdefghijkmnopqrstuvwxyz'; // 1-9 and aplhabet without 'l'
41
+ const MIN_CODE = 10000000;
42
+ const MAX_CODE = 99999999;
43
+ var Codes;
44
+ (function (Codes) {
45
+ function generateToken(length) {
46
+ return crypto.randomBytes(length || exports.GENERATED_TOKEN_LENGTH / 2).toString('hex');
47
+ }
48
+ Codes.generateToken = generateToken;
49
+ function generateShortAlphaNumericCode() {
50
+ let result = '';
51
+ for (let i = 0; i < exports.SHORT_CODE_LENGTH; i++) {
52
+ result += SHORT_CODE_CHAR_SET.charAt(Math.floor(Math.random() * SHORT_CODE_CHAR_SET.length));
53
+ }
54
+ return result;
55
+ }
56
+ Codes.generateShortAlphaNumericCode = generateShortAlphaNumericCode;
57
+ function generateShortNumericCode() {
58
+ return crypto.randomInt(MIN_CODE, MAX_CODE);
59
+ }
60
+ Codes.generateShortNumericCode = generateShortNumericCode;
61
+ })(Codes || (exports.Codes = Codes = {}));
62
+ //# sourceMappingURL=codes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codes.js","sourceRoot":"","sources":["../../src/utils/codes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEpB,QAAA,sBAAsB,GAAG,GAAG,CAAC;AAC7B,QAAA,iBAAiB,GAAG,CAAC,CAAC;AACnC,MAAM,mBAAmB,GAAG,oCAAoC,CAAA,CAAC,+BAA+B;AAEhG,MAAM,QAAQ,GAAG,QAAQ,CAAC;AAC1B,MAAM,QAAQ,GAAG,QAAQ,CAAC;AAE1B,IAAiB,KAAK,CAgBrB;AAhBD,WAAiB,KAAK;IAClB,SAAgB,aAAa,CAAC,MAAe;QACzC,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,IAAI,8BAAsB,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpF,CAAC;IAFe,mBAAa,gBAE5B,CAAA;IAED,SAAgB,6BAA6B;QACzC,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,yBAAiB,EAAE,CAAC,EAAE,EAAE,CAAC;YACzC,MAAM,IAAI,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;QACjG,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;IANe,mCAA6B,gCAM5C,CAAA;IAED,SAAgB,wBAAwB;QACpC,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAC/C,CAAC;IAFe,8BAAwB,2BAEvC,CAAA;AACL,CAAC,EAhBgB,KAAK,qBAAL,KAAK,QAgBrB"}
@@ -0,0 +1,8 @@
1
+ import { Document, Collection } from 'mongodb';
2
+ import { Creatable } from './record';
3
+ import { Base } from '@trailmixcms/models';
4
+ export declare function createDefault<T extends Base.BaseEntity & Document>({ collection, defaultEntity }: {
5
+ collection: Collection<T>;
6
+ defaultEntity: Creatable<T>;
7
+ }): Promise<void>;
8
+ //# sourceMappingURL=default.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/utils/default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAA4B,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,SAAS,EAAiB,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,wBAAsB,aAAa,CAAC,CAAC,SAAS,IAAI,CAAC,UAAU,GAAG,QAAQ,EAAE,EAAE,UAAU,EAAE,aAAa,EAAE,EAAE;IAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAAC,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;CAAE,iBAiBnK"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDefault = createDefault;
4
+ const record_1 = require("./record");
5
+ async function createDefault({ collection, defaultEntity }) {
6
+ const createdDefault = (0, record_1.ensureCreated)(defaultEntity);
7
+ const count = await collection.countDocuments({});
8
+ if (count === 0) {
9
+ await collection.insertOne(createdDefault);
10
+ }
11
+ else {
12
+ const existing = await collection.findOne({});
13
+ if (existing) {
14
+ const { _id, ...defaultFields } = createdDefault;
15
+ await collection.updateOne({}, { $set: { ...defaultFields, ...existing } }, { upsert: true });
16
+ }
17
+ }
18
+ }
19
+ //# sourceMappingURL=default.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default.js","sourceRoot":"","sources":["../../src/utils/default.ts"],"names":[],"mappings":";;AAIA,sCAiBC;AApBD,qCAAoD;AAG7C,KAAK,UAAU,aAAa,CAAuC,EAAE,UAAU,EAAE,aAAa,EAA+D;IAChK,MAAM,cAAc,GAAG,IAAA,sBAAa,EAAI,aAAa,CAAgC,CAAC;IAEtF,MAAM,KAAK,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IAClD,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QACd,MAAM,UAAU,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC/C,CAAC;SAAM,CAAC;QACJ,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC9C,IAAI,QAAQ,EAAE,CAAC;YACX,MAAM,EAAE,GAAG,EAAE,GAAG,aAAa,EAAE,GAAG,cAAc,CAAC;YACjD,MAAM,UAAU,CAAC,SAAS,CACtB,EAAE,EACF,EAAE,IAAI,EAAE,EAAE,GAAG,aAAa,EAAE,GAAG,QAAQ,EAAgB,EAAE,EACzD,EAAE,MAAM,EAAE,IAAI,EAAE,CACnB,CAAC;QACN,CAAC;IACL,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const pkg: any;
2
+ //# sourceMappingURL=environment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,GAAG,KAAgC,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pkg = void 0;
4
+ exports.pkg = require('../../package.json');
5
+ //# sourceMappingURL=environment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.js","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":";;;AAAa,QAAA,GAAG,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './default';
2
+ export * from './build-collection-token';
3
+ export * from './record';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,0BAA0B,CAAC;AACzC,cAAc,UAAU,CAAC"}
@@ -0,0 +1,20 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./default"), exports);
18
+ __exportStar(require("./build-collection-token"), exports);
19
+ __exportStar(require("./record"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,2DAAyC;AACzC,2CAAyB"}
@@ -0,0 +1,19 @@
1
+ import { ObjectId, OptionalId } from 'mongodb';
2
+ export type Creatable<T> = OptionalId<Omit<T, 'created_at' | 'expire_at'> & {
3
+ created_at?: Date;
4
+ }>;
5
+ export declare function ensureCreated<T>(record: Creatable<T>): import("mongodb").EnhancedOmit<Omit<T, "created_at" | "expire_at"> & {
6
+ created_at?: Date;
7
+ }, "_id"> & {
8
+ _id: ObjectId;
9
+ created_at: Date;
10
+ };
11
+ export declare function ensureUpdated<T>(record: Creatable<T>): import("mongodb").EnhancedOmit<Omit<T, "created_at" | "expire_at"> & {
12
+ created_at?: Date;
13
+ }, "_id"> & {
14
+ updated_at: Date;
15
+ _id?: import("mongodb").InferIdType<Omit<T, "created_at" | "expire_at"> & {
16
+ created_at?: Date;
17
+ }> | undefined;
18
+ };
19
+ //# sourceMappingURL=record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/utils/record.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,YAAY,GAAE,WAAW,CAAC,GAAG;IAAE,UAAU,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC;AAElG,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;iBAFqC,IAAI;;;;EAQ7F;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;iBAVqC,IAAI;;;;qBAAJ,IAAI;;EAe7F"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureCreated = ensureCreated;
4
+ exports.ensureUpdated = ensureUpdated;
5
+ const mongodb_1 = require("mongodb");
6
+ function ensureCreated(record) {
7
+ return {
8
+ ...record,
9
+ _id: new mongodb_1.ObjectId(),
10
+ created_at: new Date()
11
+ };
12
+ }
13
+ function ensureUpdated(record) {
14
+ return {
15
+ ...record,
16
+ updated_at: new Date()
17
+ };
18
+ }
19
+ //# sourceMappingURL=record.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record.js","sourceRoot":"","sources":["../../src/utils/record.ts"],"names":[],"mappings":";;AAIA,sCAMC;AAED,sCAKC;AAjBD,qCAA+C;AAI/C,SAAgB,aAAa,CAAI,MAAoB;IACjD,OAAO;QACH,GAAG,MAAM;QACT,GAAG,EAAE,IAAI,kBAAQ,EAAE;QACnB,UAAU,EAAE,IAAI,IAAI,EAAE;KACzB,CAAC;AACN,CAAC;AAED,SAAgB,aAAa,CAAI,MAAoB;IACjD,OAAO;QACH,GAAG,MAAM;QACT,UAAU,EAAE,IAAI,IAAI,EAAE;KACzB,CAAC;AACN,CAAC"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@trailmix-cms/db",
3
+ "version": "0.0.1",
4
+ "main": "./dist/index.js",
5
+ "types": "./dist/index.d.ts",
6
+ "scripts": {
7
+ "build": "tsc -b -v",
8
+ "clean": "tsc -b --clean",
9
+ "trace": "tsc --traceResolution"
10
+ },
11
+ "dependencies": {
12
+ "@nestjs/common": "^11.1.9",
13
+ "@nestjs/config": "^4.0.2",
14
+ "@trailmix-cms/models": "0.0.1",
15
+ "envalid": "^8.1.1",
16
+ "lodash.merge": "^4.6.2",
17
+ "mongodb": "^7.0.0",
18
+ "reflect-metadata": "^0.2.2",
19
+ "rxjs": "^7.8.2",
20
+ "zod": "^4.1.12"
21
+ },
22
+ "devDependencies": {
23
+ "@types/lodash.merge": "^4.6.9",
24
+ "@types/node": "^24.10.1",
25
+ "typescript": "5.9.3"
26
+ },
27
+ "peerDependencies": {
28
+ "@nestjs/common": "^11.1.9",
29
+ "@nestjs/config": "^4.0.2",
30
+ "@trailmix-cms/models": "0.0.1",
31
+ "mongodb": "^7.0.0",
32
+ "reflect-metadata": "^0.2.2",
33
+ "rxjs": "^7.8.2",
34
+ "zod": "^4.1.12"
35
+ }
36
+ }