@e7w/easy-routes 0.1.0 → 0.1.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/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- export type { Ctx } from "./types";
2
- export { RouterSchema } from "./models/system";
1
+ export { Permission, PermissionSchema, type Ctx } from "./types";
3
2
  export { routes } from "./router";
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { RouterSchema } from "./models/system";
1
+ export { Permission, PermissionSchema } from "./types";
2
2
  export { routes } from "./router";
@@ -1,15 +1,7 @@
1
- import z from "zod";
2
- import type { Ctx, Meta } from "../types";
3
- interface RouterSchema {
4
- init(req: Ctx["req"], meta: Meta): void | Promise<void>;
5
- permission: number;
6
- defaultTitle?: string;
7
- }
8
- export declare const RouterSchema: z.ZodType<RouterSchema, RouterSchema>;
1
+ import { Permission, type Ctx } from "../types";
9
2
  export declare const system: {
10
- router?: RouterSchema;
11
- init(req: Ctx["req"], meta: Meta): Promise<void>;
3
+ router?: Permission;
4
+ init(req: Ctx["req"]): Promise<void>;
12
5
  hasPermission(permission?: number): boolean;
13
6
  getCtx(req: Ctx["req"], permission?: number): Ctx;
14
7
  };
15
- export {};
@@ -69,14 +69,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
69
69
  }
70
70
  };
71
71
  import { inject, loader, provide } from "@e7w/easy-model";
72
- import z from "zod";
73
- export var RouterSchema = z.object({
74
- init: z.function({
75
- output: z.union([z.promise(z.void()), z.void()]),
76
- }),
77
- permission: z.number(),
78
- defaultTitle: z.string().optional(),
79
- });
72
+ import { Permission, PermissionSchema } from "../types";
80
73
  export var system = provide((function () {
81
74
  var _a;
82
75
  var _b;
@@ -99,12 +92,12 @@ export var system = provide((function () {
99
92
  enumerable: false,
100
93
  configurable: true,
101
94
  writable: true,
102
- value: function (req, meta) {
95
+ value: function (req) {
103
96
  return __awaiter(this, void 0, void 0, function () {
104
97
  var _b;
105
98
  return __generator(this, function (_c) {
106
99
  switch (_c.label) {
107
- case 0: return [4 /*yield*/, ((_b = this.router) === null || _b === void 0 ? void 0 : _b.init(req, meta))];
100
+ case 0: return [4 /*yield*/, ((_b = this.router) === null || _b === void 0 ? void 0 : _b.init(req))];
108
101
  case 1:
109
102
  _c.sent();
110
103
  return [2 /*return*/];
@@ -142,7 +135,7 @@ export var system = provide((function () {
142
135
  }()),
143
136
  (function () {
144
137
  var _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
145
- _router_decorators = [inject(RouterSchema)];
138
+ _router_decorators = [inject(PermissionSchema)];
146
139
  _init_decorators = [(_b = loader).once.bind(_b), loader.load(true)];
147
140
  __esDecorate(_a, null, _init_decorators, { kind: "method", name: "init", static: false, private: false, access: { has: function (obj) { return "init" in obj; }, get: function (obj) { return obj.init; } }, metadata: _metadata }, null, _instanceExtraInitializers);
148
141
  __esDecorate(null, null, _router_decorators, { kind: "field", name: "router", static: false, private: false, access: { has: function (obj) { return "router" in obj; }, get: function (obj) { return obj.router; }, set: function (obj, value) { obj.router = value; } }, metadata: _metadata }, _router_initializers, _router_extraInitializers);
package/dist/router.js CHANGED
@@ -97,7 +97,7 @@ filePaths.forEach(function (filePath) {
97
97
  query: Object.fromEntries(url.searchParams),
98
98
  pathname: url.pathname.replace(/\/?$/, "/"),
99
99
  };
100
- return [4 /*yield*/, ((_d = (_c = system.init(req, meta)) === null || _c === void 0 ? void 0 : _c.catch) === null || _d === void 0 ? void 0 : _d.call(_c, function () { }))];
100
+ return [4 /*yield*/, ((_d = (_c = system.init(req)) === null || _c === void 0 ? void 0 : _c.catch) === null || _d === void 0 ? void 0 : _d.call(_c, function () { }))];
101
101
  case 1:
102
102
  _h.sent();
103
103
  ctx = system.getCtx(req, meta.permission);
@@ -1,4 +1,5 @@
1
1
  import type { Params } from "react-router";
2
+ import z from "zod";
2
3
  export interface Ctx {
3
4
  title: string;
4
5
  signed: boolean;
@@ -14,3 +15,9 @@ export type Meta = {
14
15
  permission?: number;
15
16
  loader?(ctx: Ctx): void | Promise<void>;
16
17
  } & Record<string, unknown>;
18
+ export declare abstract class Permission {
19
+ permission: number;
20
+ abstract defaultTitle: string;
21
+ abstract init(req: Ctx['req']): Promise<void> | void;
22
+ }
23
+ export declare const PermissionSchema: z.ZodType<Permission, Permission>;
@@ -1 +1,20 @@
1
- export {};
1
+ import z from "zod";
2
+ var Permission = /** @class */ (function () {
3
+ function Permission() {
4
+ Object.defineProperty(this, "permission", {
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true,
8
+ value: 0
9
+ });
10
+ }
11
+ return Permission;
12
+ }());
13
+ export { Permission };
14
+ export var PermissionSchema = z.object({
15
+ init: z.function({
16
+ output: z.union([z.promise(z.void()), z.void()]),
17
+ }),
18
+ permission: z.number(),
19
+ defaultTitle: z.string(),
20
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e7w/easy-routes",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org/"
@@ -10,6 +10,10 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "import": "./dist/index.js"
12
12
  },
13
+ "scripts": {
14
+ "build": "tsc --build && copyfiles -u 1 src/**/*.css dist/",
15
+ "lint": "eslint . --fix"
16
+ },
13
17
  "dependencies": {
14
18
  "@e7w/easy-model": "^0.2.1",
15
19
  "nprogress": "^0.2.0",
@@ -38,11 +42,8 @@
38
42
  "files": [
39
43
  "dist",
40
44
  "README.md",
41
- "LICENSE.md"
45
+ "LICENSE.md",
46
+ "tsconfig.json"
42
47
  ],
43
- "license": "MIT",
44
- "scripts": {
45
- "build": "tsc --build && copyfiles -u 1 src/**/*.css dist/",
46
- "lint": "eslint ."
47
- }
48
+ "license": "MIT"
48
49
  }
package/tsconfig.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
4
+ "target": "es5",
5
+ "useDefineForClassFields": true,
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "module": "ESNext",
8
+ "types": ["vite/client"],
9
+ "skipLibCheck": true,
10
+
11
+ /* Bundler mode */
12
+ "moduleResolution": "bundler",
13
+ "verbatimModuleSyntax": true,
14
+ "moduleDetection": "force",
15
+ "outDir": "dist",
16
+ "declaration": true,
17
+ "jsx": "react-jsx",
18
+
19
+ /* Linting */
20
+ "strict": true,
21
+ "noUnusedLocals": true,
22
+ "noUnusedParameters": true,
23
+ "erasableSyntaxOnly": true,
24
+ "noFallthroughCasesInSwitch": true,
25
+ "noUncheckedSideEffectImports": true
26
+ },
27
+ "include": ["src"]
28
+ }