@vyckr/tachyon 0.1.0 → 0.2.0

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/Dockerfile CHANGED
@@ -16,28 +16,32 @@ RUN unzip bun-lambda-layer.zip -d /tmp
16
16
 
17
17
  WORKDIR /tmp
18
18
 
19
- COPY ./src/Tach.ts .
20
-
21
19
  COPY package.json .
22
20
 
23
21
  RUN bun install
24
22
 
25
- RUN bun build --target=bun Tach.ts --outfile lambda
26
-
27
23
  FROM public.ecr.aws/lambda/provided:al2
28
24
 
29
- COPY --from=build /tmp/lambda ${LAMBDA_TASK_ROOT}
25
+ COPY --from=build /tmp/node_modules ${LAMBDA_TASK_ROOT}/node_modules
26
+
27
+ COPY --from=build /tmp/package.json ${LAMBDA_TASK_ROOT}/package.json
30
28
 
31
29
  COPY --from=build /tmp/bootstrap ${LAMBDA_RUNTIME_DIR}
32
30
 
33
31
  COPY --from=build /tmp/bun /opt
34
32
 
33
+ COPY ./src/Tach.ts ${LAMBDA_TASK_ROOT}
34
+
35
+ COPY ./tsconfig.json ${LAMBDA_TASK_ROOT}
36
+
35
37
  COPY ./src/runtime.ts /opt
36
38
 
37
39
  RUN chmod 777 /opt/bun
38
40
 
39
- RUN chmod 777 ${LAMBDA_TASK_ROOT}/lambda
41
+ RUN chmod 777 /opt/runtime.ts
42
+
43
+ RUN chmod 777 ${LAMBDA_TASK_ROOT}/Tach.ts
40
44
 
41
45
  RUN chmod 777 ${LAMBDA_RUNTIME_DIR}/bootstrap
42
46
 
43
- CMD ["lambda.fetch"]
47
+ CMD ["Tach.fetch"]
package/README.md CHANGED
@@ -60,12 +60,12 @@ Make sure you have set the 'SCHEMA_PATH' if 'SCHEMA' is set to 'STRICT'. The sch
60
60
  ### Requirements
61
61
  - Make sure to have a 'routes' directory in the root of your project
62
62
  - Dynamic routes should be enclosed in square brackets
63
- - The first parameter should NOT be a dynamic route (e.g. /[version]/doc.ts)
64
- - All dynamic routes should be within odd indexes (e.g. /v1/[path]/login/[id]/name.ts)
65
- - The last parameter in the route should not be a dynamic route (e.g. /v1/[path]/login/[id]/name.ts)
63
+ - The first parameter should NOT be a dynamic route (e.g. /[version]/doc/index.ts)
64
+ - All dynamic routes should be within odd indexes (e.g. /v1/[path]/login/[id]/name/index.ts)
65
+ - The last parameter in the route should not be a dynamic route (e.g. /v1/[path]/login/[id]/name/index.ts)
66
66
 
67
67
  ```typescript
68
- // routes/v1/[collection]/doc.ts
68
+ // routes/v1/[collection]/doc/index.ts
69
69
  import Silo from "@vyckr/byos"
70
70
  imoprt { VALIDATE } from "../utils/decorators"
71
71
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vyckr/tachyon",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "devDependencies": {
5
5
  "@types/node": "^20.4.2",
6
6
  "bun-types": "^1.1.21"
@@ -1,4 +1,4 @@
1
- import { VALIDATE } from "../../_utils/validation.js";
1
+ import { VALIDATE } from "../../../utils/validation.js";
2
2
 
3
3
  export default class Doc {
4
4
 
@@ -1,4 +1,4 @@
1
- import { VALIDATE } from "../../_utils/validation.js";
1
+ import { VALIDATE } from "../../../utils/validation.js";
2
2
 
3
3
  export default class Docs {
4
4
 
@@ -1,4 +1,4 @@
1
- import { VALIDATE } from "../../../../_utils/validation.js";
1
+ import { VALIDATE } from "../../../../../utils/validation.js";
2
2
 
3
3
  export default class Docs {
4
4
 
@@ -1,4 +1,4 @@
1
- import { VALIDATE } from "../../../_utils/validation.js";
1
+ import { VALIDATE } from "../../../../utils/validation.js";
2
2
 
3
3
  export default class {
4
4
 
@@ -1,4 +1,4 @@
1
- import { VALIDATE } from "../../../_utils/validation.js";
1
+ import { VALIDATE } from "../../../../utils/validation.js";
2
2
 
3
3
  export default class {
4
4
 
package/src/Tach.ts CHANGED
@@ -39,7 +39,7 @@ const Tach = {
39
39
 
40
40
  routesPath: process.env.LAMBDA_TASK_ROOT ? `${process.env.LAMBDA_TASK_ROOT}/routes` : `${process.cwd()}/routes`,
41
41
 
42
- hasMiddleware: await exists(`${process.env.LAMBDA_TASK_ROOT || process.cwd()}/routes/_middleware.ts`) || await exists(`${process.env.LAMBDA_TASK_ROOT || process.cwd()}/routes/_middleware.js`) ,
42
+ hasMiddleware: await exists(`${process.env.LAMBDA_TASK_ROOT || process.cwd()}/routes/middleware.ts`) || await exists(`${process.env.LAMBDA_TASK_ROOT || process.cwd()}/routes/middleware.js`) ,
43
43
 
44
44
  pathsMatch(routeSegs: string[], pathSegs: string[]) {
45
45
 
@@ -47,10 +47,10 @@ const Tach = {
47
47
  return false;
48
48
  }
49
49
 
50
- const slugs = Tach.routeSlugs.get(`${routeSegs.join('/')}.ts`) || Tach.routeSlugs.get(`${routeSegs.join('/')}.js`) || new Map<string, number>()
50
+ const slugs = Tach.routeSlugs.get(`${routeSegs.join('/')}/index.ts`) || Tach.routeSlugs.get(`${routeSegs.join('/')}/index.js`) || new Map<string, number>()
51
51
 
52
52
  for (let i = 0; i < routeSegs.length; i++) {
53
- if (!slugs.has(routeSegs[i]) && routeSegs[i].replace('.ts', '').replace('.js', '') !== pathSegs[i]) {
53
+ if (!slugs.has(routeSegs[i]) && routeSegs[i] !== pathSegs[i]) {
54
54
  return false;
55
55
  }
56
56
  }
@@ -73,7 +73,11 @@ const Tach = {
73
73
  let bestMatchLength = -1;
74
74
 
75
75
  for (const [routeKey] of Tach.indexedRoutes) {
76
- const routeSegs = routeKey.split('/').map(seg => seg.replace('.ts', '').replace('.js', ''));
76
+
77
+ const routeSegs = routeKey.split('/')
78
+
79
+ routeSegs.pop()
80
+
77
81
  const isMatch = Tach.pathsMatch(routeSegs, paths.slice(0, routeSegs.length));
78
82
 
79
83
  if (isMatch && routeSegs.length > bestMatchLength) {
@@ -230,7 +234,7 @@ const Tach = {
230
234
 
231
235
  if(searchParams.size > 0) queryParams = Tach.parseKVParams(searchParams)
232
236
 
233
- const middlewarePath = await exists(`${Tach.routesPath}/_middleware.ts`) ? `${Tach.routesPath}/_middleware.ts` : `${Tach.routesPath}/_middleware.js`
237
+ const middlewarePath = await exists(`${Tach.routesPath}/middleware.ts`) ? `${Tach.routesPath}/middleware.ts` : `${Tach.routesPath}/middleware.js`
234
238
 
235
239
  if(params.length > 0 && !queryParams && !data) {
236
240
 
@@ -480,19 +484,17 @@ const Tach = {
480
484
 
481
485
  const slugs = new Map<string, number>()
482
486
 
487
+ if(pattern.test(paths[0]) || pattern.test(paths[paths.length - 1])) throw new Error(`Invalid route ${route}`)
488
+
483
489
  paths.forEach((path, idx) => {
484
490
 
485
- if(pattern.test(path) && (idx % 2 === 0 || paths[idx].includes('.ts') || paths[idx].includes('.js'))) {
491
+ if(pattern.test(path) && (pattern.test(paths[idx - 1]) || pattern.test(paths[idx + 1]))) {
486
492
  throw new Error(`Invalid route ${route}`)
487
493
  }
488
494
 
489
495
  if(pattern.test(path)) slugs.set(path, idx)
490
496
  })
491
497
 
492
- const idx = paths.findIndex((path) => pattern.test(path))
493
-
494
- if(idx > -1 && (idx % 2 === 0 || paths[idx].includes('.ts') || paths[idx].includes('.js'))) throw new Error(`Invalid route ${route}`)
495
-
496
498
  const staticPath = paths.filter((path) => !pattern.test(path)).join(',')
497
499
 
498
500
  if(staticPaths.includes(staticPath)) throw new Error(`Duplicate route ${route}`)
@@ -520,10 +522,8 @@ const Tach = {
520
522
 
521
523
  if(route) return await validateRoute(route)
522
524
 
523
- const files = Array.from(new Glob(`**/*.{ts,js}`).scanSync({ cwd: Tach.routesPath }))
524
-
525
- const routes = files.filter((route) => !route.split('/').some((path) => path.startsWith('_')))
526
-
525
+ const routes = Array.from(new Glob(`**/*/index.{ts,js}`).scanSync({ cwd: Tach.routesPath }))
526
+
527
527
  for(const route of routes) await validateRoute(route)
528
528
  },
529
529
 
File without changes