Skip to content

Commit 76bb3ad

Browse files
committed
refactor: remove validateArgs function and clean up argument validation in modules
1 parent 9d69f6e commit 76bb3ad

File tree

14 files changed

+1
-284
lines changed

14 files changed

+1
-284
lines changed

src/modules/canvas.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
import { validateArgs } from "../validate/validate-args.js";
2-
31
export class CanvasModule {
42
static name = Object.freeze("canvas");
53

64
static async initialize(args) {
7-
validateArgs(args, {
8-
canvasElement: { type: "HTMLCanvasElement", required: true },
9-
workerSource: { type: "string", required: true }
10-
}, "CanvasModule.initialize: ");
11-
125
const { canvasElement, workerSource } = args;
136
const rect = canvasElement.getBoundingClientRect();
147
const width = Math.round(rect.width);

src/modules/component.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { validateArgs } from "../validate/validate-args.js";
2-
31
/**
42
* @class ComponentModule
53
* @description Helper class for working with web components.
@@ -26,11 +24,6 @@ class ComponentModule {
2624
* await api.call("component", "load_html", { url: import.meta.url });
2725
*/
2826
static async load_html(args) {
29-
validateArgs(args, {
30-
url: { type: "string", required: true },
31-
hasCss: { type: "boolean", required: false },
32-
}, "ComponentModule.load_html: ");
33-
3427
const { url, hasCss } = args;
3528
const htmlPath = url.replace(".js", ".html");
3629

@@ -47,11 +40,6 @@ class ComponentModule {
4740
}
4841

4942
static async load_component(args) {
50-
validateArgs(args, {
51-
element: { type: "HTMLElement", required: true },
52-
url: { type: "string", required: true },
53-
}, "ComponentModule.load_component: ");
54-
5543
const promise = new Promise((resolve) => {
5644
const { element, url } = args;
5745

@@ -79,10 +67,6 @@ class ComponentModule {
7967
* @returns {Promise<void>}
8068
*/
8169
static async ready(args){
82-
validateArgs(args, {
83-
element: { type: "HTMLElement", required: true },
84-
}, "ComponentModule.ready: ");
85-
8670
const { element } = args;
8771

8872
element.dataset.ready = "true";
@@ -106,11 +90,6 @@ class ComponentModule {
10690
* });
10791
*/
10892
static async on_ready(args) {
109-
validateArgs(args, {
110-
element: { type: "HTMLElement", required: true },
111-
callback: { type: "function", required: true },
112-
}, "ComponentModule.on_ready: ");
113-
11493
const { element, callback } = args;
11594

11695
if (element.dataset.ready === "true") {

src/modules/css-grid.js

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// deno-lint-ignore-file require-await
2-
import { validateArgs } from "../validate/validate-args.js";
32

43
export class CssGridModule {
54
static name = Object.freeze("css_grid");
@@ -13,11 +12,6 @@ export class CssGridModule {
1312
* @returns {Promise<void>}
1413
*/
1514
static async from(args) {
16-
validateArgs(args, {
17-
"columns": { type: "string", default: "1fr" },
18-
"rows": { type: "string", default: "1fr" },
19-
}, "CssGridModule.from: ");
20-
2115
return {
2216
columns: args.columns.split(" "),
2317
rows: args.rows.split(" "),
@@ -34,10 +28,6 @@ export class CssGridModule {
3428
* @returns {Promise<{columns: string, rows: string}>}
3529
*/
3630
static async to(args) {
37-
validateArgs(args, {
38-
"data": { type: "object", required: true },
39-
}, "CssGridModule.to: ");
40-
4131
return {
4232
columns: args.data.columns.join(" "),
4333
rows: args.data.rows.join(" "),
@@ -57,12 +47,6 @@ export class CssGridModule {
5747
* @returns {Promise<void>}
5848
*/
5949
static async apply(args) {
60-
validateArgs(args, {
61-
"data": { type: "object", required: true },
62-
"element": { type: "HTMLElement", required: true },
63-
}, "CssGridModule.to: ");
64-
65-
6650
const {data, element} = args;
6751
const css = await CssGridModule.to({ data });
6852

@@ -87,11 +71,6 @@ export class CssGridModule {
8771
static async create(args) {
8872
args = args ?? {};
8973

90-
validateArgs(args, {
91-
columnCount: { type: "number", default: 1 },
92-
rowCount: { type: "number", default: 1 },
93-
}, "CssGridModule.create: ");
94-
9574
const columns = new Array(args.columnCount).fill("1fr");
9675
const rows = new Array(args.rowCount).fill("1fr");
9776

@@ -111,12 +90,6 @@ export class CssGridModule {
11190
* @returns {Promise<*>}
11291
*/
11392
static async push(args) {
114-
validateArgs(args, {
115-
data: { type: "object", required: true },
116-
column: { type: "string" },
117-
row: { type: "string" },
118-
}, "CssGridModule.push: ");
119-
12093
if (args.column) {
12194
args.data.columns.push(args.column);
12295
}
@@ -138,10 +111,6 @@ export class CssGridModule {
138111
* @returns {Promise<string>}
139112
*/
140113
static async optimize(args) {
141-
validateArgs(args, {
142-
values: { type: "string", required: true },
143-
}, "CssGridModule.optimize: ");
144-
145114
const parts = args.values.split(" ");
146115
const optimized = [];
147116
let count = 1;
@@ -189,10 +158,6 @@ export class CssGridModule {
189158
* [A2][B2][C2]
190159
*/
191160
static async to_regions(args) {
192-
validateArgs(args, {
193-
"data": { type: "object", required: true },
194-
}, "CssGridModule.to_regions: ");
195-
196161
const result = [];
197162

198163
for (let i = 0; i < args.data.rows.length; i++) {
@@ -229,12 +194,6 @@ export class CssGridModule {
229194
* @return {Promise<*>}
230195
*/
231196
static async copy_region(args) {
232-
validateArgs(args, {
233-
"regions": { type: "Array", required: true },
234-
"start": { type: "object", required: true },
235-
"end": { type: "object", required: true },
236-
}, "CssGridModule.copyRegion: ");
237-
238197
const {regions, start, end} = args;
239198

240199
// Validate start and end points
@@ -276,12 +235,6 @@ export class CssGridModule {
276235
* @return {Promise<*>}
277236
*/
278237
static async reset_region(args) {
279-
validateArgs(args, {
280-
"regions": { type: "Array", required: true },
281-
"row": { type: "number", required: true },
282-
"column": { type: "number", required: true },
283-
}, "CssGridModule.copyRegion: ");
284-
285238
const {regions, row, column} = args;
286239

287240
const cellCode = regions[row][column];

src/modules/files.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import {validateArgs} from "../validate/validate-args.js";
2-
31
class FilesModule {
42
/**
53
* @property name
@@ -16,10 +14,6 @@ class FilesModule {
1614
* @returns {Promise<void>}
1715
*/
1816
static async load_files(args) {
19-
validateArgs(args, {
20-
ext: { type: "string", required: true },
21-
}, "FilesModule.load_files: ");
22-
2317
const { ext } = args;
2418

2519
const input = document.createElement("input");

src/modules/idle.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
import { validateArgs } from "./../validate/validate-args.js";
2-
31
export class IdleModule {
42
static name = Object.freeze("idle");
53

64
static perform(args) {
7-
validateArgs(args, {
8-
tasks: { type: "Array", required: true }
9-
}, "IdleModule.initialize: ");
10-
115
return globalThis.idleWorker.perform(args.tasks);
126
}
137
}

src/modules/markdown.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {validateArgs} from "../validate/validate-args.js";
21
import init, {markdown_to_html} from "./markdown/markdown.js";
32

43
await init();
@@ -7,10 +6,6 @@ export class MarkdownModule {
76
static name = Object.freeze("messaging");
87

98
static async to_html(args) {
10-
validateArgs(args, {
11-
markdown: {type: "string", required: true},
12-
}, "MarkdownModule.to_html: ");
13-
149
return markdown_to_html(args.markdown);
1510
}
1611
}

src/modules/messaging.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// deno-lint-ignore-file require-await
2-
import { validateArgs } from "../validate/validate-args.js";
3-
42
/**
53
* @class MessagingModule
64
* @description Messaging module provides the ability to send and receive messages
@@ -42,11 +40,6 @@ export class MessagingModule {
4240
* });
4341
*/
4442
static async subscribe(args) {
45-
validateArgs(args, {
46-
topic: { type: "string", required: true },
47-
callback: { type: "function", required: true },
48-
}, "MessagingModule.subscribe: ");
49-
5043
const { topic, callback } = args;
5144

5245
if (!this.subscribers[topic]) {
@@ -76,11 +69,6 @@ export class MessagingModule {
7669
* });
7770
*/
7871
static async unsubscribe(args) {
79-
validateArgs(args, {
80-
topic: { type: "string", required: true },
81-
callback: { type: "function", required: true },
82-
}, "MessagingModule.unsubscribe: ");
83-
8472
const { topic, callback } = args;
8573

8674
if (!this.subscribers[topic]) {
@@ -117,11 +105,6 @@ export class MessagingModule {
117105
* });
118106
*/
119107
static async publish(args) {
120-
validateArgs(args, {
121-
topic: { type: "string", required: true },
122-
message: { type: "object", required: true },
123-
}, "MessagingModule.publish: ");
124-
125108
const { topic, message } = args;
126109

127110
if (!this.subscribers[topic]) {

src/modules/quadtree.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import { validateArgs } from "../validate/validate-args.js";
21
import { QuadTree } from "./quadtree/quadtree.js";
32

43
export class QuadTreeModule {
54
static name = Object.freeze("canvas");
65

76
static async initialize(args) {
8-
validateArgs(args, {
9-
width : {type: "Number", required: true},
10-
height : {type: "Number", required: true},
11-
capacity: {type: "Number", required: false}
12-
}, "QuadTreeModule.initialize: ");
13-
147
const { width, height, capacity } = args;
158

169
return new QuadTree({ x: 0, y: 0, width, height }, capacity ?? 8);

src/modules/router.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
// deno-lint-ignore-file require-await
2-
3-
import { validateArgs } from "../validate/validate-args.js";
4-
52
const DEFAULT_ROUTE = "home";
63

74
/**
@@ -58,10 +55,6 @@ class RouterModule {
5855
* await api.call("router", "init", { routes });
5956
*/
6057
static async init(args) {
61-
validateArgs(args, {
62-
routes: { type: "object", required: true },
63-
}, "RouterModule.init: ");
64-
6558
this.routes = args.routes;
6659

6760
this.routeUpdateHandler = routeUpdated.bind(args.api);
@@ -112,11 +105,6 @@ class RouterModule {
112105
* const route = await crs.call("router", "getRoute", { route: "person", params: { id: 1 } });
113106
*/
114107
static async get(args) {
115-
validateArgs(args, {
116-
route: { type: "string", default: "home" },
117-
params: { type: "object", default: {} },
118-
}, "RouterModule.getRoute: ");
119-
120108
const { route, params } = args;
121109

122110
if (this.routes && this.routes[route]) {
@@ -135,14 +123,9 @@ class RouterModule {
135123
* @returns {Promise<void>}
136124
*/
137125
static async goto(args) {
138-
validateArgs(args, {
139-
route: { type: "string", required: true },
140-
params: { type: "object", default: {} },
141-
}, "RouterModule.goto: ");
142-
143126
const { route, params } = args;
144-
145127
const path = await this.get({ route, params });
128+
146129
history.pushState({}, "", path);
147130

148131
args.api.try("messaging", "publish", {

src/modules/surrealdb.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// https://surrealdb.com/docs/surrealdb/integration/http#accessing-endpoints-via-postman
22
import Surreal from "./surreal/cdn.js";
3-
import { validateArgs } from "../validate/validate-args.js";
4-
53
const DEFAULT_SERVER = "http://localhost:8000";
64

75
/**
@@ -31,14 +29,6 @@ class SurrealDBModule {
3129
* @returns {Promise<void>}
3230
*/
3331
static async connect(args) {
34-
validateArgs(args, {
35-
username: { type: "string", required: true },
36-
password: { type: "string", required: true },
37-
url: { type: "string", required: false, default: DEFAULT_SERVER },
38-
namespace: { type: "string", required: false },
39-
database: { type: "string", required: false },
40-
}, "SurrealDBModule.connect: ");
41-
4232
if (this.db != null) {
4333
await this.disconnect();
4434
}
@@ -91,10 +81,6 @@ class SurrealDBModule {
9181
);
9282
}
9383

94-
validateArgs(args, {
95-
namespace: { type: "string", required: true },
96-
}, "SurrealDBModule.create_namespace: ");
97-
9884
await this.db.query(`
9985
DEFINE NAMESPACE IF NOT EXISTS ${args.namespace};
10086
`);
@@ -115,11 +101,6 @@ class SurrealDBModule {
115101
);
116102
}
117103

118-
validateArgs(args, {
119-
namespace: { type: "string", required: true },
120-
database: { type: "string", required: true },
121-
}, "SurrealDBModule.create_database: ");
122-
123104
await this.db.query(`
124105
USE NS ${args.namespace};
125106
DEFINE DATABASE IF NOT EXISTS ${args.database};
@@ -170,11 +151,6 @@ class SurrealDBModule {
170151
throw new Error("SurrealDBModule.signin: Database not connected");
171152
}
172153

173-
validateArgs(args, {
174-
username: { type: "string", required: true },
175-
password: { type: "string", required: true },
176-
}, "SurrealDBModule.signin: ");
177-
178154
return await this.db.signin(args);
179155
}
180156
}

0 commit comments

Comments
 (0)