@adviser/cement 0.2.11 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  WebSysAbstraction
3
- } from "./chunk-BEOYQN5I.js";
3
+ } from "./chunk-XJF7FQUN.js";
4
4
  import {
5
5
  BrowserEnvActions,
6
6
  EnvImpl,
@@ -17,7 +17,7 @@ import {
17
17
  TimeMode,
18
18
  TimeUnits,
19
19
  envFactory
20
- } from "./chunk-LK3TUJH3.js";
20
+ } from "./chunk-O4F5AURC.js";
21
21
  import {
22
22
  __spreadValues,
23
23
  __yieldStar
@@ -104,6 +104,186 @@ function IsLogger(obj) {
104
104
  ].map((fn) => typeof obj[fn] === "function").reduce((a, b) => a && b, true);
105
105
  }
106
106
 
107
+ // src/uri.ts
108
+ function falsy2undef(value) {
109
+ return value === void 0 || value === null ? void 0 : value;
110
+ }
111
+ function ensureURLWithDefaultProto(url, defaultProtocol) {
112
+ if (!url) {
113
+ return new URL(`${defaultProtocol}//`);
114
+ }
115
+ if (typeof url === "string") {
116
+ try {
117
+ return new URL(url);
118
+ } catch (e) {
119
+ return new URL(`${defaultProtocol}//${url}`);
120
+ }
121
+ } else {
122
+ return url;
123
+ }
124
+ }
125
+ function isURL(value) {
126
+ return value instanceof URL || !!value && typeof value.searchParams === "object" && typeof value.searchParams.sort === "function" && typeof value.hash === "string";
127
+ }
128
+ function from(fac, strURLUri, defaultProtocol) {
129
+ switch (typeof falsy2undef(strURLUri)) {
130
+ case "undefined":
131
+ return fac(new URL(`${defaultProtocol}//`));
132
+ case "string":
133
+ return fac(ensureURLWithDefaultProto(strURLUri, defaultProtocol));
134
+ case "object":
135
+ if (BuildURI.is(strURLUri)) {
136
+ return fac(new URL(strURLUri._url.toString()));
137
+ } else if (URI.is(strURLUri)) {
138
+ return fac(new URL(strURLUri._url.toString()));
139
+ } else if (isURL(strURLUri)) {
140
+ return fac(new URL(strURLUri.toString()));
141
+ }
142
+ throw new Error(`unknown object type: ${strURLUri}`);
143
+ default:
144
+ throw new Error(`Invalid argument: ${typeof strURLUri}`);
145
+ }
146
+ }
147
+ var BuildURI = class _BuildURI {
148
+ constructor(url) {
149
+ this._url = url;
150
+ }
151
+ static is(value) {
152
+ return value instanceof _BuildURI || !!value && typeof value.delParam === "function" && typeof value.setParam === "function";
153
+ }
154
+ static from(strURLUri, defaultProtocol = "file:") {
155
+ return from((url) => new _BuildURI(url), strURLUri, defaultProtocol);
156
+ }
157
+ hostname(h) {
158
+ this._url.hostname = h;
159
+ return this;
160
+ }
161
+ password(p) {
162
+ this._url.password = p;
163
+ return this;
164
+ }
165
+ port(p) {
166
+ this._url.port = p;
167
+ return this;
168
+ }
169
+ username(u) {
170
+ this._url.username = u;
171
+ return this;
172
+ }
173
+ search(s) {
174
+ this._url.search = s;
175
+ return this;
176
+ }
177
+ protocol(p) {
178
+ this._url.protocol = p;
179
+ return this;
180
+ }
181
+ pathname(p) {
182
+ this._url.pathname = p;
183
+ return this;
184
+ }
185
+ hash(h) {
186
+ this._url.hash = h;
187
+ return this;
188
+ }
189
+ host(h) {
190
+ this._url.host = h;
191
+ return this;
192
+ }
193
+ delParam(key) {
194
+ this._url.searchParams.delete(key);
195
+ return this;
196
+ }
197
+ defParam(key, str) {
198
+ if (!this._url.searchParams.has(key)) {
199
+ this._url.searchParams.set(key, str);
200
+ }
201
+ return this;
202
+ }
203
+ setParam(key, str) {
204
+ this._url.searchParams.set(key, str);
205
+ return this;
206
+ }
207
+ toString() {
208
+ this._url.searchParams.sort();
209
+ return this._url.toString();
210
+ }
211
+ URI() {
212
+ return URI.from(this._url);
213
+ }
214
+ };
215
+ var URI = class _URI {
216
+ // if no protocol is provided, default to file:
217
+ static merge(into, from2, defaultProtocol = "file:") {
218
+ const intoUrl = _URI.from(into, defaultProtocol);
219
+ const fromUrl = _URI.from(from2, defaultProtocol);
220
+ for (const [key, value] of fromUrl._url.searchParams) {
221
+ if (!intoUrl._url.searchParams.has(key)) {
222
+ intoUrl._url.searchParams.set(key, value);
223
+ }
224
+ }
225
+ return intoUrl;
226
+ }
227
+ static is(value) {
228
+ return value instanceof _URI || !!value && typeof value.asURL === "function" && typeof value.getParam === "function" && typeof value.hasParam === "function";
229
+ }
230
+ // if no protocol is provided, default to file:
231
+ static from(strURLUri, defaultProtocol = "file:") {
232
+ return from((url) => new _URI(url), strURLUri, defaultProtocol);
233
+ }
234
+ constructor(url) {
235
+ this._url = url;
236
+ }
237
+ build() {
238
+ return BuildURI.from(this.asURL());
239
+ }
240
+ get hostname() {
241
+ return this._url.hostname;
242
+ }
243
+ get password() {
244
+ return this._url.password;
245
+ }
246
+ get port() {
247
+ return this._url.port;
248
+ }
249
+ get username() {
250
+ return this._url.username;
251
+ }
252
+ get search() {
253
+ return this._url.search;
254
+ }
255
+ get protocol() {
256
+ return this._url.protocol;
257
+ }
258
+ get pathname() {
259
+ return this._url.toString().replace(/^.*:\/\//, "").replace(/\?.*$/, "");
260
+ }
261
+ get hash() {
262
+ return this._url.hash;
263
+ }
264
+ get host() {
265
+ return this._url.host;
266
+ }
267
+ hasParam(key) {
268
+ return this._url.searchParams.has(key);
269
+ }
270
+ getParam(key) {
271
+ return falsy2undef(this._url.searchParams.get(key));
272
+ }
273
+ clone() {
274
+ return new _URI(this.asURL());
275
+ }
276
+ asURL() {
277
+ const url = new URL(this._url.toString());
278
+ url.searchParams.sort();
279
+ return url;
280
+ }
281
+ toString() {
282
+ this._url.searchParams.sort();
283
+ return this._url.toString();
284
+ }
285
+ };
286
+
107
287
  // src/logger_impl.ts
108
288
  var encoder = new TextEncoder();
109
289
  var LevelHandlerImpl = class {
@@ -361,7 +541,7 @@ var LoggerImpl = class _LoggerImpl {
361
541
  return this;
362
542
  }
363
543
  Url(url, key = "url") {
364
- this.Ref(key, () => url.toString());
544
+ this.Ref(key, () => URI.from(url).toString());
365
545
  return this;
366
546
  }
367
547
  Str(key, value) {
@@ -775,188 +955,17 @@ function isSet(value, ref = globalThis) {
775
955
  return false;
776
956
  }
777
957
  function runtimeFn() {
778
- const isNodeIsh = isSet("process.versions.node");
779
- const isDeno = isSet("Deno");
958
+ const isReactNative = isSet("navigator.product") && globalThis.navigator.product === "ReactNative";
959
+ const isNodeIsh = isSet("process.versions.node") && !isReactNative;
960
+ const isDeno = isSet("Deno") && !isReactNative;
780
961
  return {
781
962
  isNodeIsh,
782
- isBrowser: !(isNodeIsh || isDeno),
963
+ isBrowser: !(isNodeIsh || isDeno) && !isReactNative,
783
964
  isDeno,
784
- isReactNative: false
965
+ isReactNative
785
966
  };
786
967
  }
787
968
 
788
- // src/uri.ts
789
- function falsy2undef(value) {
790
- return value === void 0 || value === null ? void 0 : value;
791
- }
792
- function ensureURLWithDefaultProto(url, defaultProtocol) {
793
- if (!url) {
794
- return new URL(`${defaultProtocol}//`);
795
- }
796
- if (typeof url === "string") {
797
- try {
798
- return new URL(url);
799
- } catch (e) {
800
- return new URL(`${defaultProtocol}//${url}`);
801
- }
802
- } else {
803
- return url;
804
- }
805
- }
806
- function from(fac, strURLUri, defaultProtocol) {
807
- switch (typeof falsy2undef(strURLUri)) {
808
- case "undefined":
809
- return fac(new URL(`${defaultProtocol}//`));
810
- case "string":
811
- return fac(ensureURLWithDefaultProto(strURLUri, defaultProtocol));
812
- case "object":
813
- if (strURLUri instanceof URI) {
814
- return fac(new URL(strURLUri._url.toString()));
815
- } else if (strURLUri instanceof URL) {
816
- return fac(new URL(strURLUri.toString()));
817
- }
818
- throw new Error(`unknown object type: ${strURLUri}`);
819
- default:
820
- throw new Error(`Invalid argument: ${typeof strURLUri}`);
821
- }
822
- }
823
- var BuildURI = class _BuildURI {
824
- constructor(url) {
825
- this._url = url;
826
- }
827
- static from(strURLUri, defaultProtocol = "file:") {
828
- return from((url) => new _BuildURI(url), strURLUri, defaultProtocol);
829
- }
830
- hostname(h) {
831
- this._url.hostname = h;
832
- return this;
833
- }
834
- password(p) {
835
- this._url.password = p;
836
- return this;
837
- }
838
- port(p) {
839
- this._url.port = p;
840
- return this;
841
- }
842
- username(u) {
843
- this._url.username = u;
844
- return this;
845
- }
846
- search(s) {
847
- this._url.search = s;
848
- return this;
849
- }
850
- protocol(p) {
851
- this._url.protocol = p;
852
- return this;
853
- }
854
- pathname(p) {
855
- this._url.pathname = p;
856
- return this;
857
- }
858
- hash(h) {
859
- this._url.hash = h;
860
- return this;
861
- }
862
- host(h) {
863
- this._url.host = h;
864
- return this;
865
- }
866
- delParam(key) {
867
- this._url.searchParams.delete(key);
868
- return this;
869
- }
870
- defParam(key, str) {
871
- if (!this._url.searchParams.has(key)) {
872
- this._url.searchParams.set(key, str);
873
- }
874
- return this;
875
- }
876
- setParam(key, str) {
877
- this._url.searchParams.set(key, str);
878
- return this;
879
- }
880
- toString() {
881
- this._url.searchParams.sort();
882
- return this._url.toString();
883
- }
884
- URI() {
885
- return URI.from(this._url);
886
- }
887
- };
888
- function isURI(value) {
889
- return value instanceof URI || !!value && typeof value.asURL === "function" || false;
890
- }
891
- var URI = class _URI {
892
- // if no protocol is provided, default to file:
893
- static merge(into, from2, defaultProtocol = "file:") {
894
- const intoUrl = _URI.from(into, defaultProtocol);
895
- const fromUrl = _URI.from(from2, defaultProtocol);
896
- for (const [key, value] of fromUrl._url.searchParams) {
897
- if (!intoUrl._url.searchParams.has(key)) {
898
- intoUrl._url.searchParams.set(key, value);
899
- }
900
- }
901
- return intoUrl;
902
- }
903
- // if no protocol is provided, default to file:
904
- static from(strURLUri, defaultProtocol = "file:") {
905
- return from((url) => new _URI(url), strURLUri, defaultProtocol);
906
- }
907
- constructor(url) {
908
- this._url = url;
909
- }
910
- build() {
911
- return BuildURI.from(this.asURL());
912
- }
913
- get hostname() {
914
- return this._url.hostname;
915
- }
916
- get password() {
917
- return this._url.password;
918
- }
919
- get port() {
920
- return this._url.port;
921
- }
922
- get username() {
923
- return this._url.username;
924
- }
925
- get search() {
926
- return this._url.search;
927
- }
928
- get protocol() {
929
- return this._url.protocol;
930
- }
931
- get pathname() {
932
- return this._url.toString().replace(/^.*:\/\//, "").replace(/\?.*$/, "");
933
- }
934
- get hash() {
935
- return this._url.hash;
936
- }
937
- get host() {
938
- return this._url.host;
939
- }
940
- hasParam(key) {
941
- return this._url.searchParams.has(key);
942
- }
943
- getParam(key) {
944
- return falsy2undef(this._url.searchParams.get(key));
945
- }
946
- clone() {
947
- return new _URI(this.asURL());
948
- }
949
- asURL() {
950
- const url = new URL(this._url.toString());
951
- url.searchParams.sort();
952
- return url;
953
- }
954
- toString() {
955
- this._url.searchParams.sort();
956
- return this._url.toString();
957
- }
958
- };
959
-
960
969
  // src/crypto.ts
961
970
  function randomBytes(size) {
962
971
  const bytes = new Uint8Array(size);
@@ -1011,7 +1020,7 @@ export {
1011
1020
  URI,
1012
1021
  asyncLogValue,
1013
1022
  envFactory,
1014
- isURI,
1023
+ isURL,
1015
1024
  logValue,
1016
1025
  removeSelfRef,
1017
1026
  runtimeFn,