@tstdl/base 0.84.30 → 0.84.32

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/browser/utils.js CHANGED
@@ -25,6 +25,7 @@ __export(utils_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(utils_exports);
27
27
  var import_object = require("../utils/object/object.js");
28
+ var import_type_guards = require("../utils/type-guards.js");
28
29
  function getLaunchOptions(options) {
29
30
  const { windowSize, browserArguments, headless } = options;
30
31
  const args = [`--window-size=${windowSize?.width ?? 1e3},${windowSize?.height ?? 1e3}`, ...browserArguments ?? []];
@@ -48,8 +49,8 @@ function mergeNewBrowserContextOptions(a, b, c) {
48
49
  };
49
50
  }
50
51
  function isLocator(locatorOrHandle) {
51
- return (0, import_object.hasOwnProperty)(locatorOrHandle, "count");
52
+ return (0, import_type_guards.isFunction)(locatorOrHandle.count);
52
53
  }
53
54
  function isElementHandle(locatorOrHandle) {
54
- return (0, import_object.hasOwnProperty)(locatorOrHandle, "asElement");
55
+ return (0, import_type_guards.isFunction)(locatorOrHandle.asElement);
55
56
  }
@@ -64,22 +64,23 @@ class MongoEntityRepository extends import_database.EntityRepository {
64
64
  await this.initialize();
65
65
  }
66
66
  async initialize() {
67
- const indexes = this.indexes;
67
+ const indexes = this.indexes?.map((index) => ({ index, normalizedIndex: normalizeIndex(index) }));
68
68
  if ((0, import_type_guards.isUndefined)(indexes)) {
69
69
  return;
70
70
  }
71
71
  const existingRawIndexes = await this.collection.indexes();
72
72
  const existingIndexes = existingRawIndexes.map(normalizeIndex).filter((index) => index.name != "_id_");
73
- const unwantedIndexes = existingIndexes.filter((existingIndex) => !indexes.some((index) => (0, import_equals.equals)(existingIndex, index, { deep: true, sortArray: false })));
74
- const requiredIndexes = indexes.filter((wantedIndex) => !existingIndexes.some((index) => (0, import_equals.equals)(wantedIndex, index, { deep: true, sortArray: false })));
73
+ const unwantedIndexes = existingIndexes.filter((existingIndex) => !indexes.some(({ normalizedIndex }) => (0, import_equals.equals)(existingIndex, normalizedIndex, { deep: true, sortArray: false })));
74
+ const requiredIndexes = indexes.filter(({ normalizedIndex: wantedNormalizedIndex }) => !existingIndexes.some((index) => (0, import_equals.equals)(wantedNormalizedIndex, index, { deep: true, sortArray: false })));
75
75
  for (const unwantedIndex of unwantedIndexes) {
76
76
  this.logger.warn(`dropping index ${unwantedIndex.name}`);
77
77
  await this.collection.dropIndex(unwantedIndex.name);
78
78
  }
79
79
  if (requiredIndexes.length > 0) {
80
- const indexNames = requiredIndexes.map((index) => index.name ?? (0, import_throw._throw)(new Error("index name missing")));
80
+ const indexexToCreate = requiredIndexes.map(({ index }) => index);
81
+ const indexNames = indexexToCreate.map((index) => index.name ?? (0, import_throw._throw)(new Error("index name missing")));
81
82
  this.logger.warn(`creating indexes ${indexNames.join(", ")}`);
82
- await this.baseRepository.createIndexes(requiredIndexes);
83
+ await this.baseRepository.createIndexes(indexexToCreate);
83
84
  }
84
85
  }
85
86
  async load(id) {
@@ -286,9 +287,9 @@ class MongoEntityRepository extends import_database.EntityRepository {
286
287
  }
287
288
  }
288
289
  function normalizeIndex(index) {
289
- const { name: providedName, v, background, ns, ...indexRest } = index;
290
+ const { name: providedName, unique, v, background, ns, ...indexRest } = index;
290
291
  const name = providedName ?? (0, import_object.objectKeys)(index.key).join("_");
291
- return { name, ...indexRest };
292
+ return (0, import_object.filterUndefinedFromRecord)({ name, unique: unique == true ? true : void 0, ...indexRest });
292
293
  }
293
294
  function convertOptions(options, mappingMap) {
294
295
  if (options == void 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.84.30",
3
+ "version": "0.84.32",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -33,11 +33,11 @@
33
33
  "@types/mjml": "4.7",
34
34
  "@types/node": "20",
35
35
  "@types/nodemailer": "6.4",
36
- "@typescript-eslint/eslint-plugin": "5.59",
37
- "@typescript-eslint/parser": "5.59",
36
+ "@typescript-eslint/eslint-plugin": "5.60",
37
+ "@typescript-eslint/parser": "5.60",
38
38
  "concurrently": "8.2",
39
39
  "esbuild": "0.18",
40
- "eslint": "8.42",
40
+ "eslint": "8.43",
41
41
  "eslint-import-resolver-typescript": "3.5",
42
42
  "eslint-plugin-import": "2.27",
43
43
  "tsc-alias": "1.8",
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import * as repl from 'node:repl';
3
+ import type { Record } from '../types.js';
4
+ /**
5
+ * Starts an interactive (repl) session (node only)
6
+ * @param context context to set the repl context to
7
+ */
8
+ export declare function startRepl(options?: repl.ReplOptions & {
9
+ context?: Record<string>;
10
+ }): Promise<void>;
package/utils/repl.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var repl_exports = {};
30
+ __export(repl_exports, {
31
+ startRepl: () => startRepl
32
+ });
33
+ module.exports = __toCommonJS(repl_exports);
34
+ var repl = __toESM(require("node:repl"), 1);
35
+ var import_object = require("./object/object.js");
36
+ var import_type_guards = require("./type-guards.js");
37
+ async function startRepl(options) {
38
+ const replServer = repl.start(options);
39
+ if ((0, import_type_guards.isDefined)(options?.context)) {
40
+ for (const [key, value] of (0, import_object.objectEntries)(options.context)) {
41
+ replServer.context[key] = value;
42
+ }
43
+ }
44
+ await new Promise((resolve) => replServer.once("exit", resolve));
45
+ }