@nxtedition/lib 23.11.0 → 23.11.1

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/couch.d.ts CHANGED
@@ -16,7 +16,7 @@ export interface CouchRequestOptions<Stream extends boolean = false> {
16
16
  body?: unknown
17
17
  headersTimeout?: number
18
18
  bodyTimeout?: number
19
- dispatcher: undici.Dispatcher
19
+ dispatcher?: undici.Dispatcher
20
20
  query?: {
21
21
  startkey?: string
22
22
  endkey?: string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "23.11.0",
3
+ "version": "23.11.1",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -7,7 +7,7 @@ import objectHash from 'object-hash'
7
7
  import { makeWeakCache } from '../../weakCache.js'
8
8
  import firstValueFrom from '../../rxjs/firstValueFrom.js'
9
9
 
10
- export function makeTemplateCompiler({ ds, proxify, logger, sha512, fetch }) {
10
+ export function makeTemplateCompiler({ ds, proxify, logger, platform }) {
11
11
  const compiler = {
12
12
  current: null,
13
13
  resolveTemplate,
@@ -17,8 +17,8 @@ export function makeTemplateCompiler({ ds, proxify, logger, sha512, fetch }) {
17
17
  }
18
18
 
19
19
  const compilers = {
20
- nxt: getNxtpressionsCompiler({ ds, logger, sha512 }),
21
- js: getJavascriptCompiler({ ds, proxify, compiler, logger, fetch }),
20
+ nxt: getNxtpressionsCompiler({ ds, logger, platform }),
21
+ js: getJavascriptCompiler({ ds, proxify, compiler, logger, platform }),
22
22
  }
23
23
 
24
24
  function inner(str) {
@@ -8,21 +8,23 @@ export function makeTemplateCompiler({ ds, proxify, logger = console }) {
8
8
  ds,
9
9
  proxify,
10
10
  logger,
11
- sha512: (data) => {
12
- throw new Error('sha512 is not supported')
13
- },
14
- fetch: async (resource, options) => {
15
- // eslint-disable-next-line no-undef
16
- const res = await window.fetch(resource, options)
17
- return {
18
- statusCode: res.status,
19
- headers: Object.fromEntries(res.headers.entries()),
20
- body: {
21
- text: async () => {
22
- return await res.text()
11
+ platform: {
12
+ hasha: (data) => {
13
+ throw new Error('hasha is not supported')
14
+ },
15
+ fetch: async (resource, options) => {
16
+ // eslint-disable-next-line no-undef
17
+ const res = await window.fetch(resource, options)
18
+ return {
19
+ statusCode: res.status,
20
+ headers: Object.fromEntries(res.headers.entries()),
21
+ body: {
22
+ text: async () => {
23
+ return await res.text()
24
+ },
23
25
  },
24
- },
25
- }
26
+ }
27
+ },
26
28
  },
27
29
  })
28
30
  }
@@ -17,8 +17,10 @@ export function makeTemplateCompiler({ logger = globalThis.__nxt_lib_app?.logger
17
17
  return commonMakeTemplateCompiler({
18
18
  ...args,
19
19
  logger,
20
- sha256: (data) => hashSync(data),
21
- fetch,
20
+ platform: {
21
+ hasha: hashSync,
22
+ fetch,
23
+ },
22
24
  })
23
25
  }
24
26
 
@@ -0,0 +1,24 @@
1
+ import { test } from 'node:test'
2
+ import assert from 'node:assert'
3
+ import { makeTemplateCompiler } from './index.js'
4
+
5
+ test('javascript', async () => {
6
+ const compiler = makeTemplateCompiler({
7
+ ds: {},
8
+ logger: console,
9
+ })
10
+
11
+ assert.strictEqual(
12
+ await compiler.resolveTemplate('{{#js _($.foo, foo => foo.toUpperCase()) }}', { foo: 'bar' }),
13
+ 'BAR',
14
+ )
15
+ })
16
+
17
+ test('nexpression', async () => {
18
+ const compiler = makeTemplateCompiler({
19
+ ds: {},
20
+ logger: console,
21
+ })
22
+
23
+ assert.strictEqual(await compiler.resolveTemplate('{{ foo }}', { foo: 'bar' }), 'bar')
24
+ })
@@ -222,7 +222,7 @@ function makeWrapper(expression) {
222
222
  return (value, suspend = true) => proxify(value, expression, handler, suspend)
223
223
  }
224
224
 
225
- export default function ({ ds, proxify, compiler, logger, fetch: fetchFn }) {
225
+ export default function ({ ds, proxify, compiler, logger, platform }) {
226
226
  class Expression {
227
227
  constructor(script, expression, args, observer) {
228
228
  this._expression = expression
@@ -468,7 +468,7 @@ export default function ({ ds, proxify, compiler, logger, fetch: fetchFn }) {
468
468
 
469
469
  _getFetch(resource, options, suspend) {
470
470
  const key = JSON.stringify({ resource, options })
471
- const entry = this._getEntry(key, FetchEntry, { resource, options, fetch: fetchFn })
471
+ const entry = this._getEntry(key, FetchEntry, { resource, options, fetch: platform.fetch })
472
472
 
473
473
  if (entry.refresh === null) {
474
474
  return null
@@ -25,7 +25,7 @@ function asFilter(transform, predicate, obj) {
25
25
  )
26
26
  }
27
27
 
28
- export default function ({ ds, logger, sha512 } = {}) {
28
+ export default function ({ ds, logger, platform: { hasha } } = {}) {
29
29
  const FILTERS = {
30
30
  // any
31
31
  ...asFilter(null, null, {
@@ -85,9 +85,9 @@ export default function ({ ds, logger, sha512 } = {}) {
85
85
  isString: () => (value) => fp.isString(value),
86
86
  ternary: (a, b) => (value) => (value ? a : b),
87
87
  cond: (a, b) => (value) => (value ? a : b),
88
- hasha: (options) => (value) => sha512(JSON.stringify(value), options || {}),
88
+ hasha: (options) => (value) => hasha(JSON.stringify(value), options || {}),
89
89
  hashaint: (options) => (value) =>
90
- parseInt(sha512(JSON.stringify(value), options || {}).slice(-13), 16),
90
+ parseInt(hasha(JSON.stringify(value), options || {}).slice(-13), 16),
91
91
  return: () => (value) => value || RETURN,
92
92
  add:
93
93
  (...args) =>