@adviser/cement 0.2.35 → 0.2.36

Sign up to get free protection for your applications and to get access to all the features.
@@ -224,22 +224,22 @@ var ConsoleWriterStreamDefaultWriter = class {
224
224
  this.closed = Promise.resolve(void 0);
225
225
  }
226
226
  async write(chunk) {
227
- const str = this.decoder.decode(chunk).trimEnd();
227
+ let strObj = this.decoder.decode(chunk).trimEnd();
228
228
  let output = "log";
229
229
  try {
230
- const decode = JSON.parse(str);
231
- output = decode.level;
230
+ strObj = JSON.parse(strObj);
231
+ output = strObj.level;
232
232
  } catch (e) {
233
233
  }
234
234
  switch (output) {
235
235
  case "error":
236
- console.error(str);
236
+ console.error(strObj);
237
237
  break;
238
238
  case "warn":
239
- console.warn(str);
239
+ console.warn(strObj);
240
240
  break;
241
241
  default:
242
- console.log(str);
242
+ console.log(strObj);
243
243
  }
244
244
  }
245
245
  };
@@ -308,4 +308,4 @@ export {
308
308
  uint8array2stream,
309
309
  utils_exports
310
310
  };
311
- //# sourceMappingURL=chunk-7KFVMTOS.js.map
311
+ //# sourceMappingURL=chunk-USQXEZHL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/index.ts","../../src/utils/stream-map.ts","../../src/utils/rebuffer.ts","../../src/utils/stream2string.ts","../../src/utils/string2stream.ts","../../src/utils/console-write-stream.ts","../../src/utils/fanout-write-stream.ts"],"sourcesContent":["export * from \"./rebuffer.js\";\nexport * from \"./stream-map.js\";\nexport * from \"./stream2string.js\";\nexport * from \"./string2stream.js\";\nexport * from \"./console-write-stream.js\";\nexport * from \"./fanout-write-stream.js\";\n","export interface StreamMap<T, U> {\n Map(s: T, idx: number): U | Promise<U>;\n readonly Close?: () => void;\n}\nexport function streamMap<T, U>(s: ReadableStream<T>, sm: StreamMap<T, U>): ReadableStream<U> {\n const state = { reader: s.getReader(), streamMap: sm, idx: 0 };\n return new ReadableStream<U>({\n async pull(controller): Promise<void> {\n const { done, value } = await state.reader.read();\n if (done) {\n if (state.streamMap.Close) {\n state.streamMap.Close();\n }\n controller.close();\n return;\n }\n const promiseOrU = state.streamMap.Map(value, state.idx++);\n let mapped: U;\n if (promiseOrU instanceof Promise || typeof (promiseOrU as { then: () => void }).then === \"function\") {\n mapped = await promiseOrU;\n } else {\n mapped = promiseOrU;\n }\n controller.enqueue(mapped);\n },\n });\n}\n\nexport async function devnull<T>(a: ReadableStream<T>): Promise<number> {\n const reader = a.getReader();\n let cnt = 0;\n while (true) {\n const { done } = await reader.read();\n if (done) {\n break;\n }\n cnt++;\n }\n return cnt;\n}\n\nexport function array2stream<T>(a: T[]): ReadableStream<T> {\n let i = 0;\n return new ReadableStream<T>({\n pull(controller): void {\n if (i >= a.length) {\n controller.close();\n return;\n }\n controller.enqueue(a[i]);\n i++;\n },\n });\n}\n\nexport async function stream2array<T>(a: ReadableStream<T>): Promise<T[]> {\n const ret: T[] = [];\n const reader = a.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n ret.push(value);\n }\n return ret;\n}\n","import { array2stream, stream2array } from \"./stream-map.js\";\n\ninterface ReChunkResult {\n readonly rest: Uint8Array;\n readonly chunk: Uint8Array;\n}\n\nexport async function rebufferArray(a: Uint8Array[], chunkSize: number): Promise<Uint8Array[]> {\n return stream2array(rebuffer(array2stream(a), chunkSize));\n}\n\nfunction reChunk(cs: Uint8Array[], chunkSize: number): ReChunkResult {\n const len = cs.reduce((acc, v) => acc + v.length, 0);\n const last = cs[cs.length - 1];\n const lastOfs = len - last.length;\n // console.log(\"reChunk\", len, lastOfs, last.length, chunkSize, chunkSize - lastOfs)\n const rest = last.subarray(chunkSize - lastOfs);\n cs[cs.length - 1] = last.subarray(0, chunkSize - lastOfs);\n const chunk = new Uint8Array(chunkSize);\n let ofs = 0;\n for (const c of cs) {\n chunk.set(c, ofs);\n ofs += c.length;\n }\n return { rest, chunk };\n}\n\ninterface pumpState {\n readonly reader: ReadableStreamDefaultReader<Uint8Array>;\n tmp: Uint8Array[];\n tmpLen: number;\n readonly chunkSize: number;\n}\n\nfunction pump(ps: pumpState, controller: ReadableStreamDefaultController<Uint8Array>, next: () => void): void {\n ps.reader.read().then(({ done, value }) => {\n if (done) {\n if (ps.tmpLen > 0) {\n controller.enqueue(reChunk(ps.tmp, ps.tmpLen).chunk);\n }\n controller.close();\n next();\n return;\n }\n if (ps.tmpLen + value.length > ps.chunkSize) {\n ps.tmp.push(value);\n const res = reChunk(ps.tmp, ps.chunkSize);\n controller.enqueue(res.chunk);\n ps.tmp = [res.rest];\n ps.tmpLen = res.rest.length;\n next();\n return;\n } else if (value.length) {\n ps.tmp.push(value);\n ps.tmpLen += value.length;\n }\n pump(ps, controller, next);\n });\n}\n\nexport function rebuffer(a: ReadableStream<Uint8Array>, chunkSize: number): ReadableStream<Uint8Array> {\n const state: pumpState = {\n reader: a.getReader(),\n tmp: [],\n tmpLen: 0,\n chunkSize,\n };\n return new ReadableStream<Uint8Array>({\n async pull(controller): Promise<void> {\n return new Promise<void>((resolve) => {\n pump(state, controller, resolve);\n });\n },\n });\n}\n","export async function stream2string(stream?: ReadableStream<Uint8Array> | null, maxSize?: number): Promise<string> {\n if (!stream) {\n return Promise.resolve(\"\");\n }\n const reader = stream.getReader();\n let res = \"\";\n const decoder = new TextDecoder();\n let rSize = 0;\n while (typeof maxSize === \"undefined\" || rSize < maxSize) {\n try {\n const read = await reader.read();\n if (read.done) {\n break;\n }\n if (maxSize && rSize + read.value.length > maxSize) {\n read.value = read.value.slice(0, maxSize - rSize);\n }\n const block = decoder.decode(read.value, { stream: true });\n rSize += read.value.length;\n res += block;\n } catch (err) {\n return Promise.reject(err);\n }\n }\n return Promise.resolve(res);\n}\n\nexport async function stream2uint8array(stream?: ReadableStream<Uint8Array> | null): Promise<Uint8Array> {\n if (!stream) {\n return Promise.resolve(new Uint8Array());\n }\n const reader = stream.getReader();\n let res = new Uint8Array();\n // eslint-disable-next-line no-constant-condition\n while (1) {\n try {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n res = new Uint8Array([...res, ...value]);\n } catch (err) {\n return Promise.reject(err);\n }\n }\n return Promise.resolve(res);\n}\n","import { TxtEnDecoder, Utf8EnDecoderSingleton } from \"../txt-en-decoder.js\";\n\nexport function string2stream(str: string, ende: TxtEnDecoder = Utf8EnDecoderSingleton()): ReadableStream<Uint8Array> {\n return uint8array2stream(ende.encode(str));\n}\n\nexport function uint8array2stream(str: Uint8Array): ReadableStream<Uint8Array> {\n return new ReadableStream<Uint8Array>({\n start(controller): void {\n controller.enqueue(str);\n controller.close();\n },\n });\n}\n","export class ConsoleWriterStreamDefaultWriter implements WritableStreamDefaultWriter<Uint8Array> {\n readonly desiredSize: number | null = null;\n readonly decoder: TextDecoder = new TextDecoder();\n\n closed: Promise<undefined>;\n ready: Promise<undefined>;\n readonly _stream: ConsoleWriterStream;\n\n constructor(private stream: ConsoleWriterStream) {\n this._stream = stream;\n this.ready = Promise.resolve(undefined);\n this.closed = Promise.resolve(undefined);\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any\n abort(reason?: any): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n async close(): Promise<void> {\n // noop\n }\n releaseLock(): void {\n this._stream.locked = false;\n this.ready = Promise.resolve(undefined);\n this.closed = Promise.resolve(undefined);\n }\n async write(chunk?: Uint8Array | undefined): Promise<void> {\n let strObj: string | { level: string } = this.decoder.decode(chunk).trimEnd();\n let output = \"log\";\n try {\n strObj = JSON.parse(strObj) as { level: string };\n output = strObj.level;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n /* noop */\n }\n switch (output) {\n case \"error\":\n // eslint-disable-next-line no-console\n console.error(strObj);\n break;\n case \"warn\":\n // eslint-disable-next-line no-console\n console.warn(strObj);\n break;\n default:\n // eslint-disable-next-line no-console\n console.log(strObj);\n }\n }\n}\n\nexport class ConsoleWriterStream implements WritableStream<Uint8Array> {\n locked = false;\n _writer?: WritableStreamDefaultWriter<Uint8Array>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars\n abort(reason?: any): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n async close(): Promise<void> {\n return;\n }\n getWriter(): WritableStreamDefaultWriter<Uint8Array> {\n if (this.locked) {\n throw new Error(\"Stream is locked\");\n }\n this.locked = true;\n if (!this._writer) {\n this._writer = new ConsoleWriterStreamDefaultWriter(this);\n }\n return this._writer;\n }\n}\n","export class FanoutWriteStream implements WritableStreamDefaultWriter<Uint8Array> {\n readonly _writers: WritableStreamDefaultWriter<Uint8Array>[];\n readonly ready: Promise<undefined>;\n readonly closed: Promise<undefined>;\n readonly desiredSize: number | null = null;\n constructor(writers: WritableStreamDefaultWriter<Uint8Array>[]) {\n this._writers = writers;\n this.ready = Promise.all(this._writers.map((w) => w.ready)).then(() => undefined);\n this.closed = Promise.all(this._writers.map((w) => w.closed)).then(() => undefined);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n abort(reason?: any): Promise<void> {\n return Promise.all(this._writers.map((w) => w.abort(reason))).then(() => {\n /* do nothing */\n });\n }\n close(): Promise<void> {\n return Promise.all(this._writers.map((w) => w.close())).then(() => {\n /* do nothing */\n });\n }\n releaseLock(): void {\n this._writers.map((w) => w.releaseLock());\n }\n\n write(chunk?: Uint8Array | undefined): Promise<void> {\n return Promise.all(this._writers.map((w) => w.write(chunk))).then(() => {\n /* do nothing */\n });\n }\n}\n"],"mappings":";;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,SAAS,UAAgB,GAAsB,IAAwC;AAC5F,QAAM,QAAQ,EAAE,QAAQ,EAAE,UAAU,GAAG,WAAW,IAAI,KAAK,EAAE;AAC7D,SAAO,IAAI,eAAkB;AAAA,IAC3B,MAAM,KAAK,YAA2B;AACpC,YAAM,EAAE,MAAM,MAAM,IAAI,MAAM,MAAM,OAAO,KAAK;AAChD,UAAI,MAAM;AACR,YAAI,MAA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 
1119
1119
  // src/uri.ts
1120
+ function coerceKey(key, def) {
1121
+ if (typeof key === "object") {
1122
+ const keys = Object.keys(key);
1123
+ if (keys.length !== 1) {
1124
+ throw new Error(`Invalid key: ${JSON.stringify(key)}`);
1125
+ }
1126
+ return { key: keys[0], def: key[keys[0]] };
1127
+ }
1128
+ return { key, def };
1129
+ }
1120
1130
  function falsy2undef(value) {
1121
1131
  return value === void 0 || value === null ? void 0 : value;
1122
1132
  }
@@ -1263,19 +1273,33 @@ function getParamResult(key, val, msgFn = (key2) => {
1263
1273
  return Result.Ok(val);
1264
1274
  }
1265
1275
  function getParamsResult(keys, getParam) {
1266
- const keyStrs = keys.flat().filter((k) => typeof k === "string");
1276
+ const keyDef = keys.flat().reduce(
1277
+ (acc, i) => {
1278
+ if (typeof i === "string") {
1279
+ acc.push({ key: i });
1280
+ } else if (typeof i === "object") {
1281
+ acc.push(...Object.keys(i).map((k) => ({ key: k, def: i[k] })));
1282
+ }
1283
+ return acc;
1284
+ },
1285
+ []
1286
+ );
1267
1287
  const msgFn = keys.find((k) => typeof k === "function") || ((...keys2) => {
1268
1288
  const msg = keys2.join(",");
1269
1289
  return `missing parameters: ${msg}`;
1270
1290
  });
1271
1291
  const errors = [];
1272
1292
  const result = {};
1273
- for (const key of keyStrs) {
1274
- const val = getParam.getParam(key);
1293
+ for (const kd of keyDef) {
1294
+ const val = getParam.getParam(kd.key);
1275
1295
  if (val === void 0) {
1276
- errors.push(key);
1296
+ if (kd.def) {
1297
+ result[kd.key] = kd.def;
1298
+ } else {
1299
+ errors.push(kd.key);
1300
+ }
1277
1301
  } else {
1278
- result[key] = val;
1302
+ result[kd.key] = val;
1279
1303
  }
1280
1304
  }
1281
1305
  if (errors.length) {
@@ -1367,10 +1391,14 @@ var BuildURI = class _BuildURI {
1367
1391
  hasParam(key) {
1368
1392
  return this._url.searchParams.has(key);
1369
1393
  }
1394
+ get getParams() {
1395
+ return this._url.searchParams.entries();
1396
+ }
1370
1397
  getParam(key, def) {
1371
- let val = this._url.searchParams.get(key);
1372
- if (!falsy2undef(val) && def) {
1373
- val = def;
1398
+ const { key: k, def: d } = coerceKey(key, def);
1399
+ let val = this._url.searchParams.get(k);
1400
+ if (!falsy2undef(val) && d) {
1401
+ val = d;
1374
1402
  }
1375
1403
  return falsy2undef(val);
1376
1404
  }
@@ -1393,6 +1421,9 @@ var BuildURI = class _BuildURI {
1393
1421
  asObj(...strips) {
1394
1422
  return this.URI().asObj(...strips);
1395
1423
  }
1424
+ clone() {
1425
+ return _BuildURI.from(this.toString());
1426
+ }
1396
1427
  URI() {
1397
1428
  return URI.from(this._url);
1398
1429
  }
@@ -1473,9 +1504,10 @@ var URI = class _URI {
1473
1504
  return this._url.searchParams.has(key);
1474
1505
  }
1475
1506
  getParam(key, def) {
1476
- let val = this._url.searchParams.get(key);
1477
- if (!falsy2undef(val) && def) {
1478
- val = def;
1507
+ const { key: k, def: d } = coerceKey(key, def);
1508
+ let val = this._url.searchParams.get(k);
1509
+ if (!falsy2undef(val) && d) {
1510
+ val = d;
1479
1511
  }
1480
1512
  return falsy2undef(val);
1481
1513
  }
@@ -1564,22 +1596,22 @@ var ConsoleWriterStreamDefaultWriter = class {
1564
1596
  this.closed = Promise.resolve(void 0);
1565
1597
  }
1566
1598
  async write(chunk) {
1567
- const str = this.decoder.decode(chunk).trimEnd();
1599
+ let strObj = this.decoder.decode(chunk).trimEnd();
1568
1600
  let output = "log";
1569
1601
  try {
1570
- const decode = JSON.parse(str);
1571
- output = decode.level;
1602
+ strObj = JSON.parse(strObj);
1603
+ output = strObj.level;
1572
1604
  } catch (e) {
1573
1605
  }
1574
1606
  switch (output) {
1575
1607
  case "error":
1576
- console.error(str);
1608
+ console.error(strObj);
1577
1609
  break;
1578
1610
  case "warn":
1579
- console.warn(str);
1611
+ console.warn(strObj);
1580
1612
  break;
1581
1613
  default:
1582
- console.log(str);
1614
+ console.log(strObj);
1583
1615
  }
1584
1616
  }
1585
1617
  };
@@ -1922,7 +1954,7 @@ var LoggerImpl = class _LoggerImpl {
1922
1954
  return this;
1923
1955
  }
1924
1956
  Bool(key, value) {
1925
- this._attributes[key] = logValue(!!value);
1957
+ this.coerceKey(key, !!value);
1926
1958
  return this;
1927
1959
  }
1928
1960
  Http(res, req, key) {
@@ -1975,12 +2007,19 @@ var LoggerImpl = class _LoggerImpl {
1975
2007
  this.Ref(key, () => URI.from(url).toString());
1976
2008
  return this;
1977
2009
  }
2010
+ coerceKey(key, value) {
2011
+ if (typeof key === "string") {
2012
+ this._attributes[key] = logValue(value);
2013
+ } else {
2014
+ this.Pair(key);
2015
+ }
2016
+ }
1978
2017
  Str(key, value) {
1979
- this._attributes[key] = logValue(value);
2018
+ this.coerceKey(key, value);
1980
2019
  return this;
1981
2020
  }
1982
2021
  Any(key, value) {
1983
- this._attributes[key] = logValue(value);
2022
+ this.coerceKey(key, value);
1984
2023
  return this;
1985
2024
  }
1986
2025
  Dur(key, nsec) {
@@ -1988,7 +2027,7 @@ var LoggerImpl = class _LoggerImpl {
1988
2027
  return this;
1989
2028
  }
1990
2029
  Uint64(key, value) {
1991
- this._attributes[key] = logValue(value);
2030
+ this.coerceKey(key, value);
1992
2031
  return this;
1993
2032
  }
1994
2033
  Int(key, value) {