primate 0.5.2 → 0.6.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/README.md +21 -36
- package/debris.json +1 -2
- package/package.json +7 -10
- package/source/App.js +36 -0
- package/source/Bundler.js +51 -0
- package/source/{server/Directory.js → Directory.js} +0 -0
- package/source/{server/EagerPromise.js → EagerPromise.js} +5 -7
- package/source/{server/File.js → File.js} +0 -0
- package/source/Router.js +28 -0
- package/source/Server.js +105 -0
- package/source/{server/Session.js → Session.js} +2 -21
- package/source/{server/attributes.js → attributes.js} +0 -0
- package/source/{server/cache.js → cache.js} +0 -0
- package/source/{server/conf.js → conf.js} +1 -1
- package/source/{server/crypto.js → crypto.js} +0 -0
- package/source/{server/domain → domain}/Domain.js +7 -9
- package/source/{server/domain → domain}/Field.js +0 -0
- package/source/{server/domain → domain}/Predicate.js +0 -0
- package/source/{server/errors → errors}/InternalServer.js +0 -0
- package/source/{server/errors → errors}/Predicate.js +0 -0
- package/source/{server/errors.js → errors.js} +0 -0
- package/source/{server/exports.js → exports.js} +6 -3
- package/source/{server/extend_object.js → extend_object.js} +0 -0
- package/source/handlers/DOM/Node.js +184 -0
- package/source/{server/view → handlers/DOM}/Parser.js +22 -18
- package/source/handlers/html.js +30 -0
- package/source/handlers/http.js +6 -0
- package/source/handlers/json.js +6 -0
- package/source/handlers/redirect.js +10 -0
- package/source/{server/servers/http-codes.json → http-codes.json} +0 -0
- package/source/{server/invariants.js → invariants.js} +0 -0
- package/source/{server/log.js → log.js} +0 -0
- package/source/{server/servers/mimes.json → mimes.json} +0 -0
- package/source/preset/primate.json +3 -7
- package/source/preset/static/index.html +0 -2
- package/source/preset/stores/default.js +1 -1
- package/source/{server/sanitize.js → sanitize.js} +0 -0
- package/source/{server/store → store}/Memory.js +0 -0
- package/source/{server/store → store}/Store.js +1 -1
- package/source/{server/types → types}/Array.js +0 -0
- package/source/{server/types → types}/Boolean.js +0 -0
- package/source/{server/types → types}/Date.js +0 -0
- package/source/{server/types → types}/Domain.js +0 -0
- package/source/{server/types → types}/Instance.js +0 -0
- package/source/{server/types → types}/Number.js +0 -0
- package/source/{server/types → types}/Object.js +0 -0
- package/source/{server/types → types}/Primitive.js +0 -0
- package/source/{server/types → types}/Storeable.js +0 -0
- package/source/{server/types → types}/String.js +0 -0
- package/source/{server/types → types}/errors/Array.json +0 -0
- package/source/{server/types → types}/errors/Boolean.json +0 -0
- package/source/{server/types → types}/errors/Date.json +0 -0
- package/source/{server/types → types}/errors/Number.json +0 -0
- package/source/{server/types → types}/errors/Object.json +0 -0
- package/source/{server/types → types}/errors/String.json +0 -0
- package/source/{server/types.js → types.js} +0 -0
- package/source/client/Action.js +0 -157
- package/source/client/App.js +0 -16
- package/source/client/Client.js +0 -61
- package/source/client/Context.js +0 -47
- package/source/client/Element.js +0 -249
- package/source/client/Node.js +0 -13
- package/source/client/Session.js +0 -27
- package/source/client/View.js +0 -89
- package/source/client/document.js +0 -6
- package/source/client/exports.js +0 -15
- package/source/preset/client/Element.js +0 -2
- package/source/preset/client/app.js +0 -2
- package/source/server/Action.js +0 -100
- package/source/server/App.js +0 -62
- package/source/server/Bundler.js +0 -177
- package/source/server/Context.js +0 -97
- package/source/server/Projector.js +0 -86
- package/source/server/Router.js +0 -52
- package/source/server/domain/domains.js +0 -31
- package/source/server/servers/Dynamic.js +0 -57
- package/source/server/servers/Server.js +0 -5
- package/source/server/servers/Static.js +0 -117
- package/source/server/view/TreeNode.js +0 -197
- package/source/server/view/View.js +0 -35
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
const data_regex = /\${([^}]*)}/g;
|
|
2
|
-
|
|
3
|
-
export default class TreeNode {
|
|
4
|
-
constructor(parent, content) {
|
|
5
|
-
this.children = [];
|
|
6
|
-
this.content = content;
|
|
7
|
-
if (parent !== undefined) {
|
|
8
|
-
this.parent = parent;
|
|
9
|
-
this.parent.attach(this);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
attach(child) {
|
|
14
|
-
this.children.push(child);
|
|
15
|
-
child.parent = this;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// splices the child at the position i and hoists its children to i...
|
|
19
|
-
splice(i) {
|
|
20
|
-
if (this.children[i] !== undefined) {
|
|
21
|
-
const children = this.children[i].children;
|
|
22
|
-
for (const child of children) {
|
|
23
|
-
child.parent = this;
|
|
24
|
-
}
|
|
25
|
-
this.children.splice(i, 1, ...children);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
filter(predicate) {
|
|
30
|
-
for (let i = this.children.length-1; i >= 0; i--) {
|
|
31
|
-
this.children[i].filter(predicate);
|
|
32
|
-
predicate(this.children[i].content) && this.splice(i);
|
|
33
|
-
}
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
each(operation) {
|
|
38
|
-
if (this.content !== undefined) {
|
|
39
|
-
operation(this);
|
|
40
|
-
}
|
|
41
|
-
for (let i = 0; i < this.children.length; i++) {
|
|
42
|
-
this.children[i].each(operation);
|
|
43
|
-
}
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
transform() {
|
|
48
|
-
const tree = [];
|
|
49
|
-
let flatten = [];
|
|
50
|
-
|
|
51
|
-
this.filter(content => !content.includes("data-"))
|
|
52
|
-
.each(node => {
|
|
53
|
-
const data_tags = node.content.split("data-");
|
|
54
|
-
data_tags.shift();
|
|
55
|
-
node.content = data_tags
|
|
56
|
-
.filter(part => part.includes("="))
|
|
57
|
-
.map(part => {
|
|
58
|
-
const index = part.indexOf("=");
|
|
59
|
-
const key = part.slice(0, index);
|
|
60
|
-
const right = part.slice(index+1);
|
|
61
|
-
return {key, "value": right.slice(1, right.indexOf("\"", 1))};
|
|
62
|
-
});
|
|
63
|
-
})
|
|
64
|
-
// transform template strings
|
|
65
|
-
.each(node => {
|
|
66
|
-
for (let i = 0; i < node.content.length; i++) {
|
|
67
|
-
const part = node.content[i];
|
|
68
|
-
const key = part.key;
|
|
69
|
-
const matches = [...part.value.matchAll(data_regex)];
|
|
70
|
-
if (matches.length > 0) {
|
|
71
|
-
for (const match of matches) {
|
|
72
|
-
// add new entries to node.content
|
|
73
|
-
node.content.push({key, "value": match[1]});
|
|
74
|
-
}
|
|
75
|
-
// remove this entry
|
|
76
|
-
node.content.splice(i, 1);
|
|
77
|
-
i--;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
// unfold scopes
|
|
82
|
-
.each(node => {
|
|
83
|
-
for (let i = 0; i < node.content.length; i++) {
|
|
84
|
-
const part = node.content[i];
|
|
85
|
-
// memove scope and rework subtree
|
|
86
|
-
if (part.key === "scope") {
|
|
87
|
-
const scope = part.value;
|
|
88
|
-
for (let j = 0; j < node.children.length; j++) {
|
|
89
|
-
let recurse = true;
|
|
90
|
-
node.children[j].each(scopeable => {
|
|
91
|
-
// skip descending into children of data-scope
|
|
92
|
-
if (!recurse) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
let found_scope = false;
|
|
96
|
-
scopeable.content.forEach(content => {
|
|
97
|
-
if (content.key === "scope") {
|
|
98
|
-
found_scope = true;
|
|
99
|
-
}
|
|
100
|
-
content.value = `${scope}.${content.value}`;
|
|
101
|
-
});
|
|
102
|
-
recurse = !found_scope;
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
node.content.splice(i, 1);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
.each(node => {
|
|
110
|
-
flatten = flatten.concat(node.content.map(content => content.value));
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const error = key => { throw new Error(
|
|
114
|
-
`\`${key}\` appears as both value and object key`); };
|
|
115
|
-
const put = (tree, part) => {
|
|
116
|
-
if (!part.includes(".")) {
|
|
117
|
-
if (!tree.includes(part)) {
|
|
118
|
-
tree.push(part);
|
|
119
|
-
}
|
|
120
|
-
for (const node of tree) {
|
|
121
|
-
if (typeof node === "object") {
|
|
122
|
-
if (node[part] !== undefined) {
|
|
123
|
-
error(part);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
const index = part.indexOf(".");
|
|
129
|
-
const left = part.slice(0, index);
|
|
130
|
-
const right = part.slice(index+1);
|
|
131
|
-
if (tree.includes(left)) {
|
|
132
|
-
error(left);
|
|
133
|
-
}
|
|
134
|
-
let found_node = undefined;
|
|
135
|
-
for (const node of tree) {
|
|
136
|
-
if (typeof node === "object") {
|
|
137
|
-
if (node[left] !== undefined) {
|
|
138
|
-
found_node = node[left];
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (found_node === undefined) {
|
|
144
|
-
found_node = [];
|
|
145
|
-
tree.push({[left]: found_node});
|
|
146
|
-
}
|
|
147
|
-
put(found_node, right);
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
//const flattened = [...new Set(flatten)];
|
|
151
|
-
flatten.forEach(part => put(tree, part));
|
|
152
|
-
//return {tree, flattened};
|
|
153
|
-
return tree;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
flatten() {
|
|
157
|
-
const object = {};
|
|
158
|
-
if (this.children.length === 0) {
|
|
159
|
-
return this.content.key;
|
|
160
|
-
}
|
|
161
|
-
const key = this.content ? this.content.key : "root";
|
|
162
|
-
object[key] = [];
|
|
163
|
-
for (const child of this.children) {
|
|
164
|
-
if (child !== undefined) {
|
|
165
|
-
const interim = child.flatten();
|
|
166
|
-
if (interim instanceof Array) {
|
|
167
|
-
object[key] = object[key].concat(interim);
|
|
168
|
-
} else {
|
|
169
|
-
object[key].push(interim);
|
|
170
|
-
}
|
|
171
|
-
const strings = [];
|
|
172
|
-
const objects = {};
|
|
173
|
-
object[key] = object[key].filter(value => {
|
|
174
|
-
if (typeof value === "string") {
|
|
175
|
-
if (strings.includes(value)) {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
strings.push(value);
|
|
179
|
-
return true;
|
|
180
|
-
} else {
|
|
181
|
-
const key = Object.keys(value)[0];
|
|
182
|
-
value = value[key];
|
|
183
|
-
// merge with it
|
|
184
|
-
if (objects[key] !== undefined) {
|
|
185
|
-
objects[key].push(...value);
|
|
186
|
-
return false;
|
|
187
|
-
} else {
|
|
188
|
-
objects[key] = value;
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return object;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import Parser from "./Parser.js";
|
|
2
|
-
import File from "../File.js";
|
|
3
|
-
import {InternalServerError} from "../errors.js";
|
|
4
|
-
|
|
5
|
-
const $content = "${content}";
|
|
6
|
-
|
|
7
|
-
export default class View {
|
|
8
|
-
constructor(path, content, layouts) {
|
|
9
|
-
this.path = path;
|
|
10
|
-
this.content = content;
|
|
11
|
-
this.layouts = layouts;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
static async new(path, layouts) {
|
|
15
|
-
return new View(path, await File.read(`${path}.html`), layouts);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
elements(layout) {
|
|
19
|
-
try {
|
|
20
|
-
return Parser.parse(layout === undefined
|
|
21
|
-
? this.content
|
|
22
|
-
: this.file(layout)).transform();
|
|
23
|
-
} catch (error) {
|
|
24
|
-
throw new InternalServerError(`${this.path} ${error.message}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
layout(layout) {
|
|
29
|
-
return this.layouts[layout] ?? $content;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
file(layout = "default") {
|
|
33
|
-
return this.layout(layout).replace($content, () => this.content);
|
|
34
|
-
}
|
|
35
|
-
}
|