cordo 2.11.1 → 2.12.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordo",
3
- "version": "2.11.1",
3
+ "version": "2.12.2",
4
4
  "description": "A framework for handling complex discord api interactions",
5
5
  "exports": {
6
6
  ".": "./src/index.ts",
package/src/core/hooks.ts CHANGED
@@ -44,7 +44,7 @@ export namespace Hooks {
44
44
  }
45
45
 
46
46
  export function isDefined(name: keyof CordoConfig['hooks']) {
47
- return !!CordoMagic.getConfig()?.hooks[name]
47
+ return !!CordoMagic.getConfig()?.hooks?.[name]
48
48
  }
49
49
 
50
50
  }
@@ -1,4 +1,5 @@
1
1
  import { MissingContextError } from "../../errors/builtin/missing-context"
2
+ import { FunctCompiler } from "../../functions/compiler"
2
3
  import { Hooks } from "../hooks"
3
4
  import type { CordoInteraction } from "../interaction"
4
5
  import { CordoMagic } from "../magic"
@@ -9,8 +10,10 @@ const DefaultFileName = 'index'
9
10
  export namespace RoutingResolve {
10
11
 
11
12
  function resolvePathDots(inputPath: string, startingPath: string) {
12
- if (!inputPath.startsWith('.')) return inputPath
13
- if (inputPath.startsWith('./')) return startingPath + inputPath.slice(1)
13
+ if (!inputPath.startsWith('.'))
14
+ return inputPath
15
+ if (inputPath.startsWith('./'))
16
+ return startingPath + inputPath.slice(1)
14
17
 
15
18
  const cwd = startingPath.split('/')
16
19
  if (cwd.at(-1) === DefaultFileName) cwd.pop()
@@ -75,7 +78,7 @@ export namespace RoutingResolve {
75
78
  const start = resolvePathDots(path, startingPoint)
76
79
  if (start === null) {
77
80
  console.log('Invalid route', path)
78
- return { routeId: '####', args: [] }
81
+ return { routeId: FunctCompiler.InvalidRoutePlaceholderId, args: [] }
79
82
  }
80
83
 
81
84
  const segments = start.split('/').filter(Boolean)
@@ -118,7 +121,7 @@ export namespace RoutingResolve {
118
121
 
119
122
  if (options.length === 0) {
120
123
  console.log('Could not find route', path, '(', path, ')')
121
- return { routeId: '####', args: [] }
124
+ return { routeId: FunctCompiler.InvalidRoutePlaceholderId, args: [] }
122
125
  }
123
126
 
124
127
  const maxSpecificity = Math.max(...options.map(o => o.specificity))
@@ -127,7 +130,7 @@ export namespace RoutingResolve {
127
130
  return {
128
131
  routeId: winner.route.name!,
129
132
  args: resolveRuntimeVars
130
- ? substituteRuntimeVariables(winner.args, invoker)
133
+ ? substituteRuntimeVariables(winner.args, invoker!)
131
134
  : winner.args,
132
135
  routeFilePath: winner.route.filePath
133
136
  }
@@ -1,7 +1,6 @@
1
1
  import { LockfileInternals } from "../core/files/lockfile"
2
2
  import { CordoMagic } from "../core/magic"
3
3
  import { RoutingResolve } from "../core/routing/resolve"
4
- import { MissingContextError } from "../errors/builtin/missing-context"
5
4
  import { LibIds } from "../lib/ids"
6
5
  import { LibUtils } from "../lib/utils"
7
6
  import { FunctInternals, type CordoFunct } from "./funct"
@@ -19,6 +18,8 @@ export namespace FunctCompiler {
19
18
  const LutArgumentIndicator = '\\'
20
19
  /** the following argument has the same value as an earlier argument */
21
20
  const ReferenceArgumentIndicator = '|'
21
+ /** placeholder route id for when the route could not be resolved */
22
+ export const InvalidRoutePlaceholderId = '#'.repeat(LockfileInternals.Const.idLength)
22
23
 
23
24
  //
24
25
 
@@ -39,9 +40,13 @@ export namespace FunctCompiler {
39
40
  const extraValues: string[] = []
40
41
 
41
42
  // encode cwd
42
- const { routeId, args } = RoutingResolve.getRouteFromPath(CordoMagic.getCwd(), false)
43
- command.push(routeId)
44
- argus.push(...args)
43
+ if (CordoMagic.getCwd()) {
44
+ const { routeId, args } = RoutingResolve.getRouteFromPath(CordoMagic.getCwd(), false)
45
+ command.push(routeId)
46
+ argus.push(...args)
47
+ } else {
48
+ command.push(InvalidRoutePlaceholderId)
49
+ }
45
50
 
46
51
  // encode functs
47
52
  for (const fun of list) {
@@ -61,7 +66,8 @@ export namespace FunctCompiler {
61
66
  // encode arguments
62
67
  const lut = CordoMagic.getLockfile()?.lut
63
68
  if (!lut)
64
- throw new MissingContextError('toCustomId failed, no lockfile found in context.')
69
+ console.warn('toCustomId called without a lockfile.')
70
+ // throw new MissingContextError('toCustomId failed, no lockfile found in context.')
65
71
 
66
72
  let argusStr = ''
67
73
  let counter = -1
@@ -76,7 +82,7 @@ export namespace FunctCompiler {
76
82
  }
77
83
 
78
84
  // check if this argument is part of the lut
79
- const lutIndex = lut.indexOf(arg)
85
+ const lutIndex = lut?.indexOf(arg) ?? -1
80
86
  if (lutIndex >= 0) {
81
87
  argusStr += LutArgumentIndicator + LibIds.stringify(lutIndex, LockfileInternals.Const.idLength)
82
88
  continue
@@ -181,8 +187,6 @@ export namespace FunctCompiler {
181
187
  }
182
188
 
183
189
  const cwdRoute = readNextRoute()
184
- if (!cwdRoute)
185
- return out
186
190
 
187
191
  out.cwd = cwdRoute
188
192
 
@@ -40,7 +40,7 @@ export function goto(
40
40
  ? FunctInternals.readFunct(path).path
41
41
  : path
42
42
 
43
- const flags = parseFlags(opts, FunctInternals.readFunct(path as any)?.flags ?? CordoMagic.getConfig()?.functDefaultFlags.gotoBits ?? 0)
43
+ const flags = parseFlags(opts, FunctInternals.readFunct(path as any)?.flags ?? CordoMagic.getConfig()?.functDefaultFlags?.gotoBits ?? 0)
44
44
 
45
45
  return FunctInternals.createFunct({
46
46
  type: 'goto',
@@ -57,7 +57,7 @@ export function run(
57
57
  ? FunctInternals.readFunct(path).path
58
58
  : path
59
59
 
60
- const flags = parseFlags(opts, FunctInternals.readFunct(path as any)?.flags ?? CordoMagic.getConfig()?.functDefaultFlags.runBits ?? 0)
60
+ const flags = parseFlags(opts, FunctInternals.readFunct(path as any)?.flags ?? CordoMagic.getConfig()?.functDefaultFlags?.runBits ?? 0)
61
61
 
62
62
  return FunctInternals.createFunct({
63
63
  type: 'run',
@@ -1,4 +1,4 @@
1
- import { expect, test } from "bun:test";
1
+ import { expect, test } from "bun:test"
2
2
  import { LibIds } from "./ids"
3
3
 
4
4
  test("1000 random numbers with parse single", () => {