@tstdl/base 0.93.125 → 0.93.127

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.
Files changed (198) hide show
  1. package/ai/genkit/tests/multi-region.test.js +6 -6
  2. package/ai/index.d.ts +2 -6
  3. package/ai/index.js +2 -6
  4. package/ai/parser/index.d.ts +1 -0
  5. package/ai/parser/index.js +1 -0
  6. package/ai/parser/parser.d.ts +12 -0
  7. package/ai/parser/parser.js +28 -0
  8. package/ai/prompts/build.d.ts +21 -0
  9. package/ai/prompts/build.js +25 -0
  10. package/ai/prompts/index.d.ts +2 -0
  11. package/ai/prompts/index.js +2 -0
  12. package/ai/prompts/instructions-formatter.d.ts +9 -22
  13. package/ai/prompts/instructions-formatter.js +20 -7
  14. package/ai/prompts/instructions.js +1 -1
  15. package/ai/prompts/steering.d.ts +27 -0
  16. package/ai/prompts/steering.js +54 -0
  17. package/ai/tests/instructions-formatter.test.js +115 -0
  18. package/ai/tests/steering.test.js +37 -0
  19. package/application/application.d.ts +2 -1
  20. package/application/application.js +3 -0
  21. package/authentication/client/module.d.ts +1 -1
  22. package/authentication/client/module.js +4 -5
  23. package/authentication/tests/authentication-ancillary.service.test.js +1 -1
  24. package/authentication/tests/authentication.api-controller.test.js +3 -1
  25. package/authentication/tests/authentication.api-request-token.provider.test.js +1 -1
  26. package/authentication/tests/authentication.client-service.test.js +1 -1
  27. package/authentication/tests/authentication.service.test.js +1 -1
  28. package/authentication/tests/subject.service.test.js +1 -1
  29. package/circuit-breaker/tests/circuit-breaker.test.js +1 -1
  30. package/document-management/api/document-management.api.d.ts +16 -16
  31. package/document-management/api/document-management.api.js +12 -12
  32. package/document-management/models/ai-configuration.d.ts +59 -0
  33. package/document-management/models/ai-configuration.js +1 -0
  34. package/document-management/models/document-assignment-scope.model.js +2 -4
  35. package/document-management/models/document-assignment-task.model.js +2 -4
  36. package/document-management/models/document-collection-assignment.model.js +2 -4
  37. package/document-management/models/document-collection.model.js +2 -3
  38. package/document-management/models/document-content.model.d.ts +6 -0
  39. package/document-management/models/document-content.model.js +32 -0
  40. package/document-management/models/document-property-value.model.js +1 -2
  41. package/document-management/models/document-request-collection-assignment.model.js +2 -4
  42. package/document-management/models/document-request.model.js +2 -4
  43. package/document-management/models/document-tag-assignment.model.js +2 -3
  44. package/document-management/models/document-validation-execution-related-document.model.js +2 -4
  45. package/document-management/models/document-validation-execution.model.js +2 -5
  46. package/document-management/models/document-workflow.model.d.ts +2 -1
  47. package/document-management/models/document-workflow.model.js +4 -5
  48. package/document-management/models/document.model.js +2 -3
  49. package/document-management/models/index.d.ts +2 -0
  50. package/document-management/models/index.js +2 -0
  51. package/document-management/server/api/document-management.api.d.ts +7 -7
  52. package/document-management/server/api/document-management.api.js +9 -9
  53. package/document-management/server/configure.d.ts +4 -1
  54. package/document-management/server/configure.js +9 -4
  55. package/document-management/server/drizzle/{0000_complex_black_bird.sql → 0000_curious_nighthawk.sql} +7 -27
  56. package/document-management/server/drizzle/meta/0000_snapshot.json +12 -284
  57. package/document-management/server/drizzle/meta/_journal.json +2 -2
  58. package/document-management/server/module.d.ts +2 -0
  59. package/document-management/server/module.js +1 -0
  60. package/document-management/server/schemas.d.ts +2 -1
  61. package/document-management/server/services/document-file.service.d.ts +6 -6
  62. package/document-management/server/services/document-file.service.js +7 -81
  63. package/document-management/server/services/document-management-ai-provider.service.d.ts +66 -0
  64. package/document-management/server/services/document-management-ai-provider.service.js +2 -0
  65. package/document-management/server/services/document-management-ai.service.d.ts +44 -7
  66. package/document-management/server/services/document-management-ai.service.js +332 -329
  67. package/document-management/server/services/document-validation.service.d.ts +1 -1
  68. package/document-management/server/services/document-workflow.service.d.ts +4 -3
  69. package/document-management/server/services/document-workflow.service.js +26 -9
  70. package/document-management/server/services/document.service.d.ts +7 -3
  71. package/document-management/server/services/document.service.js +13 -4
  72. package/document-management/server/services/index.d.ts +1 -0
  73. package/document-management/server/services/index.js +1 -0
  74. package/document-management/server/validators/ai-validation-executor.d.ts +419 -12
  75. package/document-management/server/validators/ai-validation-executor.js +51 -46
  76. package/document-management/server/validators/single-document-validation-executor.d.ts +1 -3
  77. package/document-management/server/validators/single-document-validation-executor.js +2 -4
  78. package/document-management/service-models/document.service-model.d.ts +3 -3
  79. package/document-management/service-models/document.service-model.js +1 -1
  80. package/document-management/tests/ai-config-hierarchy.test.d.ts +1 -0
  81. package/document-management/tests/ai-config-hierarchy.test.js +64 -0
  82. package/document-management/tests/ai-config-integration.test.d.ts +1 -0
  83. package/document-management/tests/ai-config-integration.test.js +125 -0
  84. package/document-management/tests/ai-config-merge.test.d.ts +1 -0
  85. package/document-management/tests/ai-config-merge.test.js +38 -0
  86. package/document-management/tests/document-management-ai-overrides.test.d.ts +1 -0
  87. package/document-management/tests/document-management-ai-overrides.test.js +64 -0
  88. package/document-management/tests/document-management-core.test.js +6 -6
  89. package/document-management/tests/document-management.api.test.js +5 -5
  90. package/document-management/tests/document-statistics.service.test.js +10 -6
  91. package/document-management/tests/document-validation-ai-overrides.test.d.ts +1 -0
  92. package/document-management/tests/document-validation-ai-overrides.test.js +85 -0
  93. package/document-management/tests/document.service.test.js +15 -11
  94. package/document-management/tests/enum-helpers.test.js +5 -5
  95. package/examples/document-management/ai-provider.d.ts +20 -0
  96. package/examples/document-management/ai-provider.js +74 -0
  97. package/examples/document-management/main.js +9 -6
  98. package/examples/injector/graph-example.d.ts +1 -0
  99. package/examples/injector/graph-example.js +340 -0
  100. package/injector/decorators.d.ts +4 -4
  101. package/injector/decorators.js +5 -6
  102. package/injector/forward-ref.d.ts +15 -0
  103. package/injector/forward-ref.js +20 -0
  104. package/injector/graph.d.ts +113 -0
  105. package/injector/graph.js +652 -0
  106. package/injector/index.d.ts +2 -0
  107. package/injector/index.js +2 -0
  108. package/injector/inject.d.ts +15 -15
  109. package/injector/injector.d.ts +101 -13
  110. package/injector/injector.js +103 -59
  111. package/injector/resolve-chain.d.ts +20 -6
  112. package/injector/resolve-chain.js +39 -14
  113. package/injector/tests/advanced.test.d.ts +1 -0
  114. package/injector/tests/advanced.test.js +116 -0
  115. package/injector/tests/async-init.test.d.ts +1 -0
  116. package/injector/tests/async-init.test.js +77 -0
  117. package/injector/tests/basic.test.d.ts +1 -0
  118. package/injector/tests/basic.test.js +114 -0
  119. package/injector/tests/hierarchical.test.d.ts +1 -0
  120. package/injector/tests/hierarchical.test.js +59 -0
  121. package/injector/tests/lifecycles.test.d.ts +1 -0
  122. package/injector/tests/lifecycles.test.js +109 -0
  123. package/injector/token.d.ts +2 -1
  124. package/injector/token.js +4 -1
  125. package/injector/type-info.d.ts +1 -5
  126. package/injector/types.d.ts +4 -10
  127. package/logger/tests/pretty-print.test.d.ts +1 -0
  128. package/logger/{formatters → tests}/pretty-print.test.js +1 -1
  129. package/logger/transports/console.d.ts +3 -2
  130. package/logger/transports/console.js +4 -3
  131. package/notification/tests/notification-api.test.js +8 -5
  132. package/notification/tests/notification-client.test.d.ts +1 -0
  133. package/notification/tests/{unit/notification-client.test.js → notification-client.test.js} +5 -5
  134. package/notification/tests/notification-flow.test.js +6 -5
  135. package/notification/tests/notification-sse.service.test.js +1 -1
  136. package/notification/tests/notification-type.service.test.js +1 -1
  137. package/object-storage/s3/s3.object-storage.js +3 -0
  138. package/object-storage/s3/tests/s3.object-storage.integration.test.js +1 -1
  139. package/orm/tests/repository-attributes.test.js +10 -17
  140. package/orm/tests/repository-cti-mapping.test.js +2 -2
  141. package/orm/tests/repository-cti-soft-delete.test.js +1 -1
  142. package/orm/tests/repository-cti.test.js +19 -33
  143. package/orm/tests/repository-extra-coverage.test.js +1 -1
  144. package/orm/tests/repository-search.test.js +5 -2
  145. package/orm/tests/transaction-safety.test.js +1 -1
  146. package/package.json +7 -9
  147. package/rate-limit/tests/postgres-rate-limiter.test.js +6 -16
  148. package/renderer/d2.d.ts +77 -0
  149. package/renderer/d2.js +68 -0
  150. package/renderer/graphviz.d.ts +47 -0
  151. package/renderer/graphviz.js +58 -0
  152. package/renderer/index.d.ts +4 -0
  153. package/renderer/index.js +4 -0
  154. package/renderer/typst.d.ts +57 -0
  155. package/renderer/typst.js +62 -0
  156. package/rpc/adapters/readable-stream.adapter.d.ts +3 -0
  157. package/rpc/adapters/readable-stream.adapter.js +5 -1
  158. package/rpc/rpc.js +28 -3
  159. package/rpc/tests/rpc.integration.test.js +3 -1
  160. package/schema/schemas/nullable.js +1 -1
  161. package/task-queue/task-queue.d.ts +2 -0
  162. package/task-queue/task-queue.js +6 -2
  163. package/task-queue/tests/complex.test.js +1 -1
  164. package/task-queue/tests/dependencies.test.js +3 -3
  165. package/task-queue/tests/extensive-dependencies.test.js +1 -1
  166. package/task-queue/tests/queue.test.js +1 -1
  167. package/task-queue/tests/worker.test.js +4 -7
  168. package/test5.js +52 -8
  169. package/{unit-test → testing}/integration-setup.d.ts +1 -0
  170. package/{unit-test → testing}/integration-setup.js +13 -0
  171. package/utils/base64.d.ts +7 -0
  172. package/utils/base64.js +10 -1
  173. package/utils/noop.d.ts +7 -1
  174. package/utils/noop.js +7 -1
  175. package/ai/ai-file.service.d.ts +0 -57
  176. package/ai/ai-file.service.js +0 -233
  177. package/ai/ai-session.d.ts +0 -38
  178. package/ai/ai-session.js +0 -50
  179. package/ai/ai.service.d.ts +0 -126
  180. package/ai/ai.service.js +0 -481
  181. package/ai/functions.d.ts +0 -9
  182. package/ai/functions.js +0 -38
  183. package/ai/module.d.ts +0 -26
  184. package/ai/module.js +0 -25
  185. package/ai/types.d.ts +0 -229
  186. package/ai/types.js +0 -33
  187. package/latex/index.d.ts +0 -1
  188. package/latex/index.js +0 -1
  189. package/typst/index.d.ts +0 -1
  190. package/typst/index.js +0 -1
  191. package/typst/render.d.ts +0 -23
  192. package/typst/render.js +0 -32
  193. /package/{logger/formatters/pretty-print.test.d.ts → ai/tests/instructions-formatter.test.d.ts} +0 -0
  194. /package/{notification/tests/unit/notification-client.test.d.ts → ai/tests/steering.test.d.ts} +0 -0
  195. /package/{latex/render.d.ts → renderer/latex.d.ts} +0 -0
  196. /package/{latex/render.js → renderer/latex.js} +0 -0
  197. /package/{unit-test → testing}/index.d.ts +0 -0
  198. /package/{unit-test → testing}/index.js +0 -0
package/ai/functions.js DELETED
@@ -1,38 +0,0 @@
1
- import { convertToOpenApiSchema } from '../schema/converters/open-api-converter.js';
2
- import { FunctionSchema, getObjectSchema, object } from '../schema/index.js';
3
- import { fromEntries, objectEntries } from '../utils/object/object.js';
4
- import { isNotNull, isNull, isString } from '../utils/type-guards.js';
5
- /**
6
- * Extracts Google AI function declarations from a class decorated with schema information.
7
- * It iterates over the properties of the class schema and converts `FunctionSchema` instances
8
- * into the format required by the Google Generative AI API.
9
- * @param type The constructor of the class to extract function declarations from.
10
- */
11
- export function getFunctionDeclarations(type) {
12
- const objectSchema = getObjectSchema(type);
13
- return objectEntries(objectSchema.properties)
14
- .map(([key, schema]) => {
15
- if (!(schema instanceof FunctionSchema)) {
16
- return null;
17
- }
18
- return {
19
- name: `${type.name}.${key}`,
20
- description: schema.description ?? undefined,
21
- parameters: isNull(schema.parameterSchemas)
22
- ? undefined
23
- : getFunctionDeclarationParameters(schema),
24
- };
25
- })
26
- .filter(isNotNull);
27
- }
28
- function getFunctionDeclarationParameters(functionSchema) {
29
- const entries = functionSchema.parameterSchemas.map((schema, index) => {
30
- const parameterName = functionSchema.parameterNames[index];
31
- if (!isString(parameterName)) {
32
- throw new Error(`Parameter ${index} requires a name.`);
33
- }
34
- return [parameterName, schema];
35
- });
36
- const parametersSchema = object(fromEntries(entries));
37
- return convertToOpenApiSchema(parametersSchema);
38
- }
package/ai/module.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import type { AiModel } from './types.js';
2
- /**
3
- * Options for configuring the AI Module.
4
- */
5
- export declare class AiModuleOptions {
6
- /** Google AI API key. */
7
- apiKey?: string;
8
- /** Path to the Google Cloud credentials file. */
9
- keyFile?: string;
10
- /** Vertex AI specific options. If provided, the service will use Vertex AI endpoints. */
11
- vertex?: {
12
- project: string;
13
- location: string;
14
- bucket?: string;
15
- };
16
- /**
17
- * The default model to use for generation requests.
18
- * @default 'small'
19
- */
20
- defaultModel?: AiModel;
21
- }
22
- /**
23
- * Configures the {@link AiService}.
24
- * @param options The configuration options for the AI services.
25
- */
26
- export declare function configureAiService(options: AiModuleOptions): void;
package/ai/module.js DELETED
@@ -1,25 +0,0 @@
1
- import { Injector } from '../injector/injector.js';
2
- /**
3
- * Options for configuring the AI Module.
4
- */
5
- export class AiModuleOptions {
6
- /** Google AI API key. */
7
- apiKey;
8
- /** Path to the Google Cloud credentials file. */
9
- keyFile;
10
- /** Vertex AI specific options. If provided, the service will use Vertex AI endpoints. */
11
- vertex;
12
- /**
13
- * The default model to use for generation requests.
14
- * @default 'small'
15
- */
16
- defaultModel;
17
- }
18
- ;
19
- /**
20
- * Configures the {@link AiService}.
21
- * @param options The configuration options for the AI services.
22
- */
23
- export function configureAiService(options) {
24
- Injector.register(AiModuleOptions, { useValue: options });
25
- }
package/ai/types.d.ts DELETED
@@ -1,229 +0,0 @@
1
- import type { LiteralUnion } from 'type-fest';
2
- import type { ObjectSchema, SchemaOutput, SchemaTestable } from '../schema/index.js';
3
- import type { Record, UndefinableJsonObject } from '../types/index.js';
4
- import type { ResolvedValueOrProvider, ValueOrAsyncProvider } from '../utils/value-or-provider.js';
5
- /**
6
- * Represents a file to be uploaded, either from a local path or as a `Blob`.
7
- */
8
- export type FileInput = {
9
- path: string;
10
- mimeType: string;
11
- } | {
12
- stream: ReadableStream<Uint8Array>;
13
- mimeType: string;
14
- size?: number;
15
- } | Blob;
16
- /**
17
- * A record of named function declarations, where each key is the function name.
18
- */
19
- export type SchemaFunctionDeclarations = Record<string, SchemaFunctionDeclaration<any>>;
20
- /**
21
- * A function declaration that only defines the function's signature (name, description, parameters).
22
- * @template T The record type for the function's parameters.
23
- */
24
- export type SchemaFunctionDeclarationWithoutHandler<T extends Record = Record> = {
25
- description: string;
26
- parameters?: ValueOrAsyncProvider<ObjectSchema<T>>;
27
- enabled?: ValueOrAsyncProvider<boolean>;
28
- };
29
- /**
30
- * A function declaration that includes a handler to be executed when the function is called by the model.
31
- * @template T The record type for the function's parameters.
32
- * @template R The return type of the handler.
33
- */
34
- export type SchemaFunctionDeclarationWithHandler<T extends Record = Record, R = unknown> = SchemaFunctionDeclarationWithoutHandler<T> & {
35
- handler: (parameters: T) => R | Promise<R>;
36
- };
37
- /**
38
- * A union of a function declaration with or without a handler.
39
- * @template T The record type for the function's parameters.
40
- * @template R The return type of the handler if it exists.
41
- */
42
- export type SchemaFunctionDeclaration<T extends Record = Record, R = unknown> = SchemaFunctionDeclarationWithoutHandler<T> | SchemaFunctionDeclarationWithHandler<T, R>;
43
- /**
44
- * Extracts the return type of a function declaration's handler.
45
- * If the declaration has no handler, it resolves to `never`.
46
- * @template T The function declaration type.
47
- */
48
- export type SchemaFunctionDeclarationHandlerResult<T extends SchemaFunctionDeclaration> = T extends SchemaFunctionDeclarationWithHandler<any, infer R> ? R : never;
49
- /**
50
- * Represents the result of a function call, typed based on the provided declarations.
51
- * This is a distributive conditional type that maps over the function declarations.
52
- * @template T The schema declarations for the available functions.
53
- */
54
- export type SchemaFunctionDeclarationsResult<T extends SchemaFunctionDeclarations = SchemaFunctionDeclarations> = {
55
- [P in keyof T]: {
56
- /** The name of the function that was called. */
57
- functionName: P;
58
- /** The parameters passed to the function call, parsed against the schema. */
59
- parameters: SchemaOutput<NonNullable<ResolvedValueOrProvider<T[P]['parameters']>>>;
60
- /** The result of executing the handler, if one was provided. */
61
- handlerResult: SchemaFunctionDeclarationHandlerResult<T[P]>;
62
- /** A function to get the content part representing the function result, for use in subsequent AI requests. */
63
- getFunctionResultContentPart: () => FunctionResultContentPart;
64
- };
65
- }[keyof T];
66
- /**
67
- * The role of the author of a piece of content.
68
- */
69
- export type ContentRole = 'user' | 'model';
70
- /** A part of a `Content` object containing text. */
71
- export type TextContentPart = {
72
- text: string;
73
- };
74
- /** A part of a `Content` object referencing a processed file via its ID. */
75
- export type FileContentPart = {
76
- file: string;
77
- };
78
- /** Represents a function call requested by the model. */
79
- export type FunctionCall = {
80
- name: string;
81
- parameters: UndefinableJsonObject;
82
- };
83
- /** A part of a `Content` object representing a function call request from the model. */
84
- export type FunctionCallContentPart = {
85
- functionCall: FunctionCall;
86
- };
87
- /** The result of a function execution. */
88
- export type FunctionResult = {
89
- name: string;
90
- value: UndefinableJsonObject;
91
- };
92
- /** A part of a `Content` object representing the result of a function call. */
93
- export type FunctionResultContentPart = {
94
- functionResult: FunctionResult;
95
- };
96
- /** A union of all possible content part types. */
97
- export type ContentPart = TextContentPart | FileContentPart | FunctionCallContentPart | FunctionResultContentPart;
98
- /** A single message in a conversation, containing a role and one or more parts. */
99
- export type Content = {
100
- role: ContentRole;
101
- parts: readonly ContentPart[];
102
- };
103
- /**
104
- * Specifies the mode for function calling.
105
- * - `auto`: The model decides whether to call a function.
106
- * - `force`: The model is forced to call a function.
107
- * - `none`: The model will not call any functions.
108
- */
109
- export type FunctionCallingMode = 'auto' | 'force' | 'none';
110
- /**
111
- * The reason why the model stopped generating content.
112
- */
113
- export type FinishReason = 'stop' | 'maxTokens' | 'unknown';
114
- /**
115
- * The specific AI model to use for a request.
116
- *
117
- * Aliases `small`, `medium`, and `large` map to models that change over time.
118
- */
119
- export type AiModel = LiteralUnion<'small' | 'medium' | 'large' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-lite', string>;
120
- /**
121
- * Options to control the generation process.
122
- */
123
- export type GenerationOptions = {
124
- /** The maximum number of tokens to generate in the response. */
125
- maxOutputTokens?: number;
126
- /** Controls the randomness of the output. Higher values (closer to 1.0) make the output more random. */
127
- temperature?: number;
128
- /** The cumulative probability of tokens to consider for sampling. */
129
- topP?: number;
130
- /** The number of highest-probability tokens to consider for sampling. */
131
- topK?: number;
132
- /** A penalty for tokens that have already appeared in the text. */
133
- presencePenalty?: number;
134
- /** A penalty for tokens based on their frequency in the text. */
135
- frequencyPenalty?: number;
136
- /**
137
- * The maximum number of tokens the model is allowed to generate for its thinking phase.
138
- */
139
- thinkingBudget?: number;
140
- /**
141
- * Whether to include the model's internal thoughts in the response.
142
- */
143
- includeThoughts?: boolean;
144
- };
145
- /**
146
- * A request to generate content from the AI model.
147
- * @template S The expected type of the `json` property in the result if `generationSchema` is provided.
148
- */
149
- export type GenerationRequest<S = unknown> = {
150
- /** The model to use for the request. If not provided, a default will be used. */
151
- model?: AiModel;
152
- /** A system instruction to guide the model's behavior. */
153
- systemInstruction?: string;
154
- /** The content or conversation history to send to the model. */
155
- contents: Content | readonly Content[];
156
- /** A set of functions the model can call. */
157
- functions?: SchemaFunctionDeclarations;
158
- /** The mode for function calling. */
159
- functionCallingMode?: FunctionCallingMode;
160
- /** A schema to which the model's output should conform. Implies `responseMimeType: 'application/json'`. */
161
- generationSchema?: SchemaTestable<S>;
162
- /** Options to control the generation process. */
163
- generationOptions?: GenerationOptions;
164
- };
165
- /**
166
- * Token usage statistics for a generation request.
167
- */
168
- export type GenerationUsage = {
169
- /** The number of generation iterations (usually 1, more if `maxOutputTokens` is hit and generation continues). */
170
- iterations: number;
171
- /** Tokens cached. */
172
- cached: number;
173
- /** Tokens used in the prompt. */
174
- prompt: number;
175
- /** Tokens used for internal thoughts. */
176
- thoughts: number;
177
- /** Tokens in the generated output. */
178
- output: number;
179
- /** Tokens used for tools. */
180
- tools: number;
181
- /** Total tokens used. */
182
- total: number;
183
- };
184
- /**
185
- * The result of a generation request.
186
- * @template S The expected type of the `json` property if a schema was provided in the request.
187
- */
188
- export type GenerationResult<S = unknown> = {
189
- /** The content generated by the model. */
190
- content: Content;
191
- /** The complete text generated by the model, or `null` if no text was generated. */
192
- text: string | null;
193
- /** The text parsed as JSON, conforming to the provided schema. `undefined` if no schema was provided. */
194
- json: S;
195
- /** An array of function calls requested by the model. */
196
- functionCalls: FunctionCall[];
197
- /** The reason why the model stopped generating. */
198
- finishReason: FinishReason;
199
- /** Token usage statistics for the request. */
200
- usage: GenerationUsage;
201
- };
202
- /**
203
- * A helper function to define a set of function declarations with strong type inference.
204
- * @param declarations A record of function declarations.
205
- * @returns The same record of declarations, with types preserved.
206
- */
207
- export declare function defineFunctions<T extends SchemaFunctionDeclarations>(declarations: T): T;
208
- /**
209
- * A helper function to define a single function declaration with strong type inference,
210
- * particularly for its parameters.
211
- * @param declaration The function declaration.
212
- * @returns The same declaration, with types preserved.
213
- */
214
- export declare function defineFunction<P extends Record, T extends SchemaFunctionDeclaration<P>>(declaration: T & Pick<SchemaFunctionDeclaration<P>, 'parameters'>): T;
215
- /**
216
- * A type guard to check if a function declaration includes a handler.
217
- * @param declaration The function declaration to check.
218
- * @returns `true` if the declaration has a `handler` property, `false` otherwise.
219
- */
220
- export declare function isSchemaFunctionDeclarationWithHandler(declaration: SchemaFunctionDeclaration): declaration is SchemaFunctionDeclarationWithHandler;
221
- export declare function isPathFileInput(input: FileInput): input is {
222
- path: string;
223
- mimeType: string;
224
- };
225
- export declare function isStreamFileInput(input: FileInput): input is {
226
- stream: ReadableStream<Uint8Array>;
227
- mimeType: string;
228
- size?: number;
229
- };
package/ai/types.js DELETED
@@ -1,33 +0,0 @@
1
- import { hasOwnProperty } from '../utils/object/object.js';
2
- import { isBlob } from '../utils/type-guards.js';
3
- /**
4
- * A helper function to define a set of function declarations with strong type inference.
5
- * @param declarations A record of function declarations.
6
- * @returns The same record of declarations, with types preserved.
7
- */
8
- export function defineFunctions(declarations) {
9
- return declarations;
10
- }
11
- /**
12
- * A helper function to define a single function declaration with strong type inference,
13
- * particularly for its parameters.
14
- * @param declaration The function declaration.
15
- * @returns The same declaration, with types preserved.
16
- */
17
- export function defineFunction(declaration) {
18
- return declaration;
19
- }
20
- /**
21
- * A type guard to check if a function declaration includes a handler.
22
- * @param declaration The function declaration to check.
23
- * @returns `true` if the declaration has a `handler` property, `false` otherwise.
24
- */
25
- export function isSchemaFunctionDeclarationWithHandler(declaration) {
26
- return hasOwnProperty(declaration, 'handler');
27
- }
28
- export function isPathFileInput(input) {
29
- return !isBlob(input) && hasOwnProperty(input, 'path');
30
- }
31
- export function isStreamFileInput(input) {
32
- return !isBlob(input) && hasOwnProperty(input, 'stream');
33
- }
package/latex/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './render.js';
package/latex/index.js DELETED
@@ -1 +0,0 @@
1
- export * from './render.js';
package/typst/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './render.js';
package/typst/index.js DELETED
@@ -1 +0,0 @@
1
- export * from './render.js';
package/typst/render.d.ts DELETED
@@ -1,23 +0,0 @@
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<ArrayBuffer>>;
package/typst/render.js DELETED
@@ -1,32 +0,0 @@
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
- }
File without changes
File without changes
File without changes
File without changes