Skip to content

Commit 848d78f

Browse files
remove endpoint, namespace spec
1 parent e052f41 commit 848d78f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+36
-360
lines changed

examples/example.urlspec

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
// Job listing and detail pages
2-
// This namespace contains all job-related URL specifications
3-
namespace "jobs";
4-
51
// Sort order for job listings
62
// Used to determine how jobs are displayed
7-
param sort_order = "recent" | "popular" | "trending";
3+
param sortOrder = "recent" | "popular" | "trending";
84

95
// Status of a job posting
10-
param job_status = "active" | "closed" | "draft";
6+
param jobStatus = "active" | "closed" | "draft";
117

128
global {
139
// Referrer source
@@ -25,7 +21,7 @@ page list = /jobs {
2521
category?: string;
2622

2723
// Sort order
28-
sort: sort_order;
24+
sort: sortOrder;
2925
}
3026

3127
// Job detail page
@@ -38,5 +34,5 @@ page detail = /jobs/:job_id {
3834
preview?: "true" | "false";
3935

4036
// Job status filter
41-
status?: job_status;
37+
status?: jobStatus;
4238
}

packages/builder/src/index.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import { writeFileSync } from "node:fs";
66
import { normalize, resolve } from "node:path";
77
import {
8-
createEndpoint,
98
createGlobalBlock,
109
createPageDeclaration,
1110
createParameterDeclaration,
@@ -27,7 +26,6 @@ import {
2726
// Re-export AST types
2827
export type {
2928
GlobalBlock,
30-
NamespaceDeclaration,
3129
PageDeclaration,
3230
ParameterDeclaration,
3331
ParamTypeDeclaration,
@@ -42,9 +40,7 @@ export type {
4240
} from "@urlspec/language";
4341
// Re-export AST builder functions for convenience
4442
export {
45-
createEndpoint,
4643
createGlobalBlock,
47-
createNamespace,
4844
createPageDeclaration,
4945
createParameterDeclaration,
5046
createParamTypeDeclaration,
@@ -75,26 +71,10 @@ export interface PageDefinition {
7571
* URLSpec builder class for programmatic generation of .urlspec files
7672
*/
7773
export class URLSpec {
78-
private namespace?: string;
79-
private endpoint?: string;
8074
private paramTypes: Map<string, ParamType> = new Map();
8175
private globalParams: ParameterDefinition[] = [];
8276
private pages: PageDefinition[] = [];
8377

84-
/**
85-
* Set the namespace for the URLSpec
86-
*/
87-
setNamespace(name: string): void {
88-
this.namespace = name;
89-
}
90-
91-
/**
92-
* Set the endpoint for the URLSpec
93-
*/
94-
setEndpoint(url: string): void {
95-
this.endpoint = url;
96-
}
97-
9878
/**
9979
* Add a parameter type definition
10080
*/
@@ -120,10 +100,6 @@ export class URLSpec {
120100
* Build the URLSpec AST document
121101
*/
122102
toAST(): URLSpecDocument {
123-
if (!this.namespace) {
124-
throw new Error("Namespace is required");
125-
}
126-
127103
// Build param types
128104
const paramTypes: ParamTypeDeclaration[] = [];
129105
for (const [name, type] of this.paramTypes.entries()) {
@@ -149,8 +125,6 @@ export class URLSpec {
149125
);
150126

151127
return createURLSpecDocument({
152-
namespace: this.namespace,
153-
endpoint: this.endpoint,
154128
paramTypes,
155129
global,
156130
pages,

packages/builder/test/builder.test.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ describe("URLSpec Builder", () => {
55
it("should build basic spec", () => {
66
const spec = new URLSpec();
77

8-
spec.setNamespace("jobs");
98
spec.addPage({
109
name: "list",
1110
path: "/jobs",
@@ -14,15 +13,13 @@ describe("URLSpec Builder", () => {
1413

1514
const result = spec.toString();
1615

17-
expect(result).toContain("namespace jobs;");
1816
expect(result).toContain("page list = /jobs {");
1917
expect(result).toContain("category?: string;");
2018
});
2119

2220
it("should build with param types", () => {
2321
const spec = new URLSpec();
2422

25-
spec.setNamespace("jobs");
2623
spec.addParamType("sortOrder", ["recent", "popular", "trending"]);
2724
spec.addPage({
2825
name: "list",
@@ -41,7 +38,6 @@ describe("URLSpec Builder", () => {
4138
it("should build with global parameters", () => {
4239
const spec = new URLSpec();
4340

44-
spec.setNamespace("jobs");
4541
spec.addGlobalParam({
4642
name: "utm_source",
4743
type: "string",
@@ -58,29 +54,24 @@ describe("URLSpec Builder", () => {
5854
expect(result).toContain("utm_source?: string;");
5955
});
6056

61-
it("should build with endpoint", () => {
57+
it("should build without namespace and endpoint", () => {
6258
const spec = new URLSpec();
6359

64-
spec.setNamespace("jobs");
65-
spec.setEndpoint("https://api.example.com");
6660
spec.addPage({
6761
name: "list",
6862
path: "/jobs",
6963
});
7064

7165
const result = spec.toString();
7266

73-
expect(result).toContain("namespace jobs;");
74-
expect(result).toContain('endpoint "https://api.example.com";');
67+
expect(result).not.toContain("namespace");
68+
expect(result).not.toContain("endpoint");
7569
expect(result).toContain("page list = /jobs {");
7670
});
7771

7872
it("should build complete example", () => {
7973
const spec = new URLSpec();
8074

81-
spec.setNamespace("jobs");
82-
spec.setEndpoint("https://api.example.com");
83-
8475
spec.addParamType("sortOrder", ["recent", "popular", "trending"]);
8576
spec.addParamType("jobStatus", ["active", "closed", "draft"]);
8677

@@ -111,8 +102,6 @@ describe("URLSpec Builder", () => {
111102

112103
const result = spec.toString();
113104

114-
expect(result).toContain("namespace jobs;");
115-
expect(result).toContain('endpoint "https://api.example.com";');
116105
expect(result).toContain("param sortOrder");
117106
expect(result).toContain("param jobStatus");
118107
expect(result).toContain("global {");
@@ -123,8 +112,6 @@ describe("URLSpec Builder", () => {
123112
it("should support dynamic page generation", () => {
124113
const spec = new URLSpec();
125114

126-
spec.setNamespace("jobs");
127-
128115
const statuses = ["pending", "approved", "rejected"];
129116
for (const status of statuses) {
130117
spec.addPage({
@@ -144,7 +131,6 @@ describe("URLSpec Builder", () => {
144131
describe("Security - Path Traversal Prevention", () => {
145132
it("should reject paths with .. traversal sequences", async () => {
146133
const spec = new URLSpec();
147-
spec.setNamespace("test");
148134

149135
await expect(spec.writeFile("../../../etc/passwd")).rejects.toThrow(
150136
"path traversal detected",
@@ -153,7 +139,6 @@ describe("URLSpec Builder", () => {
153139

154140
it("should reject paths to sensitive system directories", async () => {
155141
const spec = new URLSpec();
156-
spec.setNamespace("test");
157142

158143
await expect(spec.writeFile("/etc/hosts")).rejects.toThrow(
159144
"cannot write to sensitive directory",
@@ -174,7 +159,6 @@ describe("URLSpec Builder", () => {
174159

175160
it("should reject paths outside allowed base directory", async () => {
176161
const spec = new URLSpec();
177-
spec.setNamespace("test");
178162

179163
await expect(
180164
spec.writeFile("/tmp/test.urlspec", { allowedBaseDir: "/home/user" }),
@@ -183,7 +167,6 @@ describe("URLSpec Builder", () => {
183167

184168
it("should allow valid paths within allowed base directory", async () => {
185169
const spec = new URLSpec();
186-
spec.setNamespace("test");
187170
spec.addPage({ name: "home", path: "/" });
188171

189172
// This should not throw (but will fail to write without proper setup)
@@ -196,7 +179,6 @@ describe("URLSpec Builder", () => {
196179

197180
it("should normalize paths before validation", async () => {
198181
const spec = new URLSpec();
199-
spec.setNamespace("test");
200182

201183
// These should be rejected even with path obfuscation
202184
await expect(spec.writeFile("/tmp/../etc/passwd")).rejects.toThrow();

packages/language/src/__generated__/ast.ts

Lines changed: 0 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)