@owlmeans/client-config 0.1.0
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/LICENSE +21 -0
- package/README.md +373 -0
- package/build/.gitkeep +0 -0
- package/build/consts.d.ts +2 -0
- package/build/consts.d.ts.map +1 -0
- package/build/consts.js +2 -0
- package/build/consts.js.map +1 -0
- package/build/helper.d.ts +3 -0
- package/build/helper.d.ts.map +1 -0
- package/build/helper.js +25 -0
- package/build/helper.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +3 -0
- package/build/index.js.map +1 -0
- package/build/types.d.ts +8 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/package.json +33 -0
- package/src/consts.ts +2 -0
- package/src/helper.ts +24 -0
- package/src/index.ts +4 -0
- package/src/types.ts +8 -0
- package/tsconfig.json +14 -0
- package/tsconfig.tsbuildinfo +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 OwlMeans Common — Fullstack typescript framework
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
# @owlmeans/client-config
|
|
2
|
+
|
|
3
|
+
Client-side configuration management library for OwlMeans Common applications. This package extends the base `@owlmeans/config` package with client-specific configuration capabilities including web service management, primary host/port settings, and service aliases.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @owlmeans/client-config
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
**Note**: This package depends on `@owlmeans/config` and extends its functionality. Make sure you have the proper OwlMeans Common ecosystem set up in your project.
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
The `@owlmeans/client-config` package is part of the OwlMeans Common libraries ecosystem and provides client-side configuration extensions. It follows the OwlMeans package structure with types, constants, and helpers specifically designed for client-side applications.
|
|
16
|
+
|
|
17
|
+
**Important Note**: This package is not intended to be used separately from the OwlMeans Common ecosystem. It extends the functionality of `@owlmeans/config` and should be used in conjunction with it. The configuration objects created by this package build upon the configuration structure provided by `@owlmeans/config`.
|
|
18
|
+
|
|
19
|
+
### Key Features
|
|
20
|
+
|
|
21
|
+
- **Web Service Management**: Configure and manage web services with aliases
|
|
22
|
+
- **Primary Host/Port Settings**: Set primary host and port configurations
|
|
23
|
+
- **Service Aliases**: Create short aliases for services
|
|
24
|
+
- **Client-Side Extensions**: Extend base configuration with client-specific properties
|
|
25
|
+
- **Seamless Integration**: Works seamlessly with the base `@owlmeans/config` package
|
|
26
|
+
|
|
27
|
+
## Core Concepts
|
|
28
|
+
|
|
29
|
+
### Client Configuration
|
|
30
|
+
|
|
31
|
+
Client configurations extend the base `CommonConfig` from `@owlmeans/config` with client-specific properties that are relevant for client-side applications.
|
|
32
|
+
|
|
33
|
+
### Web Service Management
|
|
34
|
+
|
|
35
|
+
The package provides functionality to manage web services, supporting both single service configurations and multiple aliased services for complex client applications.
|
|
36
|
+
|
|
37
|
+
### Service Aliases
|
|
38
|
+
|
|
39
|
+
Service aliases allow you to create short, memorable names for services, making it easier to reference them in client-side code.
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
### Basic Client Configuration
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { BasicClientConfig, addWebService } from '@owlmeans/client-config'
|
|
47
|
+
import { makeConfig } from '@owlmeans/config'
|
|
48
|
+
import { AppType } from '@owlmeans/config/exports'
|
|
49
|
+
|
|
50
|
+
// Create a client configuration
|
|
51
|
+
const config: BasicClientConfig = makeConfig(AppType.Frontend, 'my-client', {
|
|
52
|
+
webService: 'https://api.example.com',
|
|
53
|
+
primaryHost: 'app.example.com',
|
|
54
|
+
primaryPort: 443,
|
|
55
|
+
shortAlias: 'myapp'
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Adding Web Services
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { addWebService } from '@owlmeans/client-config'
|
|
63
|
+
|
|
64
|
+
// Add a single web service
|
|
65
|
+
const configWithService = addWebService('https://api.example.com', config)
|
|
66
|
+
|
|
67
|
+
// Add a web service with alias
|
|
68
|
+
const configWithAlias = addWebService('https://api.example.com', 'api', config)
|
|
69
|
+
|
|
70
|
+
// Add multiple services with aliases
|
|
71
|
+
let multiServiceConfig = addWebService('https://api.example.com', 'api', config)
|
|
72
|
+
multiServiceConfig = addWebService('https://auth.example.com', 'auth', multiServiceConfig)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## API Reference
|
|
76
|
+
|
|
77
|
+
### Types
|
|
78
|
+
|
|
79
|
+
#### `BasicClientConfig`
|
|
80
|
+
|
|
81
|
+
Extends `CommonConfig` from `@owlmeans/config` with client-specific properties.
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
interface BasicClientConfig extends CommonConfig {
|
|
85
|
+
webService?: string | Record<string, string>
|
|
86
|
+
primaryHost?: string
|
|
87
|
+
primaryPort?: number
|
|
88
|
+
shortAlias?: string
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Properties:**
|
|
93
|
+
|
|
94
|
+
- `webService` - Web service configuration. Can be a single service URL (string) or a record of aliased services
|
|
95
|
+
- `primaryHost` - Primary host for the client application
|
|
96
|
+
- `primaryPort` - Primary port for the client application
|
|
97
|
+
- `shortAlias` - Short alias for the service, useful for client-side identification
|
|
98
|
+
|
|
99
|
+
**Example:**
|
|
100
|
+
```typescript
|
|
101
|
+
const clientConfig: BasicClientConfig = {
|
|
102
|
+
// ... inherited from CommonConfig
|
|
103
|
+
webService: {
|
|
104
|
+
default: 'https://api.example.com',
|
|
105
|
+
auth: 'https://auth.example.com',
|
|
106
|
+
storage: 'https://storage.example.com'
|
|
107
|
+
},
|
|
108
|
+
primaryHost: 'app.example.com',
|
|
109
|
+
primaryPort: 443,
|
|
110
|
+
shortAlias: 'myapp'
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Helper Functions
|
|
115
|
+
|
|
116
|
+
#### `addWebService<C extends BasicClientConfig>(service: string, alias?: string | Partial<C>, cfg?: Partial<C>): C`
|
|
117
|
+
|
|
118
|
+
Adds a web service to the client configuration. This function handles both single services and multiple aliased services.
|
|
119
|
+
|
|
120
|
+
**Parameters:**
|
|
121
|
+
- `service` - The web service URL to add
|
|
122
|
+
- `alias` - Service alias (string) or partial configuration object
|
|
123
|
+
- `cfg` - Optional partial configuration to extend
|
|
124
|
+
|
|
125
|
+
**Returns:** Configuration with added web service
|
|
126
|
+
|
|
127
|
+
**Behavior:**
|
|
128
|
+
- If `alias` is not provided or is an object, sets the service as the default or single web service
|
|
129
|
+
- If `alias` is a string, adds the service with the specified alias
|
|
130
|
+
- Handles conversion between string and record-based web service configurations
|
|
131
|
+
- Maintains existing services when adding new ones
|
|
132
|
+
|
|
133
|
+
**Examples:**
|
|
134
|
+
|
|
135
|
+
**Adding a single web service:**
|
|
136
|
+
```typescript
|
|
137
|
+
const config = addWebService('https://api.example.com')
|
|
138
|
+
// Result: { webService: 'https://api.example.com' }
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Adding a web service with alias:**
|
|
142
|
+
```typescript
|
|
143
|
+
const config = addWebService('https://api.example.com', 'api')
|
|
144
|
+
// Result: { webService: { default: 'https://api.example.com', api: 'https://api.example.com' } }
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**Adding multiple services:**
|
|
148
|
+
```typescript
|
|
149
|
+
let config = addWebService('https://api.example.com', 'api')
|
|
150
|
+
config = addWebService('https://auth.example.com', 'auth', config)
|
|
151
|
+
// Result: {
|
|
152
|
+
// webService: {
|
|
153
|
+
// default: 'https://api.example.com',
|
|
154
|
+
// api: 'https://api.example.com',
|
|
155
|
+
// auth: 'https://auth.example.com'
|
|
156
|
+
// }
|
|
157
|
+
// }
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Adding service with existing string configuration:**
|
|
161
|
+
```typescript
|
|
162
|
+
const baseConfig = { webService: 'https://base.example.com' }
|
|
163
|
+
const config = addWebService('https://api.example.com', 'api', baseConfig)
|
|
164
|
+
// Result: {
|
|
165
|
+
// webService: {
|
|
166
|
+
// default: 'https://base.example.com',
|
|
167
|
+
// api: 'https://api.example.com'
|
|
168
|
+
// }
|
|
169
|
+
// }
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Using partial configuration object:**
|
|
173
|
+
```typescript
|
|
174
|
+
const config = addWebService('https://api.example.com', {
|
|
175
|
+
primaryHost: 'app.example.com',
|
|
176
|
+
shortAlias: 'myapp'
|
|
177
|
+
})
|
|
178
|
+
// Result: {
|
|
179
|
+
// webService: 'https://api.example.com',
|
|
180
|
+
// primaryHost: 'app.example.com',
|
|
181
|
+
// shortAlias: 'myapp'
|
|
182
|
+
// }
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Constants
|
|
186
|
+
|
|
187
|
+
### `DEFAULT_KEY`
|
|
188
|
+
|
|
189
|
+
Default key used for web service configurations when no alias is specified.
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
const DEFAULT_KEY = 'default'
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**Usage:**
|
|
196
|
+
```typescript
|
|
197
|
+
import { DEFAULT_KEY } from '@owlmeans/client-config'
|
|
198
|
+
|
|
199
|
+
// Access default web service
|
|
200
|
+
const defaultService = config.webService?.[DEFAULT_KEY]
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Usage Examples
|
|
204
|
+
|
|
205
|
+
### Complete Client Application Configuration
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
import {
|
|
209
|
+
BasicClientConfig,
|
|
210
|
+
addWebService,
|
|
211
|
+
DEFAULT_KEY
|
|
212
|
+
} from '@owlmeans/client-config'
|
|
213
|
+
import { makeConfig, service } from '@owlmeans/config'
|
|
214
|
+
import { AppType } from '@owlmeans/config/exports'
|
|
215
|
+
|
|
216
|
+
// Create base client configuration
|
|
217
|
+
let config: BasicClientConfig = makeConfig(AppType.Frontend, 'web-app', {
|
|
218
|
+
debug: { enabled: true },
|
|
219
|
+
brand: { home: '/dashboard' },
|
|
220
|
+
primaryHost: 'app.example.com',
|
|
221
|
+
primaryPort: 443,
|
|
222
|
+
shortAlias: 'webapp'
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
// Add web services
|
|
226
|
+
config = addWebService('https://api.example.com', 'api', config)
|
|
227
|
+
config = addWebService('https://auth.example.com', 'auth', config)
|
|
228
|
+
config = addWebService('https://storage.example.com', 'storage', config)
|
|
229
|
+
|
|
230
|
+
// Add backend services (using base config functionality)
|
|
231
|
+
config = service({
|
|
232
|
+
service: 'websocket',
|
|
233
|
+
host: 'ws.example.com',
|
|
234
|
+
port: 8080,
|
|
235
|
+
base: '/ws'
|
|
236
|
+
}, config)
|
|
237
|
+
|
|
238
|
+
console.log('API Service:', config.webService?.api)
|
|
239
|
+
console.log('Auth Service:', config.webService?.auth)
|
|
240
|
+
console.log('Default Service:', config.webService?.[DEFAULT_KEY])
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Dynamic Service Configuration
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
import { addWebService, BasicClientConfig } from '@owlmeans/client-config'
|
|
247
|
+
|
|
248
|
+
class ClientConfigManager {
|
|
249
|
+
private config: BasicClientConfig
|
|
250
|
+
|
|
251
|
+
constructor(baseConfig: BasicClientConfig) {
|
|
252
|
+
this.config = baseConfig
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
addService(url: string, alias: string): void {
|
|
256
|
+
this.config = addWebService(url, alias, this.config)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
getService(alias: string = DEFAULT_KEY): string | undefined {
|
|
260
|
+
if (typeof this.config.webService === 'string') {
|
|
261
|
+
return alias === DEFAULT_KEY ? this.config.webService : undefined
|
|
262
|
+
}
|
|
263
|
+
return this.config.webService?.[alias]
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
getAllServices(): Record<string, string> {
|
|
267
|
+
if (typeof this.config.webService === 'string') {
|
|
268
|
+
return { [DEFAULT_KEY]: this.config.webService }
|
|
269
|
+
}
|
|
270
|
+
return this.config.webService || {}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Usage
|
|
275
|
+
const manager = new ClientConfigManager(baseConfig)
|
|
276
|
+
manager.addService('https://api.example.com', 'api')
|
|
277
|
+
manager.addService('https://auth.example.com', 'auth')
|
|
278
|
+
|
|
279
|
+
const apiUrl = manager.getService('api')
|
|
280
|
+
const allServices = manager.getAllServices()
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Environment-Specific Configuration
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
import { addWebService, BasicClientConfig } from '@owlmeans/client-config'
|
|
287
|
+
|
|
288
|
+
function createEnvironmentConfig(env: 'development' | 'staging' | 'production'): BasicClientConfig {
|
|
289
|
+
const hosts = {
|
|
290
|
+
development: 'localhost:3000',
|
|
291
|
+
staging: 'staging.example.com',
|
|
292
|
+
production: 'app.example.com'
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const apiUrls = {
|
|
296
|
+
development: 'http://localhost:8000',
|
|
297
|
+
staging: 'https://staging-api.example.com',
|
|
298
|
+
production: 'https://api.example.com'
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
let config: BasicClientConfig = {
|
|
302
|
+
primaryHost: hosts[env],
|
|
303
|
+
primaryPort: env === 'development' ? 3000 : 443,
|
|
304
|
+
shortAlias: `app-${env}`
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Add environment-specific services
|
|
308
|
+
config = addWebService(apiUrls[env], 'api', config)
|
|
309
|
+
|
|
310
|
+
if (env !== 'development') {
|
|
311
|
+
config = addWebService(`https://${env}-auth.example.com`, 'auth', config)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return config
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Usage
|
|
318
|
+
const devConfig = createEnvironmentConfig('development')
|
|
319
|
+
const prodConfig = createEnvironmentConfig('production')
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Integration with OwlMeans Ecosystem
|
|
323
|
+
|
|
324
|
+
The `@owlmeans/client-config` package integrates seamlessly with other OwlMeans packages:
|
|
325
|
+
|
|
326
|
+
- **@owlmeans/config**: Provides base configuration functionality that this package extends
|
|
327
|
+
- **@owlmeans/context**: Supports context management for client configurations
|
|
328
|
+
- **@owlmeans/client**: Works with other client-side packages in the ecosystem
|
|
329
|
+
- **@owlmeans/route**: Complements routing capabilities with client configuration
|
|
330
|
+
- **@owlmeans/web-client**: Provides web-specific implementations
|
|
331
|
+
|
|
332
|
+
## Best Practices
|
|
333
|
+
|
|
334
|
+
1. **Service Organization**: Use aliases for different types of services (api, auth, storage, etc.)
|
|
335
|
+
|
|
336
|
+
2. **Environment Configuration**: Create environment-specific configurations for different deployment stages
|
|
337
|
+
|
|
338
|
+
3. **Type Safety**: Always use the `BasicClientConfig` type for type-safe configuration management
|
|
339
|
+
|
|
340
|
+
4. **Service Discovery**: Use meaningful aliases that reflect the service purpose
|
|
341
|
+
|
|
342
|
+
5. **Configuration Validation**: Validate service URLs and configuration before use
|
|
343
|
+
|
|
344
|
+
6. **Fallback Handling**: Always handle cases where services might not be configured
|
|
345
|
+
|
|
346
|
+
## Migration from Base Config
|
|
347
|
+
|
|
348
|
+
If you're migrating from using only `@owlmeans/config`, here's how to adopt client-config:
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
// Before (base config only)
|
|
352
|
+
import { makeConfig } from '@owlmeans/config'
|
|
353
|
+
|
|
354
|
+
const config = makeConfig(AppType.Frontend, 'my-app', {
|
|
355
|
+
// ... base configuration
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
// After (with client-config)
|
|
359
|
+
import { makeConfig } from '@owlmeans/config'
|
|
360
|
+
import { addWebService, BasicClientConfig } from '@owlmeans/client-config'
|
|
361
|
+
|
|
362
|
+
let config: BasicClientConfig = makeConfig(AppType.Frontend, 'my-app', {
|
|
363
|
+
// ... base configuration
|
|
364
|
+
primaryHost: 'app.example.com',
|
|
365
|
+
shortAlias: 'myapp'
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
config = addWebService('https://api.example.com', 'api', config)
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
## License
|
|
372
|
+
|
|
373
|
+
This package is part of the OwlMeans Common libraries and follows the project's licensing terms.
|
package/build/.gitkeep
ADDED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW,YAAY,CAAA"}
|
package/build/consts.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGnD,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,iBAAiB,WAAW,MAAM,UAAU,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,OAAO,CAAC,CAAC,CAAC,KAAG,CAoB3H,CAAA"}
|
package/build/helper.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DEFAULT_KEY } from './consts.js';
|
|
2
|
+
export const addWebService = (service, alias, cfg) => {
|
|
3
|
+
const _cfg = (cfg ?? (typeof alias === 'object' ? alias : undefined) ?? {});
|
|
4
|
+
if (alias == null || typeof alias === 'object') {
|
|
5
|
+
if (typeof _cfg.webService === 'string' || _cfg.webService == null) {
|
|
6
|
+
_cfg.webService = service;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
_cfg.webService[DEFAULT_KEY] = service;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
if (_cfg.webService == null) {
|
|
14
|
+
_cfg.webService = { [DEFAULT_KEY]: service, [alias]: service };
|
|
15
|
+
}
|
|
16
|
+
else if (typeof _cfg.webService === 'string') {
|
|
17
|
+
_cfg.webService = { [DEFAULT_KEY]: _cfg.webService, [alias]: service };
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
_cfg.webService[alias] = service;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return _cfg;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,MAAM,CAAC,MAAM,aAAa,GAAG,CAA8B,OAAe,EAAE,KAA2B,EAAE,GAAgB,EAAK,EAAE;IAC9H,MAAM,IAAI,GAAM,CAAC,GAAG,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAE,IAAI,EAAE,CAAM,CAAA;IAEpF,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/C,IAAI,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,EAAE,CAAC;YACnE,IAAI,CAAC,UAAU,GAAG,OAAO,CAAA;QAC3B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAA;QACxC,CAAC;IACH,CAAC;SAAM,CAAC;QACN,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,EAAE,CAAC;YAC5B,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAA;QAChE,CAAC;aAAM,IAAI,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;YAC/C,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAA;QACxE,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,OAAO,CAAA;QAClC,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CommonConfig } from '@owlmeans/config';
|
|
2
|
+
export interface BasicClientConfig extends CommonConfig {
|
|
3
|
+
webService?: string | Record<string, string>;
|
|
4
|
+
primaryHost?: string;
|
|
5
|
+
primaryPort?: number;
|
|
6
|
+
shortAlias?: string;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD,MAAM,WAAW,iBAAkB,SAAQ,YAAY;IACrD,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB"}
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@owlmeans/client-config",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsc -b",
|
|
7
|
+
"dev": "sleep 72 && nodemon -e ts,tsx,json --watch src --exec \"tsc -p ./tsconfig.json\"",
|
|
8
|
+
"watch": "tsc -b -w --preserveWatchOutput --pretty"
|
|
9
|
+
},
|
|
10
|
+
"main": "build/index.js",
|
|
11
|
+
"module": "build/index.js",
|
|
12
|
+
"types": "build/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./build/index.js",
|
|
16
|
+
"require": "./build/index.js",
|
|
17
|
+
"default": "./build/index.js",
|
|
18
|
+
"module": "./build/index.js",
|
|
19
|
+
"types": "./build/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@owlmeans/config": "^0.1.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"nodemon": "^3.1.7",
|
|
27
|
+
"typescript": "^5.6.3"
|
|
28
|
+
},
|
|
29
|
+
"private": false,
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/consts.ts
ADDED
package/src/helper.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BasicClientConfig } from './types.js'
|
|
2
|
+
import { DEFAULT_KEY } from './consts.js'
|
|
3
|
+
|
|
4
|
+
export const addWebService = <C extends BasicClientConfig>(service: string, alias?: string | Partial<C>, cfg?: Partial<C>): C => {
|
|
5
|
+
const _cfg: C = (cfg ?? (typeof alias === 'object' ? alias : undefined ) ?? {}) as C
|
|
6
|
+
|
|
7
|
+
if (alias == null || typeof alias === 'object') {
|
|
8
|
+
if (typeof _cfg.webService === 'string' || _cfg.webService == null) {
|
|
9
|
+
_cfg.webService = service
|
|
10
|
+
} else {
|
|
11
|
+
_cfg.webService[DEFAULT_KEY] = service
|
|
12
|
+
}
|
|
13
|
+
} else {
|
|
14
|
+
if (_cfg.webService == null) {
|
|
15
|
+
_cfg.webService = { [DEFAULT_KEY]: service, [alias]: service }
|
|
16
|
+
} else if (typeof _cfg.webService === 'string') {
|
|
17
|
+
_cfg.webService = { [DEFAULT_KEY]: _cfg.webService, [alias]: service }
|
|
18
|
+
} else {
|
|
19
|
+
_cfg.webService[alias] = service
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return _cfg
|
|
24
|
+
}
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"../tsconfig.default.json",
|
|
4
|
+
],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"rootDir": "./src/", /* Specify the root folder within your source files. */
|
|
7
|
+
"outDir": "./build/", /* Specify an output folder for all emitted files. */
|
|
8
|
+
},
|
|
9
|
+
"exclude": [
|
|
10
|
+
"./dist/**/*",
|
|
11
|
+
"./build/**/*",
|
|
12
|
+
"./*.ts"
|
|
13
|
+
]
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/consts.ts","./src/helper.ts","./src/index.ts","./src/types.ts"],"version":"5.6.3"}
|