primate 0.2.0 → 0.3.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/package.json +6 -1
- package/source/client/Element.js +4 -2
- package/source/server/Bundler.js +1 -1
- package/source/server/File.js +5 -1
- package/source/server/domain/Domain.js +12 -10
- package/source/server/servers/Static.js +2 -2
- package/source/server/types/File.js +20 -0
- package/source/server/types.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "primate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"author": "Primate core team <core@primatejs.com>",
|
|
5
5
|
"homepage": "https://primatejs.com",
|
|
6
6
|
"description": "Server-client framework",
|
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"test": "node --experimental-json-modules node_modules/stick stick.json"
|
|
13
13
|
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"eslint": "^8.6.0",
|
|
16
|
+
"eslint-plugin-json": "^3.1.0",
|
|
17
|
+
"stick": "../stick"
|
|
18
|
+
},
|
|
14
19
|
"type": "module",
|
|
15
20
|
"exports": "./source/server/exports.js",
|
|
16
21
|
"engines": {
|
package/source/client/Element.js
CHANGED
|
@@ -143,8 +143,10 @@ export default class Element {
|
|
|
143
143
|
return this;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
class(
|
|
147
|
-
|
|
146
|
+
class(classes, set) {
|
|
147
|
+
classes.split(" ").forEach(name => {
|
|
148
|
+
this.element.classList.toggle(name, set !== false);
|
|
149
|
+
})
|
|
148
150
|
return this;
|
|
149
151
|
}
|
|
150
152
|
|
package/source/server/Bundler.js
CHANGED
package/source/server/File.js
CHANGED
|
@@ -31,10 +31,14 @@ export default class File {
|
|
|
31
31
|
return this.exists && !this.stats.isDirectory();
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
get
|
|
34
|
+
get read_stream() {
|
|
35
35
|
return fs.createReadStream(this.path, {"flags": "r"});
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
get write_stream() {
|
|
39
|
+
return fs.createWriteStream(this.path);
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
remove() {
|
|
39
43
|
return new Promise((resolve, reject) => fs.rm(this.path,
|
|
40
44
|
{"recursive": true, "force": true},
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import Base from "../Base.js";
|
|
2
2
|
import Field from "./Field.js";
|
|
3
|
-
import
|
|
4
|
-
import {PredicateError, InternalServerError} from "../errors.js";
|
|
3
|
+
import {PredicateError} from "../errors.js";
|
|
5
4
|
import {EagerPromise} from "../promises.js";
|
|
6
|
-
import {assert} from "../invariants.js";
|
|
7
5
|
import cache from "../cache.js";
|
|
8
6
|
import {random} from "../Crypto.js";
|
|
9
|
-
import fallback from "../fallback.js";
|
|
10
7
|
|
|
11
8
|
const length = 12;
|
|
12
9
|
const preset = "../../preset/data/stores";
|
|
@@ -43,8 +40,13 @@ export default class Domain extends Base {
|
|
|
43
40
|
|
|
44
41
|
static get store() {
|
|
45
42
|
return cache(this, "store", async () => {
|
|
46
|
-
const
|
|
47
|
-
|
|
43
|
+
const create_path = path => `${path}/${this.store_file}`;
|
|
44
|
+
let store;
|
|
45
|
+
try {
|
|
46
|
+
store = await import(create_path(this.conf.paths.data.stores));
|
|
47
|
+
} catch(error) {
|
|
48
|
+
store = await import(create_path(preset));
|
|
49
|
+
}
|
|
48
50
|
return store.default.open();
|
|
49
51
|
});
|
|
50
52
|
}
|
|
@@ -103,10 +105,10 @@ export default class Domain extends Base {
|
|
|
103
105
|
|
|
104
106
|
// #serialize
|
|
105
107
|
// Serializing is done from the instance's point of view.
|
|
106
|
-
serialize() {
|
|
108
|
+
async serialize() {
|
|
107
109
|
const {properties, fields} = this;
|
|
108
|
-
return properties.map(property =>
|
|
109
|
-
({property, "value": fields[property].serialize(this[property])}))
|
|
110
|
+
return (await Promise.all(properties.map(async property =>
|
|
111
|
+
({property, "value": await fields[property].serialize(this[property])}))))
|
|
110
112
|
.filter(({value}) => value !== undefined)
|
|
111
113
|
.reduce((document, {property, value}) => {
|
|
112
114
|
document[property] = value;
|
|
@@ -170,7 +172,7 @@ export default class Domain extends Base {
|
|
|
170
172
|
const verified = await this.verify(delta);
|
|
171
173
|
if (verified) {
|
|
172
174
|
const store = await this.store;
|
|
173
|
-
const document = this.serialize();
|
|
175
|
+
const document = await this.serialize();
|
|
174
176
|
await store.save(this.collection, {"_id": document._id}, document);
|
|
175
177
|
await after();
|
|
176
178
|
}
|
|
@@ -58,7 +58,7 @@ export default class StaticServer extends Server {
|
|
|
58
58
|
response.setHeader("Content-Type", mime(filename));
|
|
59
59
|
response.setHeader("Etag", file.modified);
|
|
60
60
|
await session.log("green", url);
|
|
61
|
-
return stream(file.
|
|
61
|
+
return stream(file.read_stream, response);
|
|
62
62
|
} else {
|
|
63
63
|
return this.serve_data(url, session, request, response);
|
|
64
64
|
}
|
|
@@ -79,7 +79,7 @@ export default class StaticServer extends Server {
|
|
|
79
79
|
const integrity = `${algorithm}-${hash(src)}`;
|
|
80
80
|
const view = `<script type="module" integrity="${integrity}">${src}`
|
|
81
81
|
+ "</script>";
|
|
82
|
-
const file =
|
|
82
|
+
const file = index.replace("<first-view />", view);
|
|
83
83
|
const script_src = Array.from(hashes)
|
|
84
84
|
.concat([integrity])
|
|
85
85
|
.reduce((hash_string, next_hash) => hash_string + ` '${next_hash}'`, "");
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Storeable from "./Storeable.js";
|
|
2
|
+
import File from "../File.js";
|
|
3
|
+
|
|
4
|
+
export default class extends Storeable {
|
|
5
|
+
static get instance() {
|
|
6
|
+
return File;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static type_error() {
|
|
10
|
+
return "Must be a file";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static is(value) {
|
|
14
|
+
return value instanceof this.instance;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static deserialize(value) {
|
|
18
|
+
return value instanceof this.instance ? value : new this.instance(value);
|
|
19
|
+
}
|
|
20
|
+
}
|
package/source/server/types.js
CHANGED
|
@@ -4,3 +4,4 @@ export {default as DateType} from "./types/Date.js";
|
|
|
4
4
|
export {default as NumberType} from "./types/Number.js";
|
|
5
5
|
export {default as ObjectType} from "./types/Object.js";
|
|
6
6
|
export {default as StringType} from "./types/String.js";
|
|
7
|
+
export {default as FileType} from "./types/File.js";
|