From 886694700ec392b3c6f92cfa92cf47d8ff0b178f Mon Sep 17 00:00:00 2001 From: Peter Hoddie Date: Tue, 28 Jun 2022 11:48:11 -0700 Subject: [PATCH] split manifests, merge configs --- examples/io/tcp/fetch/config.js | 28 ------------------- examples/io/tcp/fetch/manifest.json | 25 ++--------------- examples/io/tcp/fetch/manifest_fetch.json | 11 ++++++++ examples/io/tcp/httpclient/config.js | 3 ++ examples/io/tcp/httpclient/httpclient.js | 10 +++---- examples/io/tcp/httpclient/manifest.json | 23 ++------------- .../tcp/httpclient/manifest_httpclient.json | 24 ++++++++++++++++ examples/io/tcp/mqttclient/config.js | 1 + .../tcp/mqttclient/manifest_mqttclient.json | 4 +-- 9 files changed, 51 insertions(+), 78 deletions(-) delete mode 100644 examples/io/tcp/fetch/config.js create mode 100644 examples/io/tcp/fetch/manifest_fetch.json create mode 100644 examples/io/tcp/httpclient/manifest_httpclient.json diff --git a/examples/io/tcp/fetch/config.js b/examples/io/tcp/fetch/config.js deleted file mode 100644 index 5bf4341899..0000000000 --- a/examples/io/tcp/fetch/config.js +++ /dev/null @@ -1,28 +0,0 @@ -import TCP from "embedded:io/socket/tcp"; -import UDP from "embedded:io/socket/udp"; -import Resolver from "embedded:network/dns/resolver/udp"; - -import HTTPClient from "embedded:network/http/client"; - -const dns = { - io: Resolver, - servers: [ - "1.1.1.1", //... - ], - socket: { - io: UDP, - }, -}; -globalThis.device = Object.freeze({ - ...globalThis.device, - network: { - http: { - io: HTTPClient, - dns, - socket: { - io: TCP, - }, - }, - }, -}, true); - diff --git a/examples/io/tcp/fetch/manifest.json b/examples/io/tcp/fetch/manifest.json index 712ba22477..b827e4d16d 100644 --- a/examples/io/tcp/fetch/manifest.json +++ b/examples/io/tcp/fetch/manifest.json @@ -1,30 +1,11 @@ { "include": [ - "$(MODDABLE)/modules/io/manifest.json" + "$(MODDABLE)/examples/io/tcp/fetch/manifest_fetch.json" ], "creation": { "static": 65536 }, "modules": { - "*": [ - "./config", - "./fetch", - "./main", - "$(MODULES)/network/dns/moddnsparser" - ], - "embedded:network/dns/resolver/udp": "../../udp/dns/dns", - "dns": "$(MODULES)/network/dns/dns", - "dns/parser": "$(MODULES)/network/dns/dnsparser", - "dns/serializer": "$(MODULES)/network/dns/dnsserializer", - "embedded:network/http/client": "./../httpclient/httpclient" - }, - "preload": [ - "config", - "embedded:network/dns/resolver", - "dns", - "dns/parser", - "dns/serializer", - "embedded:network/http/request", - "fetch" - ] + "*": "./main" + } } diff --git a/examples/io/tcp/fetch/manifest_fetch.json b/examples/io/tcp/fetch/manifest_fetch.json new file mode 100644 index 0000000000..e14d0eb456 --- /dev/null +++ b/examples/io/tcp/fetch/manifest_fetch.json @@ -0,0 +1,11 @@ +{ + "include": [ + "$(MODDABLE)/examples/io/tcp/httpclient/manifest_httpclient.json" + ], + "modules": { + "*": "./fetch" + }, + "preload": [ + "fetch" + ] +} diff --git a/examples/io/tcp/httpclient/config.js b/examples/io/tcp/httpclient/config.js index 5bf4341899..d65d228639 100644 --- a/examples/io/tcp/httpclient/config.js +++ b/examples/io/tcp/httpclient/config.js @@ -1,3 +1,5 @@ +import "system" // system initializes globalThis.device. this ensures it runs before this module. + import TCP from "embedded:io/socket/tcp"; import UDP from "embedded:io/socket/udp"; import Resolver from "embedded:network/dns/resolver/udp"; @@ -16,6 +18,7 @@ const dns = { globalThis.device = Object.freeze({ ...globalThis.device, network: { + ...globalThis.device?.network, http: { io: HTTPClient, dns, diff --git a/examples/io/tcp/httpclient/httpclient.js b/examples/io/tcp/httpclient/httpclient.js index 5540d9479a..d938220363 100644 --- a/examples/io/tcp/httpclient/httpclient.js +++ b/examples/io/tcp/httpclient/httpclient.js @@ -135,10 +135,9 @@ class HTTPClient { this.#onClose = onClose; const dns = new options.dns.io(options.dns); - dns.resolve({ host: this.#host, - + onResolved: (host, address) => { this.#socket = new options.socket.io({ ...options.socket, @@ -149,16 +148,15 @@ class HTTPClient { onError: this.#onError.bind(this) }); }, - onError: (err) => { + onError: () => { this.#onError?.(); - }, + } }); - } close() { this.#socket?.close(); this.#socket = undefined; - Timer.clear(this.#timer); + Timer.clear(this.#timer); this.#timer = undefined; } request(options) { diff --git a/examples/io/tcp/httpclient/manifest.json b/examples/io/tcp/httpclient/manifest.json index 7a499c3803..ec2755baf3 100644 --- a/examples/io/tcp/httpclient/manifest.json +++ b/examples/io/tcp/httpclient/manifest.json @@ -1,26 +1,9 @@ { "include": [ - "$(MODDABLE)/modules/io/manifest.json", + "./manifest_httpclient.json", "$(MODDABLE)/modules/data/text/decoder/manifest.json" ], "modules": { - "*": [ - "./config", - "./main", - "$(MODULES)/network/dns/moddnsparser" - ], - "embedded:network/dns/resolver/udp": "../../udp/dns/dns", - "dns": "$(MODULES)/network/dns/dns", - "dns/parser": "$(MODULES)/network/dns/dnsparser", - "dns/serializer": "$(MODULES)/network/dns/dnsserializer", - "embedded:network/http/client": "./../httpclient/httpclient" - }, - "preload": [ - "config", - "embedded:network/dns/resolver", - "dns", - "dns/parser", - "dns/serializer", - "embedded:network/http/client" - ] + "*": "./main" + } } diff --git a/examples/io/tcp/httpclient/manifest_httpclient.json b/examples/io/tcp/httpclient/manifest_httpclient.json new file mode 100644 index 0000000000..0f02008290 --- /dev/null +++ b/examples/io/tcp/httpclient/manifest_httpclient.json @@ -0,0 +1,24 @@ +{ + "include": [ + "$(MODDABLE)/modules/io/manifest.json" + ], + "modules": { + "*": [ + "$(MODULES)/network/dns/moddnsparser" + ], + "httpclient/config": "./config", + "embedded:network/dns/resolver/udp": "../../udp/dns/dns", + "dns": "$(MODULES)/network/dns/dns", + "dns/parser": "$(MODULES)/network/dns/dnsparser", + "dns/serializer": "$(MODULES)/network/dns/dnsserializer", + "embedded:network/http/client": "./../httpclient/httpclient" + }, + "preload": [ + "httpclient/config", + "embedded:network/dns/resolver", + "dns", + "dns/parser", + "dns/serializer", + "embedded:network/http/client" + ] +} diff --git a/examples/io/tcp/mqttclient/config.js b/examples/io/tcp/mqttclient/config.js index 6e1d809471..20ae5447c1 100644 --- a/examples/io/tcp/mqttclient/config.js +++ b/examples/io/tcp/mqttclient/config.js @@ -18,6 +18,7 @@ const dns = { globalThis.device = Object.freeze({ ...globalThis.device, network: { + ...globalThis.device?.network, mqtt: { io: MQTTClient, dns, diff --git a/examples/io/tcp/mqttclient/manifest_mqttclient.json b/examples/io/tcp/mqttclient/manifest_mqttclient.json index 5718260c2a..b19a5f93cd 100644 --- a/examples/io/tcp/mqttclient/manifest_mqttclient.json +++ b/examples/io/tcp/mqttclient/manifest_mqttclient.json @@ -1,9 +1,9 @@ { "modules": { "*": [ - "./config", "$(MODULES)/network/dns/moddnsparser" ], + "mqttclient/config": "./config", "embedded:network/dns/resolver/udp": "../../udp/dns/dns", "dns": "$(MODULES)/network/dns/dns", "dns/parser": "$(MODULES)/network/dns/dnsparser", @@ -11,7 +11,7 @@ "embedded:network/mqtt/client": "./mqttclient" }, "preload": [ - "config", + "mqttclient/config", "embedded:network/dns/resolver", "dns", "dns/parser",