@nxtedition/lib 23.11.0 → 23.11.2
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 +1 -1
- package/http.js +3 -1
- package/package.json +1 -1
- package/util/template/index-common.js +3 -3
- package/util/template/index-web.js +16 -14
- package/util/template/index.js +4 -2
- package/util/template/index.test.js +24 -0
- package/util/template/javascript.js +2 -2
- package/util/template/nextpressions.js +3 -3
package/couch.d.ts
CHANGED
package/http.js
CHANGED
|
@@ -334,7 +334,9 @@ export async function requestMiddleware(ctx, next) {
|
|
|
334
334
|
} finally {
|
|
335
335
|
pendingSet.delete(ctx)
|
|
336
336
|
|
|
337
|
-
if (
|
|
337
|
+
if (res.writableEnded || res.destroyed || res.stream?.destroyed) {
|
|
338
|
+
// Do nothing..
|
|
339
|
+
} else {
|
|
338
340
|
res.destroy()
|
|
339
341
|
ctx.logger?.warn({ req }, 'request destroyed')
|
|
340
342
|
}
|
package/package.json
CHANGED
|
@@ -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,
|
|
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,
|
|
21
|
-
js: getJavascriptCompiler({ ds, proxify, compiler, logger,
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
}
|
package/util/template/index.js
CHANGED
|
@@ -17,8 +17,10 @@ export function makeTemplateCompiler({ logger = globalThis.__nxt_lib_app?.logger
|
|
|
17
17
|
return commonMakeTemplateCompiler({
|
|
18
18
|
...args,
|
|
19
19
|
logger,
|
|
20
|
-
|
|
21
|
-
|
|
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,
|
|
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:
|
|
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,
|
|
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) =>
|
|
88
|
+
hasha: (options) => (value) => hasha(JSON.stringify(value), options || {}),
|
|
89
89
|
hashaint: (options) => (value) =>
|
|
90
|
-
parseInt(
|
|
90
|
+
parseInt(hasha(JSON.stringify(value), options || {}).slice(-13), 16),
|
|
91
91
|
return: () => (value) => value || RETURN,
|
|
92
92
|
add:
|
|
93
93
|
(...args) =>
|