@mostfeatured/dbi 0.0.63 → 0.0.64

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.
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseCustomId = exports.customIdBuilder = void 0;
3
+ exports.parseCustomId = exports.buildCustomId = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const stuffs = tslib_1.__importStar(require("stuffs"));
6
- function customIdBuilder(dbi, name, customData, ttl) {
6
+ function buildCustomId(dbi, name, data, ttl) {
7
7
  let customId = [
8
8
  name,
9
- ...customData.map(value => {
9
+ ...data.map(value => {
10
10
  if (typeof value == "string")
11
11
  return value;
12
12
  if (typeof value == "number")
13
13
  return `π${value}`;
14
+ if (typeof value == "boolean")
15
+ return `𝞫${value ? 1 : 0}`;
14
16
  let id = stuffs.randomString(8);
15
17
  Object.assign(value, {
16
18
  $ref: id,
@@ -26,13 +28,15 @@ function customIdBuilder(dbi, name, customData, ttl) {
26
28
  throw new Error("Custom id cannot be longer than 100 characters.");
27
29
  return customId;
28
30
  }
29
- exports.customIdBuilder = customIdBuilder;
31
+ exports.buildCustomId = buildCustomId;
30
32
  function parseCustomId(dbi, customId) {
31
33
  let splitted = customId.split("—");
32
34
  let name = splitted.shift();
33
35
  let data = splitted.map(value => {
34
36
  if (value.startsWith("π"))
35
37
  return Number(value.slice(1));
38
+ if (value.startsWith("𝞫"))
39
+ return !!Number(value.slice(1));
36
40
  if (value.startsWith("¤"))
37
41
  return dbi.data.refs.get(value.slice(1))?.value;
38
42
  return value;
@@ -1 +1 @@
1
- {"version":3,"file":"customId.js","sourceRoot":"","sources":["../../src/utils/customId.ts"],"names":[],"mappings":";;;;AACA,uDAAiC;AAGjC,SAAgB,eAAe,CAAC,GAAwB,EAAE,IAAY,EAAE,UAAiB,EAAE,GAAW;IACpG,IAAI,QAAQ,GAAG;QACb,IAAI;QACJ,GAAG,UAAU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;YAAE,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACzD,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;QAC3E,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IACH,OAAO;QACL,IAAI;QACJ,IAAI;KACL,CAAA;AACH,CAAC;AAZD,sCAYC","sourcesContent":["import { DBI } from \"../DBI\";\r\nimport * as stuffs from \"stuffs\";\r\nimport { NamespaceEnums } from \"../../generated/namespaceData\";\r\n\r\nexport function customIdBuilder(dbi: DBI<NamespaceEnums>, name: string, customData: any[], ttl?:number): string {\r\n let customId = [\r\n name,\r\n ...customData.map(value => {\r\n if (typeof value == \"string\") return value;\r\n if (typeof value == \"number\") return `π${value}`;\r\n let id = stuffs.randomString(8);\r\n Object.assign(value, {\r\n $ref: id,\r\n $unRef() { return dbi.data.refs.delete(id); },\r\n })\r\n dbi.data.refs.set(id, { at: Date.now(), value, ttl });\r\n return `¤${id}`;\r\n })\r\n ].join(\"—\");\r\n if (!dbi.config.strict) customId = customId.slice(0, 100);\r\n if (customId.length > 100) throw new Error(\"Custom id cannot be longer than 100 characters.\")\r\n return customId;\r\n}\r\n\r\nexport function parseCustomId(dbi: DBI<NamespaceEnums>, customId: string): {name: string, data: any[]} {\r\n let splitted = customId.split(\"—\");\r\n let name = splitted.shift();\r\n let data = splitted.map(value => {\r\n if (value.startsWith(\"π\")) return Number(value.slice(1));\r\n if (value.startsWith(\"¤\")) return dbi.data.refs.get(value.slice(1))?.value;\r\n return value;\r\n });\r\n return {\r\n name,\r\n data\r\n }\r\n}"]}
1
+ {"version":3,"file":"customId.js","sourceRoot":"","sources":["../../src/utils/customId.ts"],"names":[],"mappings":";;;;AACA,uDAAiC;AAGjC,SAAgB,aAA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QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnC,IAAI,IAAI,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC5B,IAAI,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QAC9B,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACzD,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5D,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;QAC3E,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IACH,OAAO;QACL,IAAI;QACJ,IAAI;KACL,CAAA;AACH,CAAC;AAbD,sCAaC","sourcesContent":["import { DBI } from \"../DBI\";\r\nimport * as stuffs from \"stuffs\";\r\nimport { NamespaceEnums } from \"../../generated/namespaceData\";\r\n\r\nexport function buildCustomId(dbi: DBI<NamespaceEnums>, name: string, data: any[], ttl?:number): string {\r\n let customId = [\r\n name,\r\n ...data.map(value => {\r\n if (typeof value == \"string\") return value;\r\n if (typeof value == \"number\") return `π${value}`;\r\n if (typeof value == \"boolean\") return `𝞫${value ? 1 : 0}`;\r\n let id = stuffs.randomString(8);\r\n Object.assign(value, {\r\n $ref: id,\r\n $unRef() { return dbi.data.refs.delete(id); },\r\n })\r\n dbi.data.refs.set(id, { at: Date.now(), value, ttl });\r\n return `¤${id}`;\r\n })\r\n ].join(\"—\");\r\n if (!dbi.config.strict) customId = customId.slice(0, 100);\r\n if (customId.length > 100) throw new Error(\"Custom id cannot be longer than 100 characters.\")\r\n return customId;\r\n}\r\n\r\nexport function parseCustomId(dbi: DBI<NamespaceEnums>, customId: string): {name: string, data: any[]} {\r\n let splitted = customId.split(\"—\");\r\n let name = splitted.shift();\r\n let data = splitted.map(value => {\r\n if (value.startsWith(\"π\")) return Number(value.slice(1));\r\n if (value.startsWith(\"𝞫\")) return !!Number(value.slice(1));\r\n if (value.startsWith(\"¤\")) return dbi.data.refs.get(value.slice(1))?.value;\r\n return value;\r\n });\r\n return {\r\n name,\r\n data\r\n }\r\n}"]}
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "stuffs": "^0.1.21"
10
10
  },
11
11
  "name": "@mostfeatured/dbi",
12
- "version": "0.0.63",
12
+ "version": "0.0.64",
13
13
  "main": "dist/index.js",
14
14
  "type": "commonjs",
15
15
  "private": false,
package/src/index.ts CHANGED
@@ -4,8 +4,15 @@ export { recursiveImport } from "./utils/recursiveImport";
4
4
  export { MemoryStore } from "./utils/MemoryStore";
5
5
 
6
6
  import path from "path";
7
+ import { parseCustomId, buildCustomId } from "./utils/customId";
8
+
7
9
  export const generatedPath = path.resolve(__dirname, "../generated");
8
10
 
9
11
  export function createDBI<TNamespace extends NamespaceEnums, TOtherType = Record<string, any>>(namespace: TNamespace, cfg: DBIConfigConstructor): DBI<TNamespace, TOtherType> {
10
12
  return new DBI<TNamespace, TOtherType>(namespace, cfg);
11
- };
13
+ };
14
+
15
+ export const Utils = {
16
+ parseCustomId,
17
+ buildCustomId
18
+ }
@@ -1,7 +1,7 @@
1
1
  import Discord from "discord.js";
2
2
  import { DBI } from "../DBI";
3
3
  import { DBIBaseInteraction, IDBIBaseExecuteCtx, TDBIReferencedData } from "./Interaction";
4
- import { customIdBuilder } from "../utils/customId";
4
+ import { buildCustomId } from "../utils/customId";
5
5
  import { IDBIToJSONArgs } from "../utils/UtilTypes";
6
6
  import { NamespaceEnums } from "../../generated/namespaceData";
7
7
  import stuffs from "stuffs";
@@ -28,7 +28,7 @@ export class DBIButton<TNamespace extends NamespaceEnums> extends DBIBaseInterac
28
28
  toJSON(arg: IDBIToJSONArgs<DBIButtonOverrides> = {}): Discord.ButtonComponentData {
29
29
  return {
30
30
  ...stuffs.defaultify((arg?.overrides || {}), this.options || {}, true),
31
- customId: customIdBuilder(this.dbi as any, this.name, arg?.reference?.data || [], arg?.reference?.ttl),
31
+ customId: buildCustomId(this.dbi as any, this.name, arg?.reference?.data || [], arg?.reference?.ttl),
32
32
  type: Discord.ComponentType.Button,
33
33
  } as any;
34
34
  };
@@ -1,7 +1,7 @@
1
1
  import { DBI } from "../DBI";
2
2
  import { DBIBaseInteraction, IDBIBaseExecuteCtx, TDBIReferencedData } from "./Interaction";
3
3
  import Discord from "discord.js";
4
- import { customIdBuilder } from "../utils/customId";
4
+ import { buildCustomId } from "../utils/customId";
5
5
  import { IDBIToJSONArgs } from "../utils/UtilTypes";
6
6
  import { NamespaceEnums } from "../../generated/namespaceData";
7
7
  import stuffs from "stuffs";
@@ -36,7 +36,7 @@ export class DBIModal<TNamespace extends NamespaceEnums> extends DBIBaseInteract
36
36
  toJSON(arg: IDBIToJSONArgs<DBIModalOverrides> = {}): Discord.ModalComponentData {
37
37
  return {
38
38
  ...stuffs.defaultify((arg?.overrides || {}), this.options || {}, true),
39
- customId: customIdBuilder(this.dbi as any, this.name, arg?.reference?.data || [], arg?.reference?.ttl)
39
+ customId: buildCustomId(this.dbi as any, this.name, arg?.reference?.data || [], arg?.reference?.ttl)
40
40
  } as any;
41
41
  };
42
42
 
@@ -1,7 +1,7 @@
1
1
  import Discord from "discord.js";
2
2
  import { DBI } from "../DBI";
3
3
  import { DBIBaseInteraction, IDBIBaseExecuteCtx, TDBIReferencedData } from "./Interaction";
4
- import { customIdBuilder } from "../utils/customId";
4
+ import { buildCustomId } from "../utils/customId";
5
5
  import { IDBIToJSONArgs } from "../utils/UtilTypes";
6
6
  import { NamespaceEnums } from "../../generated/namespaceData";
7
7
  import stuffs from "stuffs";
@@ -30,7 +30,7 @@ export class DBISelectMenu<TNamespace extends NamespaceEnums> extends DBIBaseInt
30
30
  toJSON(arg: IDBIToJSONArgs<DBISelectMenuOverrides> = {}): Discord.BaseSelectMenuComponentData {
31
31
  return {
32
32
  ...stuffs.defaultify((arg?.overrides || {}), this.options || {}, true),
33
- customId: customIdBuilder(this.dbi as any, this.name, arg?.reference?.data || [], arg?.reference?.ttl),
33
+ customId: buildCustomId(this.dbi as any, this.name, arg?.reference?.data || [], arg?.reference?.ttl),
34
34
  type: Discord.ComponentType.SelectMenu,
35
35
  } as any;
36
36
  };
@@ -2,12 +2,13 @@ import { DBI } from "../DBI";
2
2
  import * as stuffs from "stuffs";
3
3
  import { NamespaceEnums } from "../../generated/namespaceData";
4
4
 
5
- export function customIdBuilder(dbi: DBI<NamespaceEnums>, name: string, customData: any[], ttl?:number): string {
5
+ export function buildCustomId(dbi: DBI<NamespaceEnums>, name: string, data: any[], ttl?:number): string {
6
6
  let customId = [
7
7
  name,
8
- ...customData.map(value => {
8
+ ...data.map(value => {
9
9
  if (typeof value == "string") return value;
10
10
  if (typeof value == "number") return `π${value}`;
11
+ if (typeof value == "boolean") return `𝞫${value ? 1 : 0}`;
11
12
  let id = stuffs.randomString(8);
12
13
  Object.assign(value, {
13
14
  $ref: id,
@@ -27,6 +28,7 @@ export function parseCustomId(dbi: DBI<NamespaceEnums>, customId: string): {name
27
28
  let name = splitted.shift();
28
29
  let data = splitted.map(value => {
29
30
  if (value.startsWith("π")) return Number(value.slice(1));
31
+ if (value.startsWith("𝞫")) return !!Number(value.slice(1));
30
32
  if (value.startsWith("¤")) return dbi.data.refs.get(value.slice(1))?.value;
31
33
  return value;
32
34
  });