@tstdl/base 0.93.108 → 0.93.110
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/orm/sqls/sqls.js +5 -5
- package/package.json +4 -3
- package/process/spawn.d.ts +3 -3
- package/process/spawn.js +1 -1
- package/test5.d.ts +0 -12
- package/test5.js +9 -14
- package/typst/index.d.ts +1 -0
- package/typst/index.js +1 -0
- package/typst/render.d.ts +23 -0
- package/typst/render.js +32 -0
package/orm/sqls/sqls.js
CHANGED
|
@@ -8,7 +8,7 @@ import { and, Column, eq, isSQLWrapper, sql, isNotNull as sqlIsNotNull, isNull a
|
|
|
8
8
|
import { match, P } from 'ts-pattern';
|
|
9
9
|
import { distinct, toArray } from '../../utils/array/array.js';
|
|
10
10
|
import { objectEntries, objectValues } from '../../utils/object/object.js';
|
|
11
|
-
import { assertDefined, isArray, isBoolean, isDefined, isInstanceOf, isNotNull, isNull, isNumber, isObject, isString } from '../../utils/type-guards.js';
|
|
11
|
+
import { assertDefined, isArray, isBoolean, isDefined, isInstanceOf, isNotNull, isNull, isNullOrUndefined, isNumber, isObject, isString } from '../../utils/type-guards.js';
|
|
12
12
|
import { getEnumName } from '../enums.js';
|
|
13
13
|
import { caseWhen } from './case-when.js';
|
|
14
14
|
export const simpleJsonKeyPattern = /^[a-zA-Z0-9_-]+$/u;
|
|
@@ -405,10 +405,10 @@ export function jsonbBuildObject(properties) {
|
|
|
405
405
|
*/
|
|
406
406
|
export function buildJsonb(value) {
|
|
407
407
|
if (isSQLWrapper(value)) {
|
|
408
|
-
return sql
|
|
408
|
+
return sql `to_jsonb(${value})`;
|
|
409
409
|
}
|
|
410
|
-
if (
|
|
411
|
-
return sql `null`;
|
|
410
|
+
if (isNullOrUndefined(value)) {
|
|
411
|
+
return sql `'null'::jsonb`;
|
|
412
412
|
}
|
|
413
413
|
if (isArray(value)) {
|
|
414
414
|
if (value.length == 0) {
|
|
@@ -420,5 +420,5 @@ export function buildJsonb(value) {
|
|
|
420
420
|
if (isObject(value)) {
|
|
421
421
|
return jsonbBuildObject(value);
|
|
422
422
|
}
|
|
423
|
-
return sql `${value}`;
|
|
423
|
+
return sql `${JSON.stringify(value)}::jsonb`;
|
|
424
424
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.93.
|
|
3
|
+
"version": "0.93.110",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -101,8 +101,6 @@
|
|
|
101
101
|
"./pool": "./pool/index.js",
|
|
102
102
|
"./process": "./process/index.js",
|
|
103
103
|
"./promise": "./promise/index.js",
|
|
104
|
-
"./task-queue": "./task-queue/index.js",
|
|
105
|
-
"./task-queue/postgres": "./task-queue/postgres/index.js",
|
|
106
104
|
"./random": "./random/index.js",
|
|
107
105
|
"./rate-limit": "./rate-limit/index.js",
|
|
108
106
|
"./rate-limit/postgres": "./rate-limit/postgres/index.js",
|
|
@@ -120,6 +118,8 @@
|
|
|
120
118
|
"./signals": "./signals/index.js",
|
|
121
119
|
"./signals/implementation": "./signals/implementation/index.js",
|
|
122
120
|
"./sse": "./sse/index.js",
|
|
121
|
+
"./task-queue": "./task-queue/index.js",
|
|
122
|
+
"./task-queue/postgres": "./task-queue/postgres/index.js",
|
|
123
123
|
"./templates": "./templates/index.js",
|
|
124
124
|
"./templates/providers": "./templates/providers/index.js",
|
|
125
125
|
"./templates/renderers": "./templates/renderers/index.js",
|
|
@@ -128,6 +128,7 @@
|
|
|
128
128
|
"./text": "./text/index.js",
|
|
129
129
|
"./threading": "./threading/index.js",
|
|
130
130
|
"./types": "./types/index.js",
|
|
131
|
+
"./typst": "./typst/index.js",
|
|
131
132
|
"./unit-test": "./unit-test/index.js",
|
|
132
133
|
"./utils": "./utils/index.js",
|
|
133
134
|
"./utils/array": "./utils/array/index.js",
|
package/process/spawn.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
2
|
-
import type { Record } from '../types/types.js';
|
|
2
|
+
import type { Record, TypedOmit } from '../types/types.js';
|
|
3
3
|
type WaitReadResultFormat = 'string' | 'binary';
|
|
4
4
|
type WaitReadResultFormatType<T extends WaitReadResultFormat> = T extends 'string' ? string : Uint8Array<ArrayBuffer>;
|
|
5
5
|
export type WaitOptions = {
|
|
@@ -35,9 +35,9 @@ export type SpawnCommandResult = TransformStream<Uint8Array, Uint8Array> & {
|
|
|
35
35
|
export declare function spawnWaitCommand(command: string, args?: string[], options?: SpawnOptions & WaitOptions): Promise<WaitResult>;
|
|
36
36
|
export declare function spawnWaitCommand(command: string, options?: SpawnOptions & WaitOptions): Promise<WaitResult>;
|
|
37
37
|
/** spwans a command, waits for it to complete and reads its output */
|
|
38
|
-
export declare function spawnWaitReadCommand<F extends WaitReadResultFormat>(format: F, command: string, args?: string[], options?: SpawnOptions & WaitOptions): Promise<WaitReadResult<F>>;
|
|
38
|
+
export declare function spawnWaitReadCommand<F extends WaitReadResultFormat>(format: F, command: string, args?: string[], options?: TypedOmit<SpawnOptions, 'arguments'> & WaitOptions): Promise<WaitReadResult<F>>;
|
|
39
39
|
export declare function spawnWaitReadCommand<F extends WaitReadResultFormat>(format: F, command: string, options?: SpawnOptions & WaitOptions): Promise<WaitReadResult<F>>;
|
|
40
40
|
/** Spawns a command as a child process. */
|
|
41
|
-
export declare function spawnCommand(command: string, args?: string[], options?: SpawnOptions): Promise<SpawnCommandResult>;
|
|
41
|
+
export declare function spawnCommand(command: string, args?: string[], options?: TypedOmit<SpawnOptions, 'arguments'>): Promise<SpawnCommandResult>;
|
|
42
42
|
export declare function spawnCommand(command: string, options?: SpawnOptions): Promise<SpawnCommandResult>;
|
|
43
43
|
export {};
|
package/process/spawn.js
CHANGED
|
@@ -10,7 +10,7 @@ export async function spawnWaitCommand(command, argsOrOptions, optionsOrNothing)
|
|
|
10
10
|
return await process.wait({ throwOnNonZeroExitCode: options?.throwOnNonZeroExitCode });
|
|
11
11
|
}
|
|
12
12
|
export async function spawnWaitReadCommand(format, command, argsOrOptions, optionsOrNothing) {
|
|
13
|
-
const [args, options] = isArray(argsOrOptions) ? [argsOrOptions, optionsOrNothing] : [
|
|
13
|
+
const [args, options] = isArray(argsOrOptions) ? [argsOrOptions, optionsOrNothing] : [argsOrOptions?.arguments, argsOrOptions];
|
|
14
14
|
const process = await spawnCommand(command, args, options);
|
|
15
15
|
return await process.waitRead(format, { throwOnNonZeroExitCode: options?.throwOnNonZeroExitCode });
|
|
16
16
|
}
|
package/test5.d.ts
CHANGED
|
@@ -1,13 +1 @@
|
|
|
1
1
|
import './polyfills.js';
|
|
2
|
-
import type { NotificationDefinitionMap } from './notification/index.js';
|
|
3
|
-
export type Notifications = NotificationDefinitionMap<{
|
|
4
|
-
'analysis-started': {
|
|
5
|
-
payload: {
|
|
6
|
-
analysisId: string;
|
|
7
|
-
};
|
|
8
|
-
view: {
|
|
9
|
-
name: string;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
'analysis-completed': Record<never, never>;
|
|
13
|
-
}>;
|
package/test5.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
import './polyfills.js';
|
|
2
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
3
|
import { Application } from './application/application.js';
|
|
3
4
|
import { provideModule, provideSignalHandler } from './application/index.js';
|
|
4
|
-
import {
|
|
5
|
-
import { JsonLogFormatter, PrettyPrintLogFormatter } from './logger/index.js';
|
|
5
|
+
import { PrettyPrintLogFormatter } from './logger/index.js';
|
|
6
6
|
import { provideConsoleLogTransport } from './logger/transports/console.js';
|
|
7
|
-
import {
|
|
7
|
+
import { renderTypst } from './typst/render.js';
|
|
8
|
+
const template = `
|
|
9
|
+
I got an ice cream for
|
|
10
|
+
\\$1.50! \\u{1f600}
|
|
11
|
+
`;
|
|
8
12
|
async function main(_cancellationSignal) {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const notification$ = (await notificationApi.stream());
|
|
12
|
-
const tenantId = 'test-tenant';
|
|
13
|
-
const userId = 'user-123';
|
|
14
|
-
await notificationService.send(tenantId, userId, {
|
|
15
|
-
type: 'analysis-started',
|
|
16
|
-
triggerSubjectId: userId,
|
|
17
|
-
payload: { analysisId: 'analysis-456' },
|
|
18
|
-
});
|
|
13
|
+
const pdfBytes = await renderTypst(template, { format: 'docx' });
|
|
14
|
+
await writeFile('/tmp/output.docx', pdfBytes);
|
|
19
15
|
}
|
|
20
16
|
Application.run('Test', [
|
|
21
17
|
provideConsoleLogTransport(PrettyPrintLogFormatter),
|
|
22
|
-
provideConsoleLogTransport(JsonLogFormatter),
|
|
23
18
|
provideModule(main),
|
|
24
19
|
provideSignalHandler(),
|
|
25
20
|
]);
|
package/typst/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './render.js';
|
package/typst/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './render.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type TypstRenderOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* The root directory for resolving imports in the Typst source. If not specified, imports will be resolved relative to the location of the source file.
|
|
4
|
+
*/
|
|
5
|
+
root?: string;
|
|
6
|
+
/**
|
|
7
|
+
* The output format for the rendered document.
|
|
8
|
+
* Note: `docx` output uses pandoc under the hood, which does not support all Typst features.
|
|
9
|
+
* @default 'pdf'
|
|
10
|
+
*/
|
|
11
|
+
format?: 'pdf' | 'png' | 'svg' | 'html' | 'docx';
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Renders Typst source code to a file in the specified format.
|
|
15
|
+
*
|
|
16
|
+
* ## WARNING
|
|
17
|
+
* **This function should not be used with untrusted typst source, as it can lead to arbitrary code execution on the system.**
|
|
18
|
+
*
|
|
19
|
+
* Requires typst to be installed on the system.
|
|
20
|
+
* @param source
|
|
21
|
+
* @param options
|
|
22
|
+
*/
|
|
23
|
+
export declare function renderTypst(source: string, options?: TypstRenderOptions): Promise<Uint8Array>;
|
package/typst/render.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { spawnCommand } from '../process/spawn.js';
|
|
2
|
+
import { decodeText } from '../utils/encoding.js';
|
|
3
|
+
/**
|
|
4
|
+
* Renders Typst source code to a file in the specified format.
|
|
5
|
+
*
|
|
6
|
+
* ## WARNING
|
|
7
|
+
* **This function should not be used with untrusted typst source, as it can lead to arbitrary code execution on the system.**
|
|
8
|
+
*
|
|
9
|
+
* Requires typst to be installed on the system.
|
|
10
|
+
* @param source
|
|
11
|
+
* @param options
|
|
12
|
+
*/
|
|
13
|
+
export async function renderTypst(source, options) {
|
|
14
|
+
const format = options?.format ?? 'pdf';
|
|
15
|
+
const command = (format == 'docx') ? 'pandoc' : 'typst';
|
|
16
|
+
const args = (format == 'docx')
|
|
17
|
+
? ['--from', 'typst', '--to', 'docx', '--output', '-', '-']
|
|
18
|
+
: ['compile', '--format', format, '-', '-'];
|
|
19
|
+
const process = await spawnCommand(command, args);
|
|
20
|
+
const [{ code, output, error }] = await Promise.all([
|
|
21
|
+
process.waitRead('binary', { throwOnNonZeroExitCode: false }),
|
|
22
|
+
process.write(source),
|
|
23
|
+
]);
|
|
24
|
+
const errorString = decodeText(error);
|
|
25
|
+
if (code !== 0) {
|
|
26
|
+
throw new Error(`
|
|
27
|
+
Typst compilation failed with exit code ${code}.\n
|
|
28
|
+
Error Output:\n${errorString}
|
|
29
|
+
`.trim());
|
|
30
|
+
}
|
|
31
|
+
return output;
|
|
32
|
+
}
|