@api-client/core 0.17.4 → 0.17.5
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/build/src/modeling/Semantics.d.ts +1 -1
- package/build/src/modeling/Semantics.d.ts.map +1 -1
- package/build/src/modeling/Semantics.js +6 -6
- package/build/src/modeling/Semantics.js.map +1 -1
- package/build/src/modeling/definitions/{Price.d.ts → Currency.d.ts} +24 -24
- package/build/src/modeling/definitions/Currency.d.ts.map +1 -0
- package/build/src/modeling/definitions/{Price.js → Currency.js} +18 -18
- package/build/src/modeling/definitions/Currency.js.map +1 -0
- package/build/src/modeling/definitions/HTML.d.ts +17 -4
- package/build/src/modeling/definitions/HTML.d.ts.map +1 -1
- package/build/src/modeling/definitions/HTML.js +0 -1
- package/build/src/modeling/definitions/HTML.js.map +1 -1
- package/build/src/modeling/definitions/Markdown.d.ts +12 -4
- package/build/src/modeling/definitions/Markdown.d.ts.map +1 -1
- package/build/src/modeling/definitions/Markdown.js +0 -1
- package/build/src/modeling/definitions/Markdown.js.map +1 -1
- package/build/src/modeling/definitions/Status.d.ts +1 -1
- package/build/src/modeling/definitions/Status.d.ts.map +1 -1
- package/build/src/modeling/definitions/Status.js +1 -0
- package/build/src/modeling/definitions/Status.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/modeling/Semantics.ts +6 -6
- package/src/modeling/definitions/{Price.examples.md → Currency.examples.md} +12 -12
- package/src/modeling/definitions/{Price.ts → Currency.ts} +26 -26
- package/src/modeling/definitions/HTML.ts +17 -5
- package/src/modeling/definitions/Markdown.ts +12 -5
- package/src/modeling/definitions/Status.ts +2 -1
- package/tests/unit/modeling/definitions/{price.spec.ts → currency.spec.ts} +114 -114
- package/tests/unit/modeling/definitions/description.spec.ts +0 -2
- package/tests/unit/modeling/semantic-configs.spec.ts +44 -44
- package/tests/unit/modeling/semantics.spec.ts +10 -1
- package/build/src/modeling/definitions/Price.d.ts.map +0 -1
- package/build/src/modeling/definitions/Price.js.map +0 -1
package/package.json
CHANGED
|
@@ -151,7 +151,7 @@ export enum SemanticType {
|
|
|
151
151
|
* Can store simple decimal amounts or complex objects with amount and currency.
|
|
152
152
|
* Enforces proper decimal handling to avoid floating-point errors.
|
|
153
153
|
*/
|
|
154
|
-
|
|
154
|
+
Currency = 'Semantic#Currency',
|
|
155
155
|
/**
|
|
156
156
|
* Annotates a field as a URL with validation and allowed protocols.
|
|
157
157
|
*/
|
|
@@ -463,7 +463,7 @@ export const DataSemantics: Record<SemanticType, DataSemantic> = {
|
|
|
463
463
|
description: 'Detailed description text',
|
|
464
464
|
category: SemanticCategory.Content,
|
|
465
465
|
applicableDataTypes: ['string'],
|
|
466
|
-
hasConfig:
|
|
466
|
+
hasConfig: false,
|
|
467
467
|
},
|
|
468
468
|
[SemanticType.Summary]: {
|
|
469
469
|
id: SemanticType.Summary,
|
|
@@ -472,7 +472,7 @@ export const DataSemantics: Record<SemanticType, DataSemantic> = {
|
|
|
472
472
|
description: 'Brief summary text',
|
|
473
473
|
category: SemanticCategory.Content,
|
|
474
474
|
applicableDataTypes: ['string'],
|
|
475
|
-
hasConfig:
|
|
475
|
+
hasConfig: false,
|
|
476
476
|
},
|
|
477
477
|
[SemanticType.Markdown]: {
|
|
478
478
|
id: SemanticType.Markdown,
|
|
@@ -524,9 +524,9 @@ export const DataSemantics: Record<SemanticType, DataSemantic> = {
|
|
|
524
524
|
applicableDataTypes: ['string'],
|
|
525
525
|
hasConfig: true,
|
|
526
526
|
},
|
|
527
|
-
[SemanticType.
|
|
528
|
-
id: SemanticType.
|
|
529
|
-
displayName: '
|
|
527
|
+
[SemanticType.Currency]: {
|
|
528
|
+
id: SemanticType.Currency,
|
|
529
|
+
displayName: 'Currency',
|
|
530
530
|
scope: SemanticScope.Property,
|
|
531
531
|
description: 'Monetary value with currency',
|
|
532
532
|
category: SemanticCategory.Business,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Currency Semantic Examples
|
|
2
2
|
|
|
3
|
-
This document provides examples of how to use the
|
|
3
|
+
This document provides examples of how to use the Currency semantic with different configurations.
|
|
4
4
|
|
|
5
5
|
## Basic Usage
|
|
6
6
|
|
|
7
7
|
```typescript
|
|
8
|
-
import {
|
|
8
|
+
import { createCurrencySemantic, CURRENCY_PRESETS } from './Currency.js'
|
|
9
9
|
|
|
10
10
|
// Simple USD decimal storage
|
|
11
|
-
const
|
|
11
|
+
const basicCurrency = createCurrencySemantic({
|
|
12
12
|
storageFormat: 'decimal',
|
|
13
13
|
defaultCurrency: 'USD',
|
|
14
14
|
decimalPlaces: 2,
|
|
@@ -16,7 +16,7 @@ const basicPrice = createPriceSemantic({
|
|
|
16
16
|
})
|
|
17
17
|
|
|
18
18
|
// Using a preset
|
|
19
|
-
const usdDecimal =
|
|
19
|
+
const usdDecimal = CURRENCY_PRESETS.USD_DECIMAL
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## Configuration Examples
|
|
@@ -24,7 +24,7 @@ const usdDecimal = PRICE_PRESETS.USD_DECIMAL
|
|
|
24
24
|
### 1. Simple E-commerce Store (USD only)
|
|
25
25
|
|
|
26
26
|
```typescript
|
|
27
|
-
const
|
|
27
|
+
const ecommerceCurrency = createCurrencySemantic({
|
|
28
28
|
storageFormat: 'decimal',
|
|
29
29
|
defaultCurrency: 'USD',
|
|
30
30
|
decimalPlaces: 2,
|
|
@@ -35,7 +35,7 @@ const ecommercePrice = createPriceSemantic({
|
|
|
35
35
|
### 2. International E-commerce (Multi-currency)
|
|
36
36
|
|
|
37
37
|
```typescript
|
|
38
|
-
const
|
|
38
|
+
const internationalCurrency = createCurrencySemantic({
|
|
39
39
|
storageFormat: 'complex_object',
|
|
40
40
|
allowedCurrencies: ['USD', 'EUR', 'GBP', 'JPY', 'CAD', 'AUD'],
|
|
41
41
|
decimalPlaces: 2,
|
|
@@ -46,7 +46,7 @@ const internationalPrice = createPriceSemantic({
|
|
|
46
46
|
### 3. Financial System (High precision, allows negatives)
|
|
47
47
|
|
|
48
48
|
```typescript
|
|
49
|
-
const
|
|
49
|
+
const financialCurrency = createCurrencySemantic({
|
|
50
50
|
storageFormat: 'integer_cents',
|
|
51
51
|
defaultCurrency: 'USD',
|
|
52
52
|
decimalPlaces: 4,
|
|
@@ -57,7 +57,7 @@ const financialPrice = createPriceSemantic({
|
|
|
57
57
|
### 4. Cryptocurrency Trading
|
|
58
58
|
|
|
59
59
|
```typescript
|
|
60
|
-
const
|
|
60
|
+
const cryptoCurrency = createCurrencySemantic({
|
|
61
61
|
storageFormat: 'decimal',
|
|
62
62
|
defaultCurrency: 'BTC',
|
|
63
63
|
decimalPlaces: 8,
|
|
@@ -142,10 +142,10 @@ CREATE INDEX idx_products_price_currency ON products USING GIN ((price->>'curren
|
|
|
142
142
|
|
|
143
143
|
## Validation Examples
|
|
144
144
|
|
|
145
|
-
The
|
|
145
|
+
The Currency semantic includes built-in validation:
|
|
146
146
|
|
|
147
147
|
```typescript
|
|
148
|
-
import {
|
|
148
|
+
import { validateCurrencyConfig } from './Currency.js'
|
|
149
149
|
|
|
150
150
|
const config = {
|
|
151
151
|
storageFormat: 'decimal' as const,
|
|
@@ -153,6 +153,6 @@ const config = {
|
|
|
153
153
|
decimalPlaces: 2,
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
const errors =
|
|
156
|
+
const errors = validateCurrencyConfig(config)
|
|
157
157
|
console.log(errors) // ['defaultCurrency is required when storageFormat is not complex_object']
|
|
158
158
|
```
|
|
@@ -4,13 +4,13 @@ import { SemanticType } from '../Semantics.js'
|
|
|
4
4
|
/**
|
|
5
5
|
* Supported storage formats for monetary values.
|
|
6
6
|
*/
|
|
7
|
-
export type
|
|
7
|
+
export type CurrencyStorageFormat = 'decimal' | 'integer_cents' | 'complex_object'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Configuration options for the
|
|
10
|
+
* Configuration options for the Currency semantic.
|
|
11
11
|
* Controls monetary value storage, validation, currency handling, and precision.
|
|
12
12
|
*/
|
|
13
|
-
export interface
|
|
13
|
+
export interface CurrencyConfig {
|
|
14
14
|
/**
|
|
15
15
|
* How the monetary value is stored in the database.
|
|
16
16
|
*
|
|
@@ -18,7 +18,7 @@ export interface PriceConfig {
|
|
|
18
18
|
* - 'integer_cents': Store as INTEGER in smallest currency unit (e.g., 1999 for $19.99)
|
|
19
19
|
* - 'complex_object': Store as JSON/JSONB with amount and currency (e.g., {"amount": 1999, "currency": "USD"})
|
|
20
20
|
*/
|
|
21
|
-
storageFormat?:
|
|
21
|
+
storageFormat?: CurrencyStorageFormat
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Default currency code (ISO 4217) when not specified.
|
|
@@ -50,7 +50,7 @@ export interface PriceConfig {
|
|
|
50
50
|
validateCurrencyCode?: boolean
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* Custom metadata for the
|
|
53
|
+
* Custom metadata for the currency field.
|
|
54
54
|
*/
|
|
55
55
|
metadata?: Record<string, unknown>
|
|
56
56
|
|
|
@@ -61,26 +61,26 @@ export interface PriceConfig {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
* Type-safe configuration for
|
|
64
|
+
* Type-safe configuration for Currency semantic.
|
|
65
65
|
*/
|
|
66
|
-
export interface
|
|
67
|
-
id: SemanticType.
|
|
68
|
-
config?:
|
|
66
|
+
export interface AppliedCurrencySemantic extends AppliedDataSemantic {
|
|
67
|
+
id: SemanticType.Currency
|
|
68
|
+
config?: CurrencyConfig
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
|
-
* Type guard to check if a semantic is a
|
|
72
|
+
* Type guard to check if a semantic is a Currency semantic.
|
|
73
73
|
*/
|
|
74
|
-
export const
|
|
75
|
-
return semantic.id === SemanticType.
|
|
74
|
+
export const isCurrencySemantic = (semantic: AppliedDataSemantic): semantic is AppliedCurrencySemantic => {
|
|
75
|
+
return semantic.id === SemanticType.Currency
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
|
-
* Helper function to create a
|
|
79
|
+
* Helper function to create a Currency semantic with configuration.
|
|
80
80
|
*/
|
|
81
|
-
export const
|
|
81
|
+
export const createCurrencySemantic = (config: CurrencyConfig = {}): AppliedCurrencySemantic => {
|
|
82
82
|
const mergedConfig = {
|
|
83
|
-
...
|
|
83
|
+
...DEFAULT_CURRENCY_CONFIG,
|
|
84
84
|
...config,
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -90,16 +90,16 @@ export const createPriceSemantic = (config: PriceConfig = {}): AppliedPriceSeman
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
return {
|
|
93
|
-
id: SemanticType.
|
|
93
|
+
id: SemanticType.Currency,
|
|
94
94
|
config: mergedConfig,
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
* Default configuration for
|
|
99
|
+
* Default configuration for Currency semantic.
|
|
100
100
|
* Optimized for common e-commerce use cases with USD currency.
|
|
101
101
|
*/
|
|
102
|
-
export const
|
|
102
|
+
export const DEFAULT_CURRENCY_CONFIG: CurrencyConfig = {
|
|
103
103
|
storageFormat: 'decimal',
|
|
104
104
|
defaultCurrency: 'USD',
|
|
105
105
|
decimalPlaces: 2,
|
|
@@ -110,11 +110,11 @@ export const DEFAULT_PRICE_CONFIG: PriceConfig = {
|
|
|
110
110
|
/**
|
|
111
111
|
* Predefined configurations for common use cases.
|
|
112
112
|
*/
|
|
113
|
-
export const
|
|
113
|
+
export const CURRENCY_PRESETS = {
|
|
114
114
|
/**
|
|
115
115
|
* Simple USD decimal storage - good for most e-commerce sites.
|
|
116
116
|
*/
|
|
117
|
-
USD_DECIMAL:
|
|
117
|
+
USD_DECIMAL: createCurrencySemantic({
|
|
118
118
|
storageFormat: 'decimal',
|
|
119
119
|
defaultCurrency: 'USD',
|
|
120
120
|
decimalPlaces: 2,
|
|
@@ -124,7 +124,7 @@ export const PRICE_PRESETS = {
|
|
|
124
124
|
/**
|
|
125
125
|
* Integer cents storage - avoids floating point issues, good for financial calculations.
|
|
126
126
|
*/
|
|
127
|
-
USD_CENTS:
|
|
127
|
+
USD_CENTS: createCurrencySemantic({
|
|
128
128
|
storageFormat: 'integer_cents',
|
|
129
129
|
defaultCurrency: 'USD',
|
|
130
130
|
decimalPlaces: 2,
|
|
@@ -134,7 +134,7 @@ export const PRICE_PRESETS = {
|
|
|
134
134
|
/**
|
|
135
135
|
* Multi-currency support with complex object storage.
|
|
136
136
|
*/
|
|
137
|
-
MULTI_CURRENCY:
|
|
137
|
+
MULTI_CURRENCY: createCurrencySemantic({
|
|
138
138
|
storageFormat: 'complex_object',
|
|
139
139
|
allowedCurrencies: ['USD', 'EUR', 'GBP', 'JPY', 'CAD'],
|
|
140
140
|
decimalPlaces: 2,
|
|
@@ -144,7 +144,7 @@ export const PRICE_PRESETS = {
|
|
|
144
144
|
/**
|
|
145
145
|
* Configuration that allows negative values for refunds, discounts, etc.
|
|
146
146
|
*/
|
|
147
|
-
WITH_NEGATIVES:
|
|
147
|
+
WITH_NEGATIVES: createCurrencySemantic({
|
|
148
148
|
storageFormat: 'decimal',
|
|
149
149
|
defaultCurrency: 'USD',
|
|
150
150
|
decimalPlaces: 2,
|
|
@@ -154,7 +154,7 @@ export const PRICE_PRESETS = {
|
|
|
154
154
|
/**
|
|
155
155
|
* High-precision configuration for cryptocurrency or precious metals.
|
|
156
156
|
*/
|
|
157
|
-
HIGH_PRECISION:
|
|
157
|
+
HIGH_PRECISION: createCurrencySemantic({
|
|
158
158
|
storageFormat: 'decimal',
|
|
159
159
|
defaultCurrency: 'BTC',
|
|
160
160
|
decimalPlaces: 8,
|
|
@@ -163,9 +163,9 @@ export const PRICE_PRESETS = {
|
|
|
163
163
|
} as const
|
|
164
164
|
|
|
165
165
|
/**
|
|
166
|
-
* Helper function to validate a
|
|
166
|
+
* Helper function to validate a currency configuration.
|
|
167
167
|
*/
|
|
168
|
-
export const
|
|
168
|
+
export const validateCurrencyConfig = (config: CurrencyConfig): string[] => {
|
|
169
169
|
const errors: string[] = []
|
|
170
170
|
|
|
171
171
|
if (config.storageFormat !== 'complex_object' && !config.defaultCurrency) {
|
|
@@ -10,12 +10,25 @@ export interface HTMLConfig {
|
|
|
10
10
|
* List of allowed HTML tags in the content.
|
|
11
11
|
*/
|
|
12
12
|
allowedTags?: string[]
|
|
13
|
-
/**
|
|
14
|
-
* Maximum length of the HTML content.
|
|
15
|
-
*/
|
|
16
|
-
maxLength?: number
|
|
17
13
|
/**
|
|
18
14
|
* Render mode: 'html', 'text', or 'both'.
|
|
15
|
+
*
|
|
16
|
+
* - `html` - The API returns the HTML content as-is (after sanitization based on your other rules like allowedTags).
|
|
17
|
+
* - `text` - The API returns the text content, stripping out all HTML tags.
|
|
18
|
+
* This is extremely useful for various backend and frontend tasks:
|
|
19
|
+
* - **Search Indexing**: You can easily feed the plain text content into a search engine like Elasticsearch
|
|
20
|
+
* without the noise of HTML tags.
|
|
21
|
+
* - **Content Previews/Summaries**: Displaying a snippet of the content in a list view or a notification
|
|
22
|
+
* where formatting is not desired.
|
|
23
|
+
* - **Compatibility**: Sending the content to systems that don't support HTML, such as plain-text
|
|
24
|
+
* emails or SMS notifications.
|
|
25
|
+
* - `both` - The API returns an object containing both the raw HTML and the plain text version. For example:
|
|
26
|
+
* ```json
|
|
27
|
+
* {
|
|
28
|
+
* "html": "<p>Hello, <strong>world</strong>!</p>",
|
|
29
|
+
* "text": "Hello, world!"
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
19
32
|
*/
|
|
20
33
|
renderMode?: 'html' | 'text' | 'both'
|
|
21
34
|
/**
|
|
@@ -106,7 +119,6 @@ export const createHTMLSemantic = (config: HTMLConfig = {}): AppliedHTMLSemantic
|
|
|
106
119
|
*/
|
|
107
120
|
export const DEFAULT_HTML_CONFIG: HTMLConfig = {
|
|
108
121
|
allowedTags: ['b', 'i', 'em', 'strong', 'a', 'ul', 'ol', 'li', 'p', 'br', 'pre', 'code', 'div', 'span'],
|
|
109
|
-
maxLength: 10000,
|
|
110
122
|
renderMode: 'html',
|
|
111
123
|
sanitizeLevel: 'strict',
|
|
112
124
|
allowImages: true,
|
|
@@ -10,12 +10,20 @@ export interface MarkdownConfig {
|
|
|
10
10
|
* List of allowed HTML tags in the rendered output.
|
|
11
11
|
*/
|
|
12
12
|
allowedTags?: string[]
|
|
13
|
-
/**
|
|
14
|
-
* Maximum length of the markdown content.
|
|
15
|
-
*/
|
|
16
|
-
maxLength?: number
|
|
17
13
|
/**
|
|
18
14
|
* Render mode: 'html', 'text', or 'both'.
|
|
15
|
+
* This controls how the stored Markdown content is transformed and returned by the API.
|
|
16
|
+
*
|
|
17
|
+
* - `html` - The API converts the Markdown to HTML and returns the sanitized result.
|
|
18
|
+
* - `text` - The original Markdown as when created, but sanitized.
|
|
19
|
+
* - `both` - The API returns an object containing both the rendered HTML and the plain text version.
|
|
20
|
+
* This provides maximum flexibility for client applications.
|
|
21
|
+
* ```json
|
|
22
|
+
* {
|
|
23
|
+
* "html": "<h1>Title</h1><p>Some <strong>bold</strong> text.</p>",
|
|
24
|
+
* "text": "Title Some bold text."
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
19
27
|
*/
|
|
20
28
|
renderMode?: 'html' | 'text' | 'both'
|
|
21
29
|
/**
|
|
@@ -102,7 +110,6 @@ export const createMarkdownSemantic = (config: MarkdownConfig = {}): AppliedMark
|
|
|
102
110
|
*/
|
|
103
111
|
export const DEFAULT_MARKDOWN_CONFIG: MarkdownConfig = {
|
|
104
112
|
allowedTags: ['b', 'i', 'em', 'strong', 'a', 'ul', 'ol', 'li', 'p', 'br', 'pre', 'code'],
|
|
105
|
-
maxLength: 10000,
|
|
106
113
|
renderMode: 'html',
|
|
107
114
|
sanitizeLevel: 'strict',
|
|
108
115
|
allowImages: true,
|
|
@@ -17,7 +17,7 @@ export interface StatusConfig {
|
|
|
17
17
|
* Default state when creating new records.
|
|
18
18
|
* Must be one of the allowedStates (if specified) or enum values from the schema.
|
|
19
19
|
*/
|
|
20
|
-
defaultState
|
|
20
|
+
defaultState?: string
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* State transitions configuration.
|
|
@@ -200,6 +200,7 @@ export const createStatusSemantic = (config: Partial<StatusConfig> = {}): Applie
|
|
|
200
200
|
* Default configuration for Status semantic.
|
|
201
201
|
*/
|
|
202
202
|
export const DEFAULT_STATUS_CONFIG: StatusConfig = {
|
|
203
|
+
allowedStates: ['draft', 'published', 'archived'],
|
|
203
204
|
defaultState: 'draft',
|
|
204
205
|
stateBehaviors: {
|
|
205
206
|
draft: {
|