@mgamadeus/ddd-web 0.0.0-stage → 0.2.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/codegen/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { parseArgs } from 'node:util';\nimport { generateSdk } from './generate';\nimport { linkSkills } from './link-skills';\nimport { consoleLogger, SdkGenerationError } from './log';\n\nconst HELP = `Usage:\n ddd-web-sdk [options] Generate the RTK Query SDK (same as \"ddd-web sdk\")\n ddd-web sdk [options]\n ddd-web link-skills Symlink the package's agent skills into .claude/skills/\n\nSDK options:\n --config <path> Config file (default: openapi-config.ts)\n --api <exportName> Generate only this api entry\n --schema <url|file> Spec source for the selected api (overrides schemaFile)\n --workspace <value> Value for config.workspace.envVar (alias: --subdomain)\n --skip-prettier Do not format the generated files\n --skip-tsc Do not run tsc --noEmit after generation\n -h, --help Show this help\n`;\n\nasync function main(argv: string[]): Promise<number> {\n const [first, ...rest] = argv;\n const command = first === 'sdk' || first === 'link-skills' || first === 'help' ? first : 'sdk';\n const args = command === first ? rest : argv;\n\n if (command === 'help') {\n process.stdout.write(HELP);\n return 0;\n }\n if (command === 'link-skills') {\n linkSkills();\n return 0;\n }\n\n const { values } = parseArgs({\n args,\n options: {\n config: { type: 'string' },\n api: { type: 'string' },\n schema: { type: 'string' },\n workspace: { type: 'string' },\n subdomain: { type: 'string' },\n 'skip-prettier': { type: 'boolean' },\n 'skip-tsc': { type: 'boolean' },\n help: { type: 'boolean', short: 'h' },\n },\n strict: true,\n });\n if (values.help) {\n process.stdout.write(HELP);\n return 0;\n }\n const workspace = values.workspace ?? values.subdomain;\n await generateSdk({\n ...(values.config ? { config: values.config } : {}),\n ...(values.api ? { api: values.api } : {}),\n ...(values.schema ? { schema: values.schema } : {}),\n ...(workspace ? { workspace } : {}),\n skipPrettier: values['skip-prettier'] ?? false,\n skipTsc: values['skip-tsc'] ?? false,\n });\n return 0;\n}\n\nmain(process.argv.slice(2)).then(\n (code) => process.exit(code),\n (error: unknown) => {\n if (error instanceof SdkGenerationError || (error as { code?: string }).code === 'ERR_PARSE_ARGS_UNKNOWN_OPTION') {\n consoleLogger.error((error as Error).message);\n } else {\n consoleLogger.error(error instanceof Error ? (error.stack ?? error.message) : String(error));\n }\n process.exit(1);\n },\n);\n"],"mappings":";;;;;;;;;AACA,SAAS,iBAAiB;AAK1B,IAAM,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeb,eAAe,KAAK,MAAiC;AACnD,QAAM,CAAC,OAAO,GAAG,IAAI,IAAI;AACzB,QAAM,UAAU,UAAU,SAAS,UAAU,iBAAiB,UAAU,SAAS,QAAQ;AACzF,QAAM,OAAO,YAAY,QAAQ,OAAO;AAExC,MAAI,YAAY,QAAQ;AACtB,YAAQ,OAAO,MAAM,IAAI;AACzB,WAAO;AAAA,EACT;AACA,MAAI,YAAY,eAAe;AAC7B,eAAW;AACX,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,OAAO,IAAI,UAAU;AAAA,IAC3B;AAAA,IACA,SAAS;AAAA,MACP,QAAQ,EAAE,MAAM,SAAS;AAAA,MACzB,KAAK,EAAE,MAAM,SAAS;AAAA,MACtB,QAAQ,EAAE,MAAM,SAAS;AAAA,MACzB,WAAW,EAAE,MAAM,SAAS;AAAA,MAC5B,WAAW,EAAE,MAAM,SAAS;AAAA,MAC5B,iBAAiB,EAAE,MAAM,UAAU;AAAA,MACnC,YAAY,EAAE,MAAM,UAAU;AAAA,MAC9B,MAAM,EAAE,MAAM,WAAW,OAAO,IAAI;AAAA,IACtC;AAAA,IACA,QAAQ;AAAA,EACV,CAAC;AACD,MAAI,OAAO,MAAM;AACf,YAAQ,OAAO,MAAM,IAAI;AACzB,WAAO;AAAA,EACT;AACA,QAAM,YAAY,OAAO,aAAa,OAAO;AAC7C,QAAM,YAAY;AAAA,IAChB,GAAI,OAAO,SAAS,EAAE,QAAQ,OAAO,OAAO,IAAI,CAAC;AAAA,IACjD,GAAI,OAAO,MAAM,EAAE,KAAK,OAAO,IAAI,IAAI,CAAC;AAAA,IACxC,GAAI,OAAO,SAAS,EAAE,QAAQ,OAAO,OAAO,IAAI,CAAC;AAAA,IACjD,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;AAAA,IACjC,cAAc,OAAO,eAAe,KAAK;AAAA,IACzC,SAAS,OAAO,UAAU,KAAK;AAAA,EACjC,CAAC;AACD,SAAO;AACT;AAEA,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC,EAAE;AAAA,EAC1B,CAAC,SAAS,QAAQ,KAAK,IAAI;AAAA,EAC3B,CAAC,UAAmB;AAClB,QAAI,iBAAiB,sBAAuB,MAA4B,SAAS,iCAAiC;AAChH,oBAAc,MAAO,MAAgB,OAAO;AAAA,IAC9C,OAAO;AACL,oBAAc,MAAM,iBAAiB,QAAS,MAAM,SAAS,MAAM,UAAW,OAAO,KAAK,CAAC;AAAA,IAC7F;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;","names":[]}
@@ -0,0 +1,342 @@
1
+ /**
2
+ * Filter operators of the DDD `filters` grammar.
3
+ *
4
+ * Mirrors `FiltersOptions::OPERATORS` in DDD Core: two-letter, case-insensitive operators. Comparison operators take a
5
+ * single scalar, list operators take a list (`bw` exactly two items), fulltext operators take a non-empty search string.
6
+ */
7
+ type ComparisonOperator = 'eq' | 'ne' | 'gt' | 'ge' | 'lt' | 'le';
8
+ /** Operators whose value is a list: `in`, `ni` (not in), `bw` (between, exactly two items). */
9
+ type ListOperator = 'in' | 'ni' | 'bw';
10
+ /** Fulltext operators (MATCH AGAINST): `ft` natural language mode, `fb` boolean mode. */
11
+ type FulltextOperator = 'ft' | 'fb';
12
+ /** Every operator the backend parser accepts. */
13
+ type FilterOperator = ComparisonOperator | ListOperator | FulltextOperator;
14
+
15
+ /**
16
+ * Types of the `x-ddd-*` OpenAPI extensions emitted by DDD Core, plus the defaults that apply when an extension is
17
+ * absent. All extensions are additive: a document without them is valid and is read with the defaults below.
18
+ */
19
+ /** `info.x-ddd-contract`: contract number and the emitting `mgamadeus/ddd` version. */
20
+ interface DddContractInfo {
21
+ /** Contract number; bumped on every change of an `x-ddd-*` key, an implicit part or a default. */
22
+ contract: number;
23
+ /** Version of the `mgamadeus/ddd` package that emitted the document, e.g. `3.14.0`. */
24
+ ddd: string;
25
+ }
26
+ /**
27
+ * Column kind of a filter (`FiltersDefinition::COLUMN_KIND_*`): what a filter value is validated and bound as.
28
+ * `translatable` is a plain `#[Translatable]` (JSON of all languages), `translatable-searchable` one with
29
+ * `fullTextIndex: true` (comparisons run on its virtual search column).
30
+ */
31
+ type DddColumnKind = 'int' | 'float' | 'bool' | 'string' | 'datetime' | 'json' | 'translatable' | 'translatable-searchable';
32
+ /**
33
+ * Temporal kind of a filter (`FiltersDefinition::TEMPORAL_KIND_*`): `MOMENT` = an instant (date-time),
34
+ * `DAY` = a calendar day (date, never zone-converted).
35
+ */
36
+ type DddTemporalKind = 'MOMENT' | 'DAY';
37
+ /**
38
+ * A value rule for one operator of a filter. Known rules:
39
+ * - `wildcard-required`: the value must contain `*` (plain Translatable `eq` / `ne`, a LIKE on the JSON text);
40
+ * - `null-only`: only a null comparison is allowed (JSON columns).
41
+ * Further rules may be added by the contract; unknown rules must be ignored by clients.
42
+ */
43
+ type DddFilterValueRule = 'wildcard-required' | 'null-only' | (string & {});
44
+ /** One filter definition inside `x-ddd-query.filters`. */
45
+ interface DddFilterDefinition {
46
+ /** Filter property name as used in `filters`, may be dotted (e.g. `author.name`). */
47
+ name: string;
48
+ /** Path of the filtered value in the response schema (e.g. `changeHistory.createdTime`); `null` if none. */
49
+ path?: string | null;
50
+ /** Column kind; absent or `null` = no value validation on the backend. */
51
+ columnKind?: DddColumnKind | null;
52
+ /** Temporal kind; absent or `null` = not temporal. */
53
+ temporalKind?: DddTemporalKind | null;
54
+ /** Whether `ft` / `fb` work on this filter (single-column FULLTEXT index). */
55
+ supportsFulltext?: boolean;
56
+ /** Allowed values (`FiltersDefinition::$options`); every value, also each list item, must be one of them. */
57
+ options?: Array<string | number> | null;
58
+ /** Operators allowed for this filter; absent = every operator the column kind accepts. */
59
+ operators?: FilterOperator[];
60
+ /** Value rules per operator. */
61
+ valueRules?: Partial<Record<FilterOperator, DddFilterValueRule>>;
62
+ /** Name of the expand that must be present in `expand` for this filter to be accepted; absent = none. */
63
+ requiresExpand?: string | null;
64
+ }
65
+ /** One expand definition inside `x-ddd-query.expand`. */
66
+ interface DddExpandDefinition {
67
+ /** Property name to expand (no dots; nesting goes through `expand`). */
68
+ name: string;
69
+ /** `true` for a computed field (no relation, no clauses), e.g. a rendered SVG. */
70
+ computed?: boolean;
71
+ /** Default `top` inside the expand clause. */
72
+ top?: number;
73
+ /** Upper bound for `top` inside the expand clause. */
74
+ maxTop?: number | null;
75
+ /** Default `skip` inside the expand clause. */
76
+ skip?: number;
77
+ /** Filters available inside the expand clause (`filters=` in `(…)`). */
78
+ filters?: DddFilterDefinition[];
79
+ /** Sortable properties inside the expand clause. */
80
+ orderBy?: string[];
81
+ /** Nested expands (`expand=` in `(…)`). */
82
+ expand?: DddExpandDefinition[];
83
+ }
84
+ /** `x-ddd-query` on an operation whose request DTO applies QueryOptions. */
85
+ interface DddQueryDefinition {
86
+ filters?: DddFilterDefinition[];
87
+ /** Sortable property names. */
88
+ orderBy?: string[];
89
+ expand?: DddExpandDefinition[];
90
+ /** `true` = `select` accepted (any property), a list = the selectable properties, `false`/absent = not exposed. */
91
+ select?: boolean | string[];
92
+ /** Default page size (backend default 50). */
93
+ top?: number;
94
+ /** Upper bound for `top` (`#[QueryOptions(maxTop: …)]`); a larger `top` answers 400. */
95
+ maxTop?: number | null;
96
+ }
97
+ /** `x-ddd-entity.action`. DDD `#[Update]` is an upsert. */
98
+ type DddEntityAction = 'list' | 'get' | 'upsert' | 'delete' | 'action';
99
+ /** `x-ddd-entity` on an operation. Absent = unknown entity, clients invalidate conservatively. */
100
+ interface DddEntityInfo {
101
+ /** Entity schema name, e.g. `App.Domain.Library.Entities.Books.Book`. */
102
+ schema: string;
103
+ action: DddEntityAction;
104
+ /** Identity source, `path:<parameter>` or `body:<dotted.path>` (e.g. `body:book.id`). */
105
+ identity?: string;
106
+ /** `true` when derived by DDD Core, `false` when set explicitly via `#[OperationEntity]`. */
107
+ derived: boolean;
108
+ }
109
+ /** Extensions on an operation object. */
110
+ interface DddOperationExtensions {
111
+ 'x-ddd-query'?: DddQueryDefinition;
112
+ /** Absent = default by HTTP method (see {@link hasSideEffects}). */
113
+ 'x-ddd-side-effects'?: boolean;
114
+ 'x-ddd-entity'?: DddEntityInfo;
115
+ /** Cache TTL in seconds from `#[RequestCache]`. */
116
+ 'x-ddd-cache-ttl'?: number;
117
+ }
118
+ /** HTTP methods of OpenAPI operations (lowercase or uppercase accepted by the helpers). */
119
+ type HttpMethod = 'get' | 'head' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace';
120
+
121
+ /** Minimal OpenAPI 3 shapes the codegen reads. Unknown keys are passed through untouched. */
122
+
123
+ /**
124
+ * `info.x-ddd-contract` as read from a document: the contract types from `contract`, tolerant of a missing `ddd`
125
+ * version (the codegen only needs the contract number).
126
+ */
127
+ type DddContractInfoInput = Pick<DddContractInfo, 'contract'> & Partial<Pick<DddContractInfo, 'ddd'>>;
128
+ /** `x-ddd-entity` as read from a document: {@link DddEntityInfo}, tolerant of a missing `derived` flag. */
129
+ type DddEntityExtension = Omit<DddEntityInfo, 'derived'> & Partial<Pick<DddEntityInfo, 'derived'>>;
130
+ interface OpenApiOperation extends Omit<DddOperationExtensions, 'x-ddd-entity'> {
131
+ summary?: string;
132
+ description?: string;
133
+ operationId?: string;
134
+ tags?: string[];
135
+ parameters?: unknown[];
136
+ requestBody?: unknown;
137
+ responses?: Record<string, {
138
+ description?: string;
139
+ content?: Record<string, unknown>;
140
+ } | undefined>;
141
+ 'x-ddd-entity'?: DddEntityExtension;
142
+ [key: string]: unknown;
143
+ }
144
+ type OpenApiPathItem = Partial<Record<HttpMethod, OpenApiOperation>> & Record<string, unknown>;
145
+ interface OpenApiTag {
146
+ name: string;
147
+ description?: string;
148
+ }
149
+ interface OpenApiDocument {
150
+ openapi?: string;
151
+ info?: {
152
+ title?: string;
153
+ version?: string;
154
+ 'x-ddd-contract'?: DddContractInfoInput;
155
+ [key: string]: unknown;
156
+ };
157
+ tags?: OpenApiTag[];
158
+ paths?: Record<string, OpenApiPathItem | undefined>;
159
+ components?: {
160
+ schemas?: Record<string, unknown>;
161
+ [key: string]: unknown;
162
+ };
163
+ [key: string]: unknown;
164
+ }
165
+
166
+ /** Selects operations by HTTP method (optional, case-insensitive) and path (exact string or RegExp). */
167
+ interface OperationMatcher {
168
+ method?: Uppercase<HttpMethod> | HttpMethod;
169
+ path: string | RegExp;
170
+ }
171
+ /**
172
+ * Classifies operations by whether they change server state, for specs that do not carry
173
+ * `x-ddd-side-effects` yet. Matches on HTTP method and path (exact string or RegExp).
174
+ */
175
+ interface SideEffectsOverride extends OperationMatcher {
176
+ sideEffects: boolean;
177
+ /**
178
+ * Force the generated hook kind. Default: a writing GET becomes a mutation, a reading POST becomes a
179
+ * query. `'mutation'` keeps a reading POST a mutation (hook name unchanged) that invalidates nothing.
180
+ */
181
+ endpointType?: 'query' | 'mutation';
182
+ }
183
+ /**
184
+ * Sets how an endpoint reads its successful response, for specs whose declared content type is missing or wrong
185
+ * (e.g. an Excel export declared as `application/json`). Wins over content-type detection.
186
+ * - `blob`: `responseHandler: blobResponseHandler`, result type `DddFileResponse` (`{ blob, filename, contentType }`)
187
+ * - `text`: `responseHandler: "text"`, result type `string`
188
+ * - `json`: RTK's JSON parsing, no handler (also turns off a detected `text` / `blob`)
189
+ */
190
+ interface ResponseHandlerOverride extends OperationMatcher {
191
+ handler: 'blob' | 'text' | 'json';
192
+ }
193
+ interface HooksOptions {
194
+ queries: boolean;
195
+ lazyQueries: boolean;
196
+ mutations: boolean;
197
+ }
198
+ /** One generated API (one OpenAPI document, typically one audience). */
199
+ interface SdkApiConfig {
200
+ /** Spec source: http(s) URL or local file path (relative to the config file). */
201
+ schemaFile: string;
202
+ /**
203
+ * Module that exports the RTK base api: a path relative to the config file (e.g. `./src/api/baseApi.ts`)
204
+ * or a bare module specifier used verbatim.
205
+ */
206
+ apiFile: string;
207
+ /** Named export of the base api in `apiFile`. Default `api`. */
208
+ apiImport?: string;
209
+ /** Generated endpoints file, e.g. `./src/api/adminApi.ts`. Tags and enhanced files are written next to it. */
210
+ outputFile: string;
211
+ /** Name used for `--api` selection; also passed to RTK codegen. Default: stem of `outputFile`. */
212
+ exportName?: string;
213
+ hooks?: boolean | HooksOptions;
214
+ /** Prefix stripped from operation tags (e.g. `admin`). Default: stem of `outputFile` without `Api`. */
215
+ audience?: string;
216
+ /**
217
+ * Import specifier of the base api used by the `<stem>Enhanced.ts` file.
218
+ * Default: `apiFile` relative to the output directory (e.g. `./baseApi`).
219
+ */
220
+ baseApiImport?: string;
221
+ /** Overrides `SdkConfig.skipUpdatePostTwins` for this api. */
222
+ skipUpdatePostTwins?: boolean;
223
+ /** Added after the global `sideEffects`; the first match wins, so entries here are checked first. RegExp flags `g` / `y` are ignored for matching. */
224
+ sideEffects?: SideEffectsOverride[];
225
+ /** Added after the global `responseHandlers`; the first match wins, so entries here are checked first. */
226
+ responseHandlers?: ResponseHandlerOverride[];
227
+ /** Any further RTK codegen option (`argSuffix`, `flattenArg`, `endpointOverrides`, `filterEndpoints`, …). */
228
+ [rtkOption: string]: unknown;
229
+ }
230
+ /** Optional resolution of a workspace/subdomain value that the config reads from an env variable. */
231
+ interface WorkspaceOptions {
232
+ /** Env variable the config file reads, e.g. `DEV_WORKSPACE`. */
233
+ envVar: string;
234
+ /** Files sniffed for a URL whose first host label is the workspace. Default `['.env', '.env.local']`. */
235
+ envFiles?: string[];
236
+ /** Keys looked up in those files. Default: common `*_API_URL` keys. */
237
+ urlKeys?: string[];
238
+ /** Ask on a TTY when nothing else resolves it. Never asks without a TTY. Default `true`. */
239
+ prompt?: boolean;
240
+ }
241
+ interface SdkConfig {
242
+ apis: SdkApiConfig[];
243
+ /** Directory of generated model files. Default `<dir of first outputFile>/../models`. */
244
+ modelsDir?: string;
245
+ /**
246
+ * Skip the POST twin of an upsert (DDD `#[Update]` serves POST and PATCH): only the PATCH is generated. With
247
+ * `x-ddd-entity` both must be `upsert` of the same entity; without it summary, parameters, request body and
248
+ * responses must be identical. Conflicting annotations never skip. Default `false`.
249
+ */
250
+ skipUpdatePostTwins?: boolean;
251
+ sideEffects?: SideEffectsOverride[];
252
+ /**
253
+ * Response handler per operation, overriding content-type detection (binary 2xx → `blob`, text-only 2xx → `text`).
254
+ * First match wins.
255
+ */
256
+ responseHandlers?: ResponseHandlerOverride[];
257
+ workspace?: WorkspaceOptions;
258
+ /** tsconfig used for the final type check. Default `tsconfig.json` next to the config file. */
259
+ tsconfig?: string;
260
+ }
261
+ declare function defineConfig(config: SdkConfig): SdkConfig;
262
+ interface LoadedConfig {
263
+ config: SdkConfig;
264
+ configPath: string;
265
+ rootDir: string;
266
+ }
267
+ /**
268
+ * Loads `openapi-config.ts` (or .js/.mjs/.cjs) with jiti. Accepts `export default defineConfig({...})`
269
+ * or a named `export const apis = [...]` (plain RTK codegen entries).
270
+ */
271
+ declare function loadConfig(configPath: string): Promise<LoadedConfig>;
272
+
273
+ interface Logger {
274
+ info(message: string): void;
275
+ warn(message: string): void;
276
+ error(message: string): void;
277
+ }
278
+ declare const consoleLogger: Logger;
279
+ declare const silentLogger: Logger;
280
+ /** Thrown for expected aborts (bad spec, bad config); the CLI prints the message without a stack. */
281
+ declare class SdkGenerationError extends Error {
282
+ name: string;
283
+ }
284
+
285
+ interface GenerateSdkOptions {
286
+ /** Config file path (default `openapi-config.ts`, relative to `cwd`) or an inline config. */
287
+ config?: string | SdkConfig;
288
+ /** Base directory for a relative config path and for an inline config's relative paths. Default `process.cwd()`. */
289
+ cwd?: string;
290
+ /** Generate only the api with this `exportName` (or output file stem). */
291
+ api?: string;
292
+ /** Spec source (URL or file) replacing `schemaFile`; requires a single selected api. */
293
+ schema?: string;
294
+ /** Workspace value for `config.workspace.envVar`. */
295
+ workspace?: string;
296
+ skipPrettier?: boolean;
297
+ skipTsc?: boolean;
298
+ logger?: Logger;
299
+ }
300
+ interface GenerateSdkResult {
301
+ apis: string[];
302
+ /** Absolute paths of all written files. */
303
+ files: string[];
304
+ modelsDir: string;
305
+ typechecked: boolean;
306
+ }
307
+ declare function generateSdk(options?: GenerateSdkOptions): Promise<GenerateSdkResult>;
308
+
309
+ interface LinkSkillsOptions {
310
+ cwd?: string;
311
+ /** Directory holding the package's skills. Default `<cwd>/node_modules/@mgamadeus/ddd-web/.claude/skills`. */
312
+ sourceDir?: string;
313
+ logger?: Logger;
314
+ }
315
+ type LinkSkillAction = 'linked' | 'relinked' | 'unchanged' | 'skipped';
316
+ interface LinkSkillsResult {
317
+ skill: string;
318
+ action: LinkSkillAction;
319
+ target: string;
320
+ }
321
+ /**
322
+ * Symlinks every skill directory of the installed package into `<cwd>/.claude/skills/`. Idempotent;
323
+ * an existing symlink is repointed, a real file or directory is never touched. A package version that ships no
324
+ * skills is reported as such (nothing is created).
325
+ */
326
+ declare function linkSkills(options?: LinkSkillsOptions): LinkSkillsResult[];
327
+
328
+ /** Contract numbers (`info.x-ddd-contract.contract`) this codegen understands. */
329
+ declare const SUPPORTED_CONTRACT: {
330
+ readonly min: 1;
331
+ readonly max: 1;
332
+ };
333
+ /** Loads a spec from an http(s) URL or a local JSON file. Each source is read once per run by the caller. */
334
+ declare function loadSpec(source: string, timeoutMs?: number): Promise<OpenApiDocument>;
335
+ /**
336
+ * Checks the parts of the DDD contract the codegen depends on. Aborts on an unsupported contract
337
+ * version and on a spec without SchemaDefinition tag markup (fetched with `removeSchemaTags=1`).
338
+ */
339
+ declare function validateSpec(doc: OpenApiDocument, source: string, logger: Logger): void;
340
+
341
+ export { SUPPORTED_CONTRACT, SdkGenerationError, consoleLogger, defineConfig, generateSdk, linkSkills, loadConfig, loadSpec, silentLogger, validateSpec };
342
+ export type { GenerateSdkOptions, GenerateSdkResult, HooksOptions, LinkSkillAction, LinkSkillsOptions, LinkSkillsResult, LoadedConfig, Logger, OpenApiDocument, OperationMatcher, ResponseHandlerOverride, SdkApiConfig, SdkConfig, SideEffectsOverride, WorkspaceOptions };
@@ -0,0 +1,25 @@
1
+ import {
2
+ SUPPORTED_CONTRACT,
3
+ SdkGenerationError,
4
+ consoleLogger,
5
+ defineConfig,
6
+ generateSdk,
7
+ linkSkills,
8
+ loadConfig,
9
+ loadSpec,
10
+ silentLogger,
11
+ validateSpec
12
+ } from "../chunk-OL742YG5.js";
13
+ export {
14
+ SUPPORTED_CONTRACT,
15
+ SdkGenerationError,
16
+ consoleLogger,
17
+ defineConfig,
18
+ generateSdk,
19
+ linkSkills,
20
+ loadConfig,
21
+ loadSpec,
22
+ silentLogger,
23
+ validateSpec
24
+ };
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,109 @@
1
+ export { a as DddErrorBody, D as DddExceptionDetail, b as DddExceptionDetails } from '../errors-B4KabvNa.js';
2
+ export { C as ComparisonOperator, D as DEFAULT_TOP, a as DddColumnKind, b as DddContractInfo, c as DddEntityAction, d as DddEntityIdentity, e as DddEntityInfo, f as DddExpandDefinition, g as DddFilterDefinition, h as DddFilterValueRule, i as DddInfoExtensions, j as DddOperationExtensions, k as DddPropertyExtensions, l as DddQueryDefinition, m as DddSchemaExtensions, n as DddTemporalKind, o as DddTranslatableInfo, F as FILTER_OPERATORS, p as FULLTEXT_OPERATORS, q as FilterJoinOperator, r as FilterOperator, s as FulltextOperator, H as HttpMethod, L as LIST_OPERATORS, t as ListOperator, N as NULL_OPERATORS, O as OrderDirection, Q as QueryOptionsParams, u as getContractInfo, v as hasSideEffects, w as isFilterOperator, x as isFulltextOperator, y as isHiddenProperty, z as isListOperator, A as isPreservedOnOmission, B as isTranslatableProperty, E as parseEntityIdentity } from '../extensions-DToc6G5E.js';
3
+
4
+ /**
5
+ * `DDD.Domain.Base.Entities.Translatable.TranslationInfos` and helpers around its translations store.
6
+ */
7
+ /** Writing styles (`Translatable::WRITING_STYLE_*`). */
8
+ type WritingStyle = 'FORMAL' | 'INFORMAL';
9
+ /**
10
+ * Translation key `<languageCode>:<countryCode>:<writingStyle>` as built by
11
+ * `TranslatableService::getTranslationIndexForLanguageCodeCountryCodeAndWritingStyle()`: language and country
12
+ * lowercase, an absent country is empty, e.g. `en::FORMAL`, `de:at:INFORMAL`.
13
+ */
14
+ type TranslationKey = string;
15
+ /** Translations of one property: translation key → text. */
16
+ type PropertyTranslations = Record<TranslationKey, string>;
17
+ /** `translationsStore`: property name → translation key → text. */
18
+ type TranslationsStore = Record<string, PropertyTranslations>;
19
+ /** `TranslationInfos` as it appears in entity responses and requests (after {@link normalizeTranslationInfos}). */
20
+ interface TranslationInfos {
21
+ /** Translations per property. The wire sends `[]` for an empty store; use {@link normalizeTranslationsStore}. */
22
+ translationsStore?: TranslationsStore;
23
+ /** On persist, `true` replaces all stored translations instead of merging (JSON_MERGE_PATCH). */
24
+ replaceExistingTranslations?: boolean;
25
+ currentLanguageCode?: string;
26
+ currentCountryCode?: string | null;
27
+ currentWritingStyle?: WritingStyle;
28
+ defaultLanguageCode?: string;
29
+ defaultWritingStyle?: WritingStyle;
30
+ /** Keys (language, locale, optionally `::style`) for which translations exist → `true`. */
31
+ availableTranslations?: Record<string, boolean>;
32
+ hasTranslationForCurrentLanguageCode?: boolean;
33
+ hasTranslationForCurrentCountryCode?: boolean;
34
+ hasTranslationForCurrentWritingStyle?: boolean;
35
+ objectType?: string | null;
36
+ }
37
+ /** `TranslationInfos` as received on the wire: the maps may be empty arrays (`[]`). */
38
+ type TranslationInfosWire = Omit<TranslationInfos, 'translationsStore' | 'availableTranslations'> & {
39
+ translationsStore?: TranslationsStore | Record<string, PropertyTranslations | unknown[]> | unknown[] | null;
40
+ availableTranslations?: Record<string, boolean> | unknown[] | null;
41
+ };
42
+ /**
43
+ * Turns the wire form of a translations store into a map. PHP serialises an empty associative array as `[]`
44
+ * (`TranslationInfos::$translationsStore = []`, kept by the serializer), so an empty store — or an empty property
45
+ * entry — arrives as `[]`; both become `{}`. `null`/`undefined` become `{}` as well. Non-string texts are dropped.
46
+ */
47
+ declare function normalizeTranslationsStore(store: unknown): TranslationsStore;
48
+ /** Normalises a wire `TranslationInfos`: `translationsStore` and `availableTranslations` become maps. */
49
+ declare function normalizeTranslationInfos(infos: TranslationInfosWire): TranslationInfos;
50
+ /** Parts of a {@link TranslationKey}. */
51
+ interface TranslationKeyParts {
52
+ languageCode: string;
53
+ countryCode?: string | null;
54
+ writingStyle: WritingStyle;
55
+ }
56
+ /**
57
+ * Builds a translation key the way the backend does
58
+ * (`TranslatableService::getTranslationIndexForLanguageCodeCountryCodeAndWritingStyle()`):
59
+ * `strtolower(language) . ':' . strtolower(country ?? '') . ':' . writingStyle`.
60
+ */
61
+ declare function buildTranslationKey(parts: TranslationKeyParts): TranslationKey;
62
+ /** Splits a translation key into its parts; `null` when it is not `<language>:<country>:<style>`. */
63
+ declare function parseTranslationKey(key: TranslationKey): TranslationKeyParts | null;
64
+
65
+ /**
66
+ * DDD date and date-time wire format.
67
+ *
68
+ * `DDD\Infrastructure\Base\DateTime\DateTime::jsonSerialize()` writes `Y-m-d H:i:s` (`DateTime::SIMPLE`): a UTC
69
+ * wall-clock reading WITHOUT offset. `new Date('2026-01-02 03:04:05')` would read it as local time, so these helpers
70
+ * parse and format it explicitly as UTC. `DDD\Infrastructure\Base\DateTime\Date` writes `Y-m-d` (`Date::DATE`).
71
+ */
72
+ /** A DDD date-time string, `YYYY-MM-DD HH:MM:SS` in UTC. */
73
+ type DddDateTimeString = string;
74
+ /** A DDD date string, `YYYY-MM-DD`. */
75
+ type DddDateString = string;
76
+ /**
77
+ * Whether `value` is a real calendar date in `YYYY-MM-DD` form (rejects `2026-13-45`, `2026-02-30`).
78
+ * Mirrors the date check of `FiltersOptions::isFilterDateTimeLiteral()` (a date the formats parse but the calendar
79
+ * lacks fails).
80
+ */
81
+ declare function isValidDddDate(value: string): boolean;
82
+ /**
83
+ * Parses a DDD date-time to epoch ms. Offset-less values (`Y-m-d H:i:s`, `Y-m-d\TH:i:s`, `Y-m-d H:i`, optional
84
+ * fraction) and plain dates (`Y-m-d`, midnight) are read as UTC; values carrying an offset or `Z` are parsed as
85
+ * given. All forms are calendar-checked. Returns `null` for absent or invalid input.
86
+ */
87
+ declare function parseDddDateTimeMs(value: string | null | undefined): number | null;
88
+ /** Parses a DDD date-time to a `Date` (see {@link parseDddDateTimeMs}); `null` for absent or invalid input. */
89
+ declare function parseDddDateTime(value: string | null | undefined): Date | null;
90
+ /** Formats an instant as a DDD date-time (`Y-m-d H:i:s`, UTC, seconds truncated). Throws on an invalid date. */
91
+ declare function formatDddDateTime(value: Date | number): DddDateTimeString;
92
+ /** Formats an instant as a DDD date (`Y-m-d`, the UTC calendar day). Throws on an invalid date. */
93
+ declare function formatDddDate(value: Date | number): DddDateString;
94
+
95
+ /**
96
+ * `DDD.Domain.Base.Entities.ChangeHistory.ChangeHistory` as it appears on entities using the ChangeHistory trait.
97
+ * Both times are DDD date-times (`Y-m-d H:i:s`, UTC); parse them with `parseDddDateTime()`. The backend fills them
98
+ * on persist; a client never needs to send them (`overwriteCreatedAndModifiedTime` is hidden from responses).
99
+ */
100
+ interface ChangeHistory {
101
+ /** Time the entity was created and persisted. */
102
+ createdTime?: DddDateTimeString | null;
103
+ /** Time the entity was last modified and persisted. */
104
+ modifiedTime?: DddDateTimeString | null;
105
+ objectType?: string | null;
106
+ }
107
+
108
+ export { buildTranslationKey, formatDddDate, formatDddDateTime, isValidDddDate, normalizeTranslationInfos, normalizeTranslationsStore, parseDddDateTime, parseDddDateTimeMs, parseTranslationKey };
109
+ export type { ChangeHistory, DddDateString, DddDateTimeString, PropertyTranslations, TranslationInfos, TranslationInfosWire, TranslationKey, TranslationKeyParts, TranslationsStore, WritingStyle };
@@ -0,0 +1,126 @@
1
+ import {
2
+ DEFAULT_TOP,
3
+ FILTER_OPERATORS,
4
+ FULLTEXT_OPERATORS,
5
+ LIST_OPERATORS,
6
+ NULL_OPERATORS,
7
+ formatDddDate,
8
+ formatDddDateTime,
9
+ isFilterOperator,
10
+ isFulltextOperator,
11
+ isListOperator,
12
+ isValidDddDate,
13
+ parseDddDateTime,
14
+ parseDddDateTimeMs
15
+ } from "../chunk-QLCE3QTP.js";
16
+
17
+ // src/contract/extensions.ts
18
+ function hasSideEffects(method, operation) {
19
+ const explicit = operation?.["x-ddd-side-effects"];
20
+ if (typeof explicit === "boolean") {
21
+ return explicit;
22
+ }
23
+ return !["get", "head", "options", "trace"].includes(method.toLowerCase());
24
+ }
25
+ function isHiddenProperty(property) {
26
+ return property?.["x-ddd-hidden"] === true;
27
+ }
28
+ function isPreservedOnOmission(property) {
29
+ return property?.["x-ddd-preserve-on-omission"] === true;
30
+ }
31
+ function isTranslatableProperty(property) {
32
+ return property?.["x-ddd-translatable"] !== void 0 && property["x-ddd-translatable"] !== null;
33
+ }
34
+ function parseEntityIdentity(identity) {
35
+ if (!identity) {
36
+ return null;
37
+ }
38
+ const match = /^(path|body):(.+)$/.exec(identity);
39
+ if (!match) {
40
+ return null;
41
+ }
42
+ return { source: match[1], name: match[2] };
43
+ }
44
+ function getContractInfo(document) {
45
+ const contract = document?.info?.["x-ddd-contract"];
46
+ if (!contract || typeof contract.contract !== "number" || typeof contract.ddd !== "string") {
47
+ return null;
48
+ }
49
+ return contract;
50
+ }
51
+
52
+ // src/contract/translations.ts
53
+ function isPlainObject(value) {
54
+ return typeof value === "object" && value !== null && !Array.isArray(value);
55
+ }
56
+ function normalizeTranslationsStore(store) {
57
+ if (!isPlainObject(store)) {
58
+ return {};
59
+ }
60
+ const normalized = {};
61
+ for (const [propertyName, translations] of Object.entries(store)) {
62
+ const propertyTranslations = {};
63
+ if (isPlainObject(translations)) {
64
+ for (const [key, text] of Object.entries(translations)) {
65
+ if (typeof text === "string") {
66
+ propertyTranslations[key] = text;
67
+ }
68
+ }
69
+ }
70
+ normalized[propertyName] = propertyTranslations;
71
+ }
72
+ return normalized;
73
+ }
74
+ function normalizeTranslationInfos(infos) {
75
+ const availableTranslations = {};
76
+ if (isPlainObject(infos.availableTranslations)) {
77
+ for (const [key, available] of Object.entries(infos.availableTranslations)) {
78
+ availableTranslations[key] = available === true;
79
+ }
80
+ }
81
+ return {
82
+ ...infos,
83
+ translationsStore: normalizeTranslationsStore(infos.translationsStore),
84
+ availableTranslations
85
+ };
86
+ }
87
+ function buildTranslationKey(parts) {
88
+ return `${parts.languageCode.toLowerCase()}:${(parts.countryCode ?? "").toLowerCase()}:${parts.writingStyle}`;
89
+ }
90
+ function parseTranslationKey(key) {
91
+ const match = /^([^:]+):([^:]*):(FORMAL|INFORMAL)$/.exec(key);
92
+ if (!match) {
93
+ return null;
94
+ }
95
+ return {
96
+ languageCode: match[1],
97
+ countryCode: match[2] ? match[2] : null,
98
+ writingStyle: match[3]
99
+ };
100
+ }
101
+ export {
102
+ DEFAULT_TOP,
103
+ FILTER_OPERATORS,
104
+ FULLTEXT_OPERATORS,
105
+ LIST_OPERATORS,
106
+ NULL_OPERATORS,
107
+ buildTranslationKey,
108
+ formatDddDate,
109
+ formatDddDateTime,
110
+ getContractInfo,
111
+ hasSideEffects,
112
+ isFilterOperator,
113
+ isFulltextOperator,
114
+ isHiddenProperty,
115
+ isListOperator,
116
+ isPreservedOnOmission,
117
+ isTranslatableProperty,
118
+ isValidDddDate,
119
+ normalizeTranslationInfos,
120
+ normalizeTranslationsStore,
121
+ parseDddDateTime,
122
+ parseDddDateTimeMs,
123
+ parseEntityIdentity,
124
+ parseTranslationKey
125
+ };
126
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/contract/extensions.ts","../../src/contract/translations.ts"],"sourcesContent":["import type { FilterOperator } from './operators';\n\n/**\n * Types of the `x-ddd-*` OpenAPI extensions emitted by DDD Core, plus the defaults that apply when an extension is\n * absent. All extensions are additive: a document without them is valid and is read with the defaults below.\n */\n\n/** `info.x-ddd-contract`: contract number and the emitting `mgamadeus/ddd` version. */\nexport interface DddContractInfo {\n /** Contract number; bumped on every change of an `x-ddd-*` key, an implicit part or a default. */\n contract: number;\n /** Version of the `mgamadeus/ddd` package that emitted the document, e.g. `3.14.0`. */\n ddd: string;\n}\n\n/**\n * Column kind of a filter (`FiltersDefinition::COLUMN_KIND_*`): what a filter value is validated and bound as.\n * `translatable` is a plain `#[Translatable]` (JSON of all languages), `translatable-searchable` one with\n * `fullTextIndex: true` (comparisons run on its virtual search column).\n */\nexport type DddColumnKind =\n | 'int'\n | 'float'\n | 'bool'\n | 'string'\n | 'datetime'\n | 'json'\n | 'translatable'\n | 'translatable-searchable';\n\n/**\n * Temporal kind of a filter (`FiltersDefinition::TEMPORAL_KIND_*`): `MOMENT` = an instant (date-time),\n * `DAY` = a calendar day (date, never zone-converted).\n */\nexport type DddTemporalKind = 'MOMENT' | 'DAY';\n\n/**\n * A value rule for one operator of a filter. Known rules:\n * - `wildcard-required`: the value must contain `*` (plain Translatable `eq` / `ne`, a LIKE on the JSON text);\n * - `null-only`: only a null comparison is allowed (JSON columns).\n * Further rules may be added by the contract; unknown rules must be ignored by clients.\n */\nexport type DddFilterValueRule = 'wildcard-required' | 'null-only' | (string & {});\n\n/** One filter definition inside `x-ddd-query.filters`. */\nexport interface DddFilterDefinition {\n /** Filter property name as used in `filters`, may be dotted (e.g. `author.name`). */\n name: string;\n /** Path of the filtered value in the response schema (e.g. `changeHistory.createdTime`); `null` if none. */\n path?: string | null;\n /** Column kind; absent or `null` = no value validation on the backend. */\n columnKind?: DddColumnKind | null;\n /** Temporal kind; absent or `null` = not temporal. */\n temporalKind?: DddTemporalKind | null;\n /** Whether `ft` / `fb` work on this filter (single-column FULLTEXT index). */\n supportsFulltext?: boolean;\n /** Allowed values (`FiltersDefinition::$options`); every value, also each list item, must be one of them. */\n options?: Array<string | number> | null;\n /** Operators allowed for this filter; absent = every operator the column kind accepts. */\n operators?: FilterOperator[];\n /** Value rules per operator. */\n valueRules?: Partial<Record<FilterOperator, DddFilterValueRule>>;\n /** Name of the expand that must be present in `expand` for this filter to be accepted; absent = none. */\n requiresExpand?: string | null;\n}\n\n/** One expand definition inside `x-ddd-query.expand`. */\nexport interface DddExpandDefinition {\n /** Property name to expand (no dots; nesting goes through `expand`). */\n name: string;\n /** `true` for a computed field (no relation, no clauses), e.g. a rendered SVG. */\n computed?: boolean;\n /** Default `top` inside the expand clause. */\n top?: number;\n /** Upper bound for `top` inside the expand clause. */\n maxTop?: number | null;\n /** Default `skip` inside the expand clause. */\n skip?: number;\n /** Filters available inside the expand clause (`filters=` in `(…)`). */\n filters?: DddFilterDefinition[];\n /** Sortable properties inside the expand clause. */\n orderBy?: string[];\n /** Nested expands (`expand=` in `(…)`). */\n expand?: DddExpandDefinition[];\n}\n\n/** `x-ddd-query` on an operation whose request DTO applies QueryOptions. */\nexport interface DddQueryDefinition {\n filters?: DddFilterDefinition[];\n /** Sortable property names. */\n orderBy?: string[];\n expand?: DddExpandDefinition[];\n /** `true` = `select` accepted (any property), a list = the selectable properties, `false`/absent = not exposed. */\n select?: boolean | string[];\n /** Default page size (backend default 50). */\n top?: number;\n /** Upper bound for `top` (`#[QueryOptions(maxTop: …)]`); a larger `top` answers 400. */\n maxTop?: number | null;\n}\n\n/** `x-ddd-entity.action`. DDD `#[Update]` is an upsert. */\nexport type DddEntityAction = 'list' | 'get' | 'upsert' | 'delete' | 'action';\n\n/** `x-ddd-entity` on an operation. Absent = unknown entity, clients invalidate conservatively. */\nexport interface DddEntityInfo {\n /** Entity schema name, e.g. `App.Domain.Library.Entities.Books.Book`. */\n schema: string;\n action: DddEntityAction;\n /** Identity source, `path:<parameter>` or `body:<dotted.path>` (e.g. `body:book.id`). */\n identity?: string;\n /** `true` when derived by DDD Core, `false` when set explicitly via `#[OperationEntity]`. */\n derived: boolean;\n}\n\n/** Field-level `x-ddd-translatable` (from `#[Translatable]`). */\nexport interface DddTranslatableInfo {\n fullTextIndex?: boolean;\n fullTextMode?: string;\n}\n\n/** Extensions on the document `info` object. */\nexport interface DddInfoExtensions {\n 'x-ddd-contract'?: DddContractInfo;\n}\n\n/** Extensions on an operation object. */\nexport interface DddOperationExtensions {\n 'x-ddd-query'?: DddQueryDefinition;\n /** Absent = default by HTTP method (see {@link hasSideEffects}). */\n 'x-ddd-side-effects'?: boolean;\n 'x-ddd-entity'?: DddEntityInfo;\n /** Cache TTL in seconds from `#[RequestCache]`. */\n 'x-ddd-cache-ttl'?: number;\n}\n\n/** Extensions on a schema property. */\nexport interface DddPropertyExtensions {\n 'x-ddd-translatable'?: DddTranslatableInfo;\n /** `#[HideProperty]`: never in responses, accepted in requests (write-only). Absent = visible. */\n 'x-ddd-hidden'?: boolean;\n /** The stored value is kept when the property is omitted on an update of an existing entity. */\n 'x-ddd-preserve-on-omission'?: boolean;\n}\n\n/** Extensions on an entity schema. */\nexport interface DddSchemaExtensions {\n /** Roles required to write the entity (`RolesRequiredForUpdate`). */\n 'x-ddd-roles-required-for-update'?: string[];\n}\n\n/** HTTP methods of OpenAPI operations (lowercase or uppercase accepted by the helpers). */\nexport type HttpMethod = 'get' | 'head' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace';\n\n/**\n * Whether an operation has side effects (contract defaults, Appendix A.6): `x-ddd-side-effects` wins when present,\n * otherwise `false` for GET/HEAD/OPTIONS/TRACE and `true` for POST/PUT/PATCH/DELETE.\n */\nexport function hasSideEffects(method: string, operation?: Pick<DddOperationExtensions, 'x-ddd-side-effects'> | null): boolean {\n const explicit = operation?.['x-ddd-side-effects'];\n if (typeof explicit === 'boolean') {\n return explicit;\n }\n return !['get', 'head', 'options', 'trace'].includes(method.toLowerCase());\n}\n\n/** Whether a property is write-only (`x-ddd-hidden: true`). Absent = visible. */\nexport function isHiddenProperty(property?: DddPropertyExtensions | null): boolean {\n return property?.['x-ddd-hidden'] === true;\n}\n\n/** Whether a property keeps its stored value when omitted on an update (`x-ddd-preserve-on-omission: true`). */\nexport function isPreservedOnOmission(property?: DddPropertyExtensions | null): boolean {\n return property?.['x-ddd-preserve-on-omission'] === true;\n}\n\n/** Whether a property is `#[Translatable]` (`x-ddd-translatable` present). */\nexport function isTranslatableProperty(property?: DddPropertyExtensions | null): boolean {\n return property?.['x-ddd-translatable'] !== undefined && property['x-ddd-translatable'] !== null;\n}\n\n/** Parsed `x-ddd-entity.identity`. */\nexport interface DddEntityIdentity {\n source: 'path' | 'body';\n /** Path parameter name (`source: 'path'`) or dotted body path (`source: 'body'`). */\n name: string;\n}\n\n/** Parses `x-ddd-entity.identity` (`path:bookId`, `body:book.id`); `null` for an absent or malformed value. */\nexport function parseEntityIdentity(identity: string | null | undefined): DddEntityIdentity | null {\n if (!identity) {\n return null;\n }\n const match = /^(path|body):(.+)$/.exec(identity);\n if (!match) {\n return null;\n }\n return { source: match[1] as 'path' | 'body', name: match[2] as string };\n}\n\n/** Reads `info.x-ddd-contract` from an OpenAPI document; `null` when the document carries no contract version. */\nexport function getContractInfo(document: { info?: DddInfoExtensions | null } | null | undefined): DddContractInfo | null {\n const contract = document?.info?.['x-ddd-contract'];\n if (!contract || typeof contract.contract !== 'number' || typeof contract.ddd !== 'string') {\n return null;\n }\n return contract;\n}\n","/**\n * `DDD.Domain.Base.Entities.Translatable.TranslationInfos` and helpers around its translations store.\n */\n\n/** Writing styles (`Translatable::WRITING_STYLE_*`). */\nexport type WritingStyle = 'FORMAL' | 'INFORMAL';\n\n/**\n * Translation key `<languageCode>:<countryCode>:<writingStyle>` as built by\n * `TranslatableService::getTranslationIndexForLanguageCodeCountryCodeAndWritingStyle()`: language and country\n * lowercase, an absent country is empty, e.g. `en::FORMAL`, `de:at:INFORMAL`.\n */\nexport type TranslationKey = string;\n\n/** Translations of one property: translation key → text. */\nexport type PropertyTranslations = Record<TranslationKey, string>;\n\n/** `translationsStore`: property name → translation key → text. */\nexport type TranslationsStore = Record<string, PropertyTranslations>;\n\n/** `TranslationInfos` as it appears in entity responses and requests (after {@link normalizeTranslationInfos}). */\nexport interface TranslationInfos {\n /** Translations per property. The wire sends `[]` for an empty store; use {@link normalizeTranslationsStore}. */\n translationsStore?: TranslationsStore;\n /** On persist, `true` replaces all stored translations instead of merging (JSON_MERGE_PATCH). */\n replaceExistingTranslations?: boolean;\n currentLanguageCode?: string;\n currentCountryCode?: string | null;\n currentWritingStyle?: WritingStyle;\n defaultLanguageCode?: string;\n defaultWritingStyle?: WritingStyle;\n /** Keys (language, locale, optionally `::style`) for which translations exist → `true`. */\n availableTranslations?: Record<string, boolean>;\n hasTranslationForCurrentLanguageCode?: boolean;\n hasTranslationForCurrentCountryCode?: boolean;\n hasTranslationForCurrentWritingStyle?: boolean;\n objectType?: string | null;\n}\n\n/** `TranslationInfos` as received on the wire: the maps may be empty arrays (`[]`). */\nexport type TranslationInfosWire = Omit<TranslationInfos, 'translationsStore' | 'availableTranslations'> & {\n translationsStore?: TranslationsStore | Record<string, PropertyTranslations | unknown[]> | unknown[] | null;\n availableTranslations?: Record<string, boolean> | unknown[] | null;\n};\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Turns the wire form of a translations store into a map. PHP serialises an empty associative array as `[]`\n * (`TranslationInfos::$translationsStore = []`, kept by the serializer), so an empty store — or an empty property\n * entry — arrives as `[]`; both become `{}`. `null`/`undefined` become `{}` as well. Non-string texts are dropped.\n */\nexport function normalizeTranslationsStore(store: unknown): TranslationsStore {\n if (!isPlainObject(store)) {\n return {};\n }\n const normalized: TranslationsStore = {};\n for (const [propertyName, translations] of Object.entries(store)) {\n const propertyTranslations: PropertyTranslations = {};\n if (isPlainObject(translations)) {\n for (const [key, text] of Object.entries(translations)) {\n if (typeof text === 'string') {\n propertyTranslations[key] = text;\n }\n }\n }\n normalized[propertyName] = propertyTranslations;\n }\n return normalized;\n}\n\n/** Normalises a wire `TranslationInfos`: `translationsStore` and `availableTranslations` become maps. */\nexport function normalizeTranslationInfos(infos: TranslationInfosWire): TranslationInfos {\n const availableTranslations: Record<string, boolean> = {};\n if (isPlainObject(infos.availableTranslations)) {\n for (const [key, available] of Object.entries(infos.availableTranslations)) {\n availableTranslations[key] = available === true;\n }\n }\n return {\n ...infos,\n translationsStore: normalizeTranslationsStore(infos.translationsStore),\n availableTranslations,\n };\n}\n\n/** Parts of a {@link TranslationKey}. */\nexport interface TranslationKeyParts {\n languageCode: string;\n countryCode?: string | null;\n writingStyle: WritingStyle;\n}\n\n/**\n * Builds a translation key the way the backend does\n * (`TranslatableService::getTranslationIndexForLanguageCodeCountryCodeAndWritingStyle()`):\n * `strtolower(language) . ':' . strtolower(country ?? '') . ':' . writingStyle`.\n */\nexport function buildTranslationKey(parts: TranslationKeyParts): TranslationKey {\n return `${parts.languageCode.toLowerCase()}:${(parts.countryCode ?? '').toLowerCase()}:${parts.writingStyle}`;\n}\n\n/** Splits a translation key into its parts; `null` when it is not `<language>:<country>:<style>`. */\nexport function parseTranslationKey(key: TranslationKey): TranslationKeyParts | null {\n const match = /^([^:]+):([^:]*):(FORMAL|INFORMAL)$/.exec(key);\n if (!match) {\n return null;\n }\n return {\n languageCode: match[1] as string,\n countryCode: match[2] ? match[2] : null,\n writingStyle: match[3] as WritingStyle,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA6JO,SAAS,eAAe,QAAgB,WAAgF;AAC7H,QAAM,WAAW,YAAY,oBAAoB;AACjD,MAAI,OAAO,aAAa,WAAW;AACjC,WAAO;AAAA,EACT;AACA,SAAO,CAAC,CAAC,OAAO,QAAQ,WAAW,OAAO,EAAE,SAAS,OAAO,YAAY,CAAC;AAC3E;AAGO,SAAS,iBAAiB,UAAkD;AACjF,SAAO,WAAW,cAAc,MAAM;AACxC;AAGO,SAAS,sBAAsB,UAAkD;AACtF,SAAO,WAAW,4BAA4B,MAAM;AACtD;AAGO,SAAS,uBAAuB,UAAkD;AACvF,SAAO,WAAW,oBAAoB,MAAM,UAAa,SAAS,oBAAoB,MAAM;AAC9F;AAUO,SAAS,oBAAoB,UAA+D;AACjG,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AACA,QAAM,QAAQ,qBAAqB,KAAK,QAAQ;AAChD,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AACA,SAAO,EAAE,QAAQ,MAAM,CAAC,GAAsB,MAAM,MAAM,CAAC,EAAY;AACzE;AAGO,SAAS,gBAAgB,UAA0F;AACxH,QAAM,WAAW,UAAU,OAAO,gBAAgB;AAClD,MAAI,CAAC,YAAY,OAAO,SAAS,aAAa,YAAY,OAAO,SAAS,QAAQ,UAAU;AAC1F,WAAO;AAAA,EACT;AACA,SAAO;AACT;;;ACjKA,SAAS,cAAc,OAAkD;AACvE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAOO,SAAS,2BAA2B,OAAmC;AAC5E,MAAI,CAAC,cAAc,KAAK,GAAG;AACzB,WAAO,CAAC;AAAA,EACV;AACA,QAAM,aAAgC,CAAC;AACvC,aAAW,CAAC,cAAc,YAAY,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChE,UAAM,uBAA6C,CAAC;AACpD,QAAI,cAAc,YAAY,GAAG;AAC/B,iBAAW,CAAC,KAAK,IAAI,KAAK,OAAO,QAAQ,YAAY,GAAG;AACtD,YAAI,OAAO,SAAS,UAAU;AAC5B,+BAAqB,GAAG,IAAI;AAAA,QAC9B;AAAA,MACF;AAAA,IACF;AACA,eAAW,YAAY,IAAI;AAAA,EAC7B;AACA,SAAO;AACT;AAGO,SAAS,0BAA0B,OAA+C;AACvF,QAAM,wBAAiD,CAAC;AACxD,MAAI,cAAc,MAAM,qBAAqB,GAAG;AAC9C,eAAW,CAAC,KAAK,SAAS,KAAK,OAAO,QAAQ,MAAM,qBAAqB,GAAG;AAC1E,4BAAsB,GAAG,IAAI,cAAc;AAAA,IAC7C;AAAA,EACF;AACA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,mBAAmB,2BAA2B,MAAM,iBAAiB;AAAA,IACrE;AAAA,EACF;AACF;AAcO,SAAS,oBAAoB,OAA4C;AAC9E,SAAO,GAAG,MAAM,aAAa,YAAY,CAAC,KAAK,MAAM,eAAe,IAAI,YAAY,CAAC,IAAI,MAAM,YAAY;AAC7G;AAGO,SAAS,oBAAoB,KAAiD;AACnF,QAAM,QAAQ,sCAAsC,KAAK,GAAG;AAC5D,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AACA,SAAO;AAAA,IACL,cAAc,MAAM,CAAC;AAAA,IACrB,aAAa,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI;AAAA,IACnC,cAAc,MAAM,CAAC;AAAA,EACvB;AACF;","names":[]}