primate 0.1.1 → 0.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primate",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "author": "Primate core team <core@primatejs.com>",
5
5
  "homepage": "https://primatejs.com",
6
6
  "description": "Server-client framework",
@@ -1,9 +1,7 @@
1
1
  import Element from "../Element.js";
2
2
  import View from "./View.js";
3
3
  import Base from "./Base.js";
4
-
5
- const base = document.baseURI.replace(document.location.origin, "");
6
- const full = `${document.location.origin}${base}`;
4
+ import {origin_base} from "./document.js";
7
5
 
8
6
  export default class Action extends Base {
9
7
  constructor(name, context) {
@@ -75,7 +73,7 @@ export default class Action extends Base {
75
73
  }
76
74
  event.preventDefault();
77
75
  const data = await this.write(target.action, this.get_form_data(target));
78
- return data.pathname === document.location.href.replace(full, "")
76
+ return data.pathname === document.location.href.replace(origin_base, "")
79
77
  ? this.view.update(data.payload)
80
78
  : this.context.run(data);
81
79
  }
@@ -94,8 +92,8 @@ export default class Action extends Base {
94
92
  }
95
93
  if (target !== null) {
96
94
  const href = Element.value(target, "href");
97
- const url = new URL(href, full);
98
- if (event.button === 0 && url.href.startsWith(full)) {
95
+ const url = new URL(href, origin_base);
96
+ if (event.button === 0 && url.href.startsWith(origin_base)) {
99
97
  event.preventDefault();
100
98
  if (href !== "") {
101
99
  const data = await this.read(href);
@@ -1,15 +1,12 @@
1
1
  import Client from "./Client.js";
2
2
 
3
- const host = document.location.host;
4
- const base = document.baseURI.replace(document.location.origin, "");
5
-
6
3
  export default class App {
7
4
  constructor() {
8
5
  this.definitions = {};
9
6
  }
10
7
 
11
8
  run() {
12
- this.client = new Client({host, base});
9
+ this.client = new Client();
13
10
  this.client.open();
14
11
  }
15
12
 
@@ -1,8 +1,10 @@
1
1
  import Context from "./Context.js";
2
2
  import {contexts} from "./exports.js";
3
+ import {base, host, origin_base} from "./document.js";
3
4
 
4
5
  const events = ["submit", "click", "change", "input"];
5
6
  let back = undefined;
7
+ const location = `wss://${host}${base}`;
6
8
 
7
9
  export default class Client {
8
10
  constructor(conf) {
@@ -18,14 +20,10 @@ export default class Client {
18
20
  }
19
21
  }
20
22
 
21
- get location() {
22
- return `wss://${this.conf.host}${this.conf.base}`;
23
- }
24
-
25
23
  open() {
26
24
  return this.connection?.readyState === 1 ? this
27
25
  : new Promise(resolve => {
28
- const connection = new WebSocket(this.location);
26
+ const connection = new WebSocket(location);
29
27
  connection.addEventListener("message", ({data}) => data === "open"
30
28
  ? resolve(this)
31
29
  : this.receive(JSON.parse(data)));
@@ -56,13 +54,9 @@ export default class Client {
56
54
  return this.send("write", url, payload);
57
55
  }
58
56
 
59
- get full() {
60
- return `${document.location.origin}${this.conf.base}`;
61
- }
62
-
63
57
  async send(type, url, payload = {}) {
64
58
  await this.open();
65
- const {pathname, search} = new URL(url, this.full);
59
+ const {pathname, search} = new URL(url, origin_base);
66
60
  return new Promise(resolve => {
67
61
  back = data => resolve(data);
68
62
  this.connection.send(JSON.stringify({type, pathname, search, payload}));
@@ -0,0 +1,6 @@
1
+ const {baseURI} = document;
2
+ const {host, href, origin} = document.location;
3
+ const base = baseURI === href ? "/" : baseURI.replace(origin, "");
4
+ const origin_base = `${origin}${base}`;
5
+
6
+ export {base, origin_base, host};
@@ -125,7 +125,7 @@ export default class Bundler {
125
125
 
126
126
  register(src, source) {
127
127
  const integrity = `${algorithm}-${hash(source)}`;
128
- this.scripts.push({src, integrity});
128
+ this.scripts.push({"src": `${this.conf.base}${src}`, integrity});
129
129
  this.hashes.add(integrity);
130
130
  }
131
131
 
@@ -45,14 +45,7 @@ export default class Domain extends Base {
45
45
  return cache(this, "store", async () => {
46
46
  const logic = path => import(`${path}/${this.store_file}`);
47
47
  const store = await fallback(this.conf.paths.data.stores, preset, logic);
48
-
49
- const instance = store.default;
50
-
51
- const message = `${instance.constructor.name} must instance Store`;
52
- const error = () => { throw new InternalServerError(message); };
53
- assert(instance instanceof Store, error);
54
-
55
- return instance.open();
48
+ return store.default.open();
56
49
  });
57
50
  }
58
51
 
@@ -126,7 +119,7 @@ export default class Domain extends Base {
126
119
  static deserialize(serialized) {
127
120
  const fields = this._fields;
128
121
  return new this(Object.keys(serialized)
129
- //.filter(property => fields[property] !== undefined)
122
+ .filter(property => fields[property] !== undefined)
130
123
  .map(property =>
131
124
  ({property,
132
125
  "value": fields[property].deserialize(serialized[property])}))
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "default-src": "'self'",
3
3
  "object-src": "'none'",
4
- "style-src": "'self'",
5
- "img-src": "'self' data: https:",
4
+ "img-src": "'self' https:",
6
5
  "frame-ancestors": "'none'",
7
6
  "form-action": "'self'",
8
7
  "base-uri": "'self'"
@@ -14,7 +14,7 @@ export default class extends Instance {
14
14
  return value instanceof this.instance;
15
15
  }
16
16
 
17
- /*static deserialize(value) {
17
+ static deserialize(value) {
18
18
  return value instanceof this.instance ? value : new this.instance(value);
19
- }*/
19
+ }
20
20
  }
@@ -1,8 +0,0 @@
1
- export default value => {
2
- try {
3
- Reflect.construct(String, [], value);
4
- return true;
5
- } catch (error) {
6
- return false;
7
- }
8
- };