@izumisy-tailor/omakase-modules 0.3.0 → 0.4.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.
- package/README.md +0 -16
- package/docs/generated/README.md +35 -0
- package/docs/{tutorials → generated/_media}/creating-modules.md +192 -17
- package/docs/{tutorials → generated/_media}/using-modules.md +17 -18
- package/docs/generated/builder/README.md +25 -0
- package/docs/generated/builder/functions/defineModule.md +60 -0
- package/docs/generated/builder/functions/withModuleConfiguration.md +68 -0
- package/docs/generated/builder/type-aliases/AnyDefinedModule.md +57 -0
- package/docs/generated/builder/type-aliases/ConfiguredDependencies.md +44 -0
- package/docs/generated/builder/type-aliases/ConfiguredModule.md +60 -0
- package/docs/generated/builder/type-aliases/DefinedModule.md +93 -0
- package/docs/generated/builder/type-aliases/DependencyModules.md +29 -0
- package/docs/generated/builder/type-aliases/EmptyDependencies.md +34 -0
- package/docs/generated/builder/type-aliases/ModuleBuilder.md +124 -0
- package/docs/generated/builder/type-aliases/ModuleBuilderProps.md +42 -0
- package/docs/generated/builder/type-aliases/ModuleFactoryContext.md +40 -0
- package/docs/generated/builder/type-aliases/TablesFromNames.md +28 -0
- package/docs/generated/config/README.md +19 -0
- package/docs/generated/config/classes/ModuleLoader.md +128 -0
- package/docs/generated/config/functions/loadModules.md +79 -0
- package/docs/generated/config/sdk/README.md +16 -0
- package/docs/generated/config/sdk/functions/getModulesReference.md +81 -0
- package/docs/generated/config/sdk/functions/loadModuleForDev.md +53 -0
- package/docs/generated/config/sdk/type-aliases/GetModulesReferenceOptions.md +60 -0
- package/docs/generated/config/type-aliases/LoadedModules.md +162 -0
- package/docs/generated/modules.md +11 -0
- package/package.json +11 -7
- package/src/builder/helpers.ts +347 -27
- package/src/builder/index.ts +6 -1
- package/src/builder/register.ts +3 -6
- package/src/config/module-loader.ts +234 -12
- package/src/config/sdk/dev-context.ts +82 -0
- package/src/config/sdk/index.ts +2 -1
- package/src/config/sdk/paths.ts +85 -3
- package/src/config/sdk/wrapper/base.ts +68 -15
- package/src/config/sdk/wrapper/generator.ts +40 -3
- package/src/config/sdk/wrapper/strategies.ts +32 -13
package/README.md
CHANGED
|
@@ -29,19 +29,3 @@ pnpm add @izumisy-tailor/omakase-modules
|
|
|
29
29
|
|
|
30
30
|
- [Using Modules](./docs/tutorials/using-modules.md) - How to use pre-built modules in your application
|
|
31
31
|
- [Creating Modules](./docs/tutorials/creating-modules.md) - How to create reusable modules
|
|
32
|
-
|
|
33
|
-
## API Reference
|
|
34
|
-
|
|
35
|
-
### `@izumisy-tailor/omakase-modules`
|
|
36
|
-
|
|
37
|
-
- `loadModules(configurator)` - Load and configure modules in your application
|
|
38
|
-
|
|
39
|
-
### `@izumisy-tailor/omakase-modules/builder`
|
|
40
|
-
|
|
41
|
-
- `defineModule<Config, Tables>(options)` - Define a new module
|
|
42
|
-
- `withModuleConfiguration(module, factory)` - Access module configuration in TailorDB, Resolvers, and Executors
|
|
43
|
-
- `ModuleDependency<T>` - Type utility for declaring module dependencies
|
|
44
|
-
|
|
45
|
-
### `@izumisy-tailor/omakase-modules/config/sdk`
|
|
46
|
-
|
|
47
|
-
- `getModulesReference(loadedModules)` - Generate file path references for `tailor.config.ts`
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
**@izumisy-tailor/omakase-modules**
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
# Omakase Modules
|
|
6
|
+
|
|
7
|
+
A **configurable module system** for Tailor Platform. Define reusable modules with type-safe configurations and share them across applications.
|
|
8
|
+
|
|
9
|
+
## Motivation
|
|
10
|
+
|
|
11
|
+
When building applications on Tailor Platform, you often face these challenges:
|
|
12
|
+
|
|
13
|
+
1. **Reusability**: You want to reuse common data models and business logic (e.g., e-commerce, inventory, orders) across multiple applications
|
|
14
|
+
2. **Customizability**: While modules should be reusable, you need to customize them for application-specific requirements
|
|
15
|
+
3. **Dependency Management**: Module dependencies should be explicitly defined and managed in a type-safe manner
|
|
16
|
+
|
|
17
|
+
Omakase Modules is designed to solve these challenges by providing a flexible, type-safe module system.
|
|
18
|
+
|
|
19
|
+
## Key Features
|
|
20
|
+
|
|
21
|
+
- **Module Definition**: Define modules with `defineModule` and declare type-safe configuration schemas
|
|
22
|
+
- **Module Configuration**: Configure modules at the application level, injecting custom attributes and prefixes
|
|
23
|
+
- **Dependency Management**: Explicitly define inter-module dependencies with the `ModuleDependency` type
|
|
24
|
+
- **Configuration Injection**: Inject configurations into TailorDB, Resolvers, and Executors using `withModuleConfiguration`
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add @izumisy-tailor/omakase-modules
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Documentation
|
|
33
|
+
|
|
34
|
+
- [Using Modules](_media/using-modules.md) - How to use pre-built modules in your application
|
|
35
|
+
- [Creating Modules](_media/creating-modules.md) - How to create reusable modules
|
|
@@ -22,9 +22,29 @@ my-module/
|
|
|
22
22
|
my-executor.ts
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
## Prerequisites: tsconfig.json Path Aliases
|
|
26
|
+
|
|
27
|
+
Your module's `tsconfig.json` must include the following path aliases for the module system to function correctly:
|
|
28
|
+
|
|
29
|
+
```jsonc
|
|
30
|
+
{
|
|
31
|
+
"compilerOptions": {
|
|
32
|
+
"paths": {
|
|
33
|
+
"@omakase-modules/config": ["./src/module"],
|
|
34
|
+
"@/*": ["./src/*"]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
| Alias | Path | Purpose |
|
|
41
|
+
|-------|------|---------|
|
|
42
|
+
| `@omakase-modules/config` | `["./src/module"]` | **Required**. Points to your module definition file. The wrapper generator uses this alias to import your module's configuration during code generation. |
|
|
43
|
+
| `@/*` | `["./src/*"]` | **Required**. Provides a shorthand for importing from the `src/` directory. Used internally during development mode to resolve local source files. |
|
|
44
|
+
|
|
25
45
|
## 1. Define the Module
|
|
26
46
|
|
|
27
|
-
Create the module definition with `defineModule
|
|
47
|
+
Create the module definition with `defineModule`. The module definition uses a builder pattern:
|
|
28
48
|
|
|
29
49
|
```typescript
|
|
30
50
|
// src/module.ts
|
|
@@ -38,11 +58,19 @@ import * as pkg from "../package.json";
|
|
|
38
58
|
|
|
39
59
|
export default defineModule<ModuleConfig, TablesFromNames<typeof tableNames>>({
|
|
40
60
|
packageName: pkg.name,
|
|
41
|
-
})
|
|
61
|
+
})
|
|
62
|
+
.withDevConfig({}) // Optional: default config for development
|
|
63
|
+
.build();
|
|
42
64
|
```
|
|
43
65
|
|
|
44
66
|
The `packageName` must match the `name` field in your `package.json`. The `TablesFromNames` utility type derives the table types from `tableNames`, ensuring they stay in sync.
|
|
45
67
|
|
|
68
|
+
### Builder Methods
|
|
69
|
+
|
|
70
|
+
- `.withDevConfig(config)` - Sets the default configuration used during module development
|
|
71
|
+
- `.withDependencies(deps)` - Declares dependencies on other modules (see section 4)
|
|
72
|
+
- `.build()` - Finalizes the module definition (must be called at the end)
|
|
73
|
+
|
|
46
74
|
## 2. Define Configuration Types
|
|
47
75
|
|
|
48
76
|
Define what configuration options your module accepts:
|
|
@@ -127,22 +155,31 @@ export const buildProductTable = (
|
|
|
127
155
|
|
|
128
156
|
## 4. Declare Dependencies on Other Modules
|
|
129
157
|
|
|
130
|
-
If your module depends on other modules, use `
|
|
158
|
+
If your module depends on other modules, use `.withDependencies()` in your module definition:
|
|
131
159
|
|
|
132
160
|
```typescript
|
|
133
|
-
// src/
|
|
134
|
-
import
|
|
135
|
-
|
|
161
|
+
// src/module.ts
|
|
162
|
+
import {
|
|
163
|
+
defineModule,
|
|
164
|
+
type TablesFromNames,
|
|
165
|
+
} from "@izumisy-tailor/omakase-modules/builder";
|
|
166
|
+
import { ModuleConfig } from "./types";
|
|
167
|
+
import { tableNames } from "./tailordb";
|
|
168
|
+
import * as pkg from "../package.json";
|
|
169
|
+
import commerceModule from "omakase-module-commerce-core";
|
|
170
|
+
import orderModule from "omakase-module-order";
|
|
136
171
|
|
|
137
|
-
export
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
172
|
+
export default defineModule<ModuleConfig, TablesFromNames<typeof tableNames>>({
|
|
173
|
+
packageName: pkg.name,
|
|
174
|
+
})
|
|
175
|
+
.withDevConfig({
|
|
176
|
+
dbNamespace: "main-db",
|
|
177
|
+
})
|
|
178
|
+
.withDependencies({ commerce: commerceModule, order: orderModule })
|
|
179
|
+
.build();
|
|
143
180
|
```
|
|
144
181
|
|
|
145
|
-
This ensures type-safe dependency injection when users configure your module.
|
|
182
|
+
The dependency modules are passed directly to `.withDependencies()`. This ensures type-safe dependency injection when users configure your module.
|
|
146
183
|
|
|
147
184
|
### Using Dependency Tables in TailorDB
|
|
148
185
|
|
|
@@ -150,9 +187,22 @@ When your module needs to reference tables from dependency modules, use `loadedM
|
|
|
150
187
|
|
|
151
188
|
```typescript
|
|
152
189
|
// src/tailordb/index.ts
|
|
153
|
-
import {
|
|
190
|
+
import {
|
|
191
|
+
withModuleConfiguration,
|
|
192
|
+
type TablesFromNames,
|
|
193
|
+
} from "@izumisy-tailor/omakase-modules/builder";
|
|
154
194
|
import moduleDef from "../module";
|
|
195
|
+
import { buildInventoryTable } from "./inventory";
|
|
196
|
+
import { buildInventoryTransactionTable } from "./inventory-transaction";
|
|
197
|
+
import { buildStockAdjustmentTable } from "./stock-adjustment";
|
|
155
198
|
import commerceModuleTables from "omakase-module-commerce-core/backend/tailordb";
|
|
199
|
+
import orderModuleTables from "omakase-module-order/backend/tailordb";
|
|
200
|
+
|
|
201
|
+
export const tableNames = [
|
|
202
|
+
"inventory",
|
|
203
|
+
"inventoryTransaction",
|
|
204
|
+
"stockAdjustment",
|
|
205
|
+
] as const;
|
|
156
206
|
|
|
157
207
|
export default withModuleConfiguration(
|
|
158
208
|
moduleDef,
|
|
@@ -161,9 +211,22 @@ export default withModuleConfiguration(
|
|
|
161
211
|
const { product, productVariant } = await loadedModules.getTables(
|
|
162
212
|
commerceModuleTables
|
|
163
213
|
);
|
|
214
|
+
const { order } = await loadedModules.getTables(orderModuleTables);
|
|
164
215
|
|
|
165
216
|
const inventory = buildInventoryTable(context, { product, productVariant });
|
|
166
|
-
|
|
217
|
+
const inventoryTransaction = buildInventoryTransactionTable(context, {
|
|
218
|
+
inventory,
|
|
219
|
+
order,
|
|
220
|
+
});
|
|
221
|
+
const stockAdjustment = buildStockAdjustmentTable(context, {
|
|
222
|
+
inventory,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
inventory,
|
|
227
|
+
inventoryTransaction,
|
|
228
|
+
stockAdjustment,
|
|
229
|
+
} satisfies TablesFromNames<typeof tableNames>;
|
|
167
230
|
}
|
|
168
231
|
);
|
|
169
232
|
```
|
|
@@ -236,7 +299,119 @@ src/executors/
|
|
|
236
299
|
|
|
237
300
|
This is because the Tailor SDK processes resolver and executor files individually, expecting each file to contain a single definition with a default export.
|
|
238
301
|
|
|
239
|
-
## 5.
|
|
302
|
+
## 5. Set Up tailor.config.ts for Module Development
|
|
303
|
+
|
|
304
|
+
Every module needs a `tailor.config.ts` file for development. This file uses `loadModuleForDev` to resolve the module's factory functions into actual TailorDB table definitions, enabling the Tailor SDK's generator to produce Kysely type definitions.
|
|
305
|
+
|
|
306
|
+
### Why tailor.config.ts is Required
|
|
307
|
+
|
|
308
|
+
Omakase Modules use a factory pattern—tables are not defined directly but through `withModuleConfiguration` functions that receive configuration at runtime. The Tailor SDK's `@tailor-platform/kysely-type` generator needs concrete table definitions to generate TypeScript types.
|
|
309
|
+
|
|
310
|
+
`loadModuleForDev` bridges this gap by:
|
|
311
|
+
1. Resolving your module's factory functions with the `devConfig` you defined
|
|
312
|
+
2. Automatically registering any dependency modules
|
|
313
|
+
3. Producing actual TailorDB table definitions that the generator can process
|
|
314
|
+
|
|
315
|
+
The generated Kysely types (`src/generated/tailordb.ts`) enable:
|
|
316
|
+
- **Type-safe SQL queries** in your module's executors and resolvers
|
|
317
|
+
- **Cross-module JOIN queries** when other modules depend on yours via the `getDB` function
|
|
318
|
+
|
|
319
|
+
### Basic tailor.config.ts
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
// tailor.config.ts
|
|
323
|
+
import { defineConfig, defineGenerators } from "@tailor-platform/sdk";
|
|
324
|
+
import {
|
|
325
|
+
loadModuleForDev,
|
|
326
|
+
getModulesReference,
|
|
327
|
+
} from "@izumisy-tailor/omakase-modules/config/sdk";
|
|
328
|
+
import myModule from "./src/module";
|
|
329
|
+
|
|
330
|
+
const moduleReference = await getModulesReference(
|
|
331
|
+
loadModuleForDev(myModule)
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
export default defineConfig({
|
|
335
|
+
name: "my-module",
|
|
336
|
+
|
|
337
|
+
db: {
|
|
338
|
+
"main-db": {
|
|
339
|
+
files: [...moduleReference.tailordb],
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
export const generators = defineGenerators([
|
|
345
|
+
"@tailor-platform/kysely-type",
|
|
346
|
+
{ distPath: "./src/generated/tailordb.ts" },
|
|
347
|
+
]);
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
> **Note**: Resolvers and executors are not required in `tailor.config.ts` during module development. The primary purpose is to generate Kysely type definitions for type-safe database queries.
|
|
351
|
+
|
|
352
|
+
### The Role of devConfig
|
|
353
|
+
|
|
354
|
+
The `devConfig` you define in your module with `.withDevConfig()` is the default configuration used by `loadModuleForDev`. This allows the generator to produce type definitions without explicitly passing configuration each time.
|
|
355
|
+
|
|
356
|
+
If your module doesn't require any configuration, you can omit `.withDevConfig()` entirely—`loadModuleForDev` will use an empty object `{}` as the default.
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
// src/module.ts - module with configuration
|
|
360
|
+
export default defineModule<ModuleConfig, TablesFromNames<typeof tableNames>>({
|
|
361
|
+
packageName: pkg.name,
|
|
362
|
+
})
|
|
363
|
+
.withDevConfig({
|
|
364
|
+
// Default configuration for development
|
|
365
|
+
dataModel: {
|
|
366
|
+
product: { docNumberPrefix: "DEV" },
|
|
367
|
+
},
|
|
368
|
+
})
|
|
369
|
+
.build();
|
|
370
|
+
|
|
371
|
+
// src/module.ts - module without configuration (withDevConfig can be omitted)
|
|
372
|
+
export default defineModule<ModuleConfig, TablesFromNames<typeof tableNames>>({
|
|
373
|
+
packageName: pkg.name,
|
|
374
|
+
}).build();
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
When `loadModuleForDev(myModule)` is called without a second argument, it uses this `devConfig` (or `{}` if not defined). You can override it by passing a custom config:
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
// Use custom config instead of devConfig
|
|
381
|
+
loadModuleForDev(myModule, {
|
|
382
|
+
dataModel: {
|
|
383
|
+
product: { docNumberPrefix: "TEST" },
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
This flexibility is useful for:
|
|
389
|
+
- **Multiple tailor.config.ts files**: When you need different configurations for different environments (e.g., testing vs development)
|
|
390
|
+
- **Temporary overrides**: When you want to test with a different configuration without modifying `devConfig`
|
|
391
|
+
- **CI/CD pipelines**: When configuration needs to be passed dynamically from environment variables
|
|
392
|
+
|
|
393
|
+
### Handling Dependencies in Development
|
|
394
|
+
|
|
395
|
+
When your module has dependencies declared with `.withDependencies()`, `loadModuleForDev` automatically registers all dependency modules with empty configurations. This allows the generator to produce types that include dependency tables, enabling JOIN queries across module boundaries.
|
|
396
|
+
|
|
397
|
+
```typescript
|
|
398
|
+
// Module with dependencies
|
|
399
|
+
export default defineModule<ModuleConfig, TablesFromNames<typeof tableNames>>({
|
|
400
|
+
packageName: pkg.name,
|
|
401
|
+
})
|
|
402
|
+
.withDependencies({ commerce: commerceModule })
|
|
403
|
+
.withDevConfig({ /* ... */ })
|
|
404
|
+
.build();
|
|
405
|
+
|
|
406
|
+
// In tailor.config.ts - dependencies are auto-registered
|
|
407
|
+
const moduleReference = await getModulesReference(
|
|
408
|
+
loadModuleForDev(myModule) // commerceModule is automatically loaded with {}
|
|
409
|
+
);
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
> **Note**: In development context, dependency modules are registered with empty configurations (`{}`). Actual configuration for dependencies is provided when your module is used in an application via `loadModules`.
|
|
413
|
+
|
|
414
|
+
## 6. Configure Package Exports
|
|
240
415
|
|
|
241
416
|
Set up your `package.json` to export the module files.
|
|
242
417
|
|
|
@@ -248,6 +423,7 @@ Set up your `package.json` to export the module files.
|
|
|
248
423
|
"type": "module",
|
|
249
424
|
"exports": {
|
|
250
425
|
".": "./src/module.ts",
|
|
426
|
+
"./db": "./src/db.ts",
|
|
251
427
|
"./backend/tailordb": "./src/tailordb/index.ts",
|
|
252
428
|
"./backend/resolvers/*": "./src/resolvers/*.ts",
|
|
253
429
|
"./backend/executors/*": "./src/executors/*.ts"
|
|
@@ -289,7 +465,6 @@ The `@izumisy-tailor/omakase-modules/builder` package provides these utility typ
|
|
|
289
465
|
|------|-------------|
|
|
290
466
|
| `TablesFromNames<T>` | Derives a tables type from a `tableNames` array. `T` should be `typeof tableNames`. |
|
|
291
467
|
| `ModuleFactoryContext<C>` | Context passed to table builder functions. `C` is your module's config type. |
|
|
292
|
-
| `ModuleDependency<T>` | Type for declaring dependencies on other modules. `T` is the module's default export type. |
|
|
293
468
|
|
|
294
469
|
## Next Steps
|
|
295
470
|
|
|
@@ -100,7 +100,7 @@ The wrapper generator creates files that:
|
|
|
100
100
|
|
|
101
101
|
## 4. Handle Module Dependencies
|
|
102
102
|
|
|
103
|
-
When modules depend on other modules, you need to wire them together:
|
|
103
|
+
When modules depend on other modules, you need to wire them together. The `loader.add()` method returns the configured module, which can then be passed as a dependency to other modules via the `dependencies` property:
|
|
104
104
|
|
|
105
105
|
```typescript
|
|
106
106
|
// modules.ts
|
|
@@ -112,7 +112,7 @@ import inventoryModule from "omakase-module-inventory";
|
|
|
112
112
|
|
|
113
113
|
export default loadModules((loader) => {
|
|
114
114
|
// Add the base module first
|
|
115
|
-
const $
|
|
115
|
+
const $ecommerceModule = loader.add(
|
|
116
116
|
ecommerceCoreModule.configure({
|
|
117
117
|
config: {
|
|
118
118
|
dataModel: {
|
|
@@ -127,14 +127,13 @@ export default loadModules((loader) => {
|
|
|
127
127
|
})
|
|
128
128
|
);
|
|
129
129
|
|
|
130
|
-
// Pass the commerce module as a dependency
|
|
131
|
-
const $
|
|
130
|
+
// Pass the commerce module as a dependency via the dependencies property
|
|
131
|
+
const $orderModule = loader.add(
|
|
132
132
|
orderModule.configure({
|
|
133
133
|
config: {
|
|
134
|
-
|
|
135
|
-
commerce: $commerce,
|
|
136
|
-
},
|
|
134
|
+
dataModel: {},
|
|
137
135
|
},
|
|
136
|
+
dependencies: { commerce: $ecommerceModule },
|
|
138
137
|
})
|
|
139
138
|
);
|
|
140
139
|
|
|
@@ -142,12 +141,10 @@ export default loadModules((loader) => {
|
|
|
142
141
|
loader.add(
|
|
143
142
|
inventoryModule.configure({
|
|
144
143
|
config: {
|
|
145
|
-
dbNamespace: "main",
|
|
146
|
-
|
|
147
|
-
commerce: $commerce,
|
|
148
|
-
order: $order,
|
|
149
|
-
},
|
|
144
|
+
dbNamespace: "main-db",
|
|
145
|
+
invantoryBootstrapBaseValue: 300,
|
|
150
146
|
},
|
|
147
|
+
dependencies: { commerce: $ecommerceModule, order: $orderModule },
|
|
151
148
|
})
|
|
152
149
|
);
|
|
153
150
|
|
|
@@ -155,7 +152,7 @@ export default loadModules((loader) => {
|
|
|
155
152
|
});
|
|
156
153
|
```
|
|
157
154
|
|
|
158
|
-
|
|
155
|
+
Note that dependencies are passed as a separate `dependencies` property alongside `config`, not nested inside `config`. This ensures type-safe dependency wiring.
|
|
159
156
|
|
|
160
157
|
## Common Configuration Options
|
|
161
158
|
|
|
@@ -198,11 +195,13 @@ Some modules have their own configuration options:
|
|
|
198
195
|
|
|
199
196
|
```typescript
|
|
200
197
|
// Inventory module example
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
198
|
+
inventoryModule.configure({
|
|
199
|
+
config: {
|
|
200
|
+
dbNamespace: "main", // Required: TailorDB namespace for this module
|
|
201
|
+
invantoryBootstrapBaseValue: 200, // Module-specific option
|
|
202
|
+
},
|
|
203
|
+
dependencies: { commerce: $ecommerceModule, order: $orderModule },
|
|
204
|
+
})
|
|
206
205
|
```
|
|
207
206
|
|
|
208
207
|
## Troubleshooting
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[**@izumisy-tailor/omakase-modules**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@izumisy-tailor/omakase-modules](../modules.md) / builder
|
|
6
|
+
|
|
7
|
+
# builder
|
|
8
|
+
|
|
9
|
+
## Type Aliases
|
|
10
|
+
|
|
11
|
+
- [AnyDefinedModule](type-aliases/AnyDefinedModule.md)
|
|
12
|
+
- [ConfiguredDependencies](type-aliases/ConfiguredDependencies.md)
|
|
13
|
+
- [ConfiguredModule](type-aliases/ConfiguredModule.md)
|
|
14
|
+
- [DefinedModule](type-aliases/DefinedModule.md)
|
|
15
|
+
- [DependencyModules](type-aliases/DependencyModules.md)
|
|
16
|
+
- [EmptyDependencies](type-aliases/EmptyDependencies.md)
|
|
17
|
+
- [ModuleBuilder](type-aliases/ModuleBuilder.md)
|
|
18
|
+
- [ModuleBuilderProps](type-aliases/ModuleBuilderProps.md)
|
|
19
|
+
- [ModuleFactoryContext](type-aliases/ModuleFactoryContext.md)
|
|
20
|
+
- [TablesFromNames](type-aliases/TablesFromNames.md)
|
|
21
|
+
|
|
22
|
+
## Functions
|
|
23
|
+
|
|
24
|
+
- [defineModule](functions/defineModule.md)
|
|
25
|
+
- [withModuleConfiguration](functions/withModuleConfiguration.md)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
[**@izumisy-tailor/omakase-modules**](../../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@izumisy-tailor/omakase-modules](../../modules.md) / [builder](../README.md) / defineModule
|
|
6
|
+
|
|
7
|
+
# Function: defineModule()
|
|
8
|
+
|
|
9
|
+
> **defineModule**\<`C`, `Tables`\>(`baseProps`): [`ModuleBuilder`](../type-aliases/ModuleBuilder.md)\<`C`, `Tables`\>
|
|
10
|
+
|
|
11
|
+
Defined in: [builder/helpers.ts:341](https://github.com/tailor-sandbox/omakase-modules/blob/c8d6563533665d8bb159b4602b5c906b40e938f2/packages/core/src/builder/helpers.ts#L341)
|
|
12
|
+
|
|
13
|
+
Defines a reusable module with optional dependencies on other modules.
|
|
14
|
+
|
|
15
|
+
## Type Parameters
|
|
16
|
+
|
|
17
|
+
| Type Parameter | Default type |
|
|
18
|
+
| ------ | ------ |
|
|
19
|
+
| `C` *extends* `Record`\<`string`, `unknown`\> | - |
|
|
20
|
+
| `Tables` *extends* `Record`\<`string`, `unknown`\> | `Record`\<`string`, `unknown`\> |
|
|
21
|
+
|
|
22
|
+
## Parameters
|
|
23
|
+
|
|
24
|
+
| Parameter | Type |
|
|
25
|
+
| ------ | ------ |
|
|
26
|
+
| `baseProps` | \{ `packageName`: `string`; \} |
|
|
27
|
+
| `baseProps.packageName` | `string` |
|
|
28
|
+
|
|
29
|
+
## Returns
|
|
30
|
+
|
|
31
|
+
[`ModuleBuilder`](../type-aliases/ModuleBuilder.md)\<`C`, `Tables`\>
|
|
32
|
+
|
|
33
|
+
## Example
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
// Module without dependencies
|
|
37
|
+
export default defineModule<ModuleConfig, Tables>({
|
|
38
|
+
packageName: "my-module",
|
|
39
|
+
}).build();
|
|
40
|
+
|
|
41
|
+
// Module with dependencies - Deps type is automatically inferred
|
|
42
|
+
import commerceModule from "omakase-module-commerce-core";
|
|
43
|
+
import orderModule from "omakase-module-order";
|
|
44
|
+
|
|
45
|
+
export default defineModule<ModuleConfig, Tables>({
|
|
46
|
+
packageName: "my-module",
|
|
47
|
+
}).withDependencies({
|
|
48
|
+
commerce: commerceModule,
|
|
49
|
+
order: orderModule,
|
|
50
|
+
}).build();
|
|
51
|
+
|
|
52
|
+
// When configuring a module with dependencies, pass them as a record:
|
|
53
|
+
inventoryModule.configure({
|
|
54
|
+
config: { dbNamespace: "main-db" },
|
|
55
|
+
dependencies: {
|
|
56
|
+
commerce: $commerceModule,
|
|
57
|
+
order: $orderModule,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
```
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
[**@izumisy-tailor/omakase-modules**](../../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@izumisy-tailor/omakase-modules](../../modules.md) / [builder](../README.md) / withModuleConfiguration
|
|
6
|
+
|
|
7
|
+
# Function: withModuleConfiguration()
|
|
8
|
+
|
|
9
|
+
> **withModuleConfiguration**\<`C`, `Tables`, `Deps`, `Result`\>(`module`, `factory`): (`loadedModules`) => `Promise`\<`Result`\>
|
|
10
|
+
|
|
11
|
+
Defined in: [builder/register.ts:31](https://github.com/tailor-sandbox/omakase-modules/blob/c8d6563533665d8bb159b4602b5c906b40e938f2/packages/core/src/builder/register.ts#L31)
|
|
12
|
+
|
|
13
|
+
Define module exports that depend on configuration from loadModules.
|
|
14
|
+
|
|
15
|
+
This function returns a factory function that takes LoadedModules as input
|
|
16
|
+
and produces the configured exports. The wrapper files generated by
|
|
17
|
+
getModulesReference will call this factory with the app's loadModules result.
|
|
18
|
+
|
|
19
|
+
## Type Parameters
|
|
20
|
+
|
|
21
|
+
| Type Parameter |
|
|
22
|
+
| ------ |
|
|
23
|
+
| `C` *extends* `Record`\<`string`, `unknown`\> |
|
|
24
|
+
| `Tables` *extends* `Record`\<`string`, `unknown`\> |
|
|
25
|
+
| `Deps` *extends* `Record`\<`string`, `any`\> |
|
|
26
|
+
| `Result` |
|
|
27
|
+
|
|
28
|
+
## Parameters
|
|
29
|
+
|
|
30
|
+
| Parameter | Type |
|
|
31
|
+
| ------ | ------ |
|
|
32
|
+
| `module` | [`DefinedModule`](../type-aliases/DefinedModule.md)\<`C`, `Tables`, `Deps`\> |
|
|
33
|
+
| `factory` | (`context`, `loadedModules`) => `Result` \| `Promise`\<`Result`\> |
|
|
34
|
+
|
|
35
|
+
## Returns
|
|
36
|
+
|
|
37
|
+
> (`loadedModules`): `Promise`\<`Result`\>
|
|
38
|
+
|
|
39
|
+
### Parameters
|
|
40
|
+
|
|
41
|
+
| Parameter | Type |
|
|
42
|
+
| ------ | ------ |
|
|
43
|
+
| `loadedModules` | [`LoadedModules`](../../config/type-aliases/LoadedModules.md) |
|
|
44
|
+
|
|
45
|
+
### Returns
|
|
46
|
+
|
|
47
|
+
`Promise`\<`Result`\>
|
|
48
|
+
|
|
49
|
+
## Example
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// In module's tailordb/index.ts
|
|
53
|
+
export default withModuleConfiguration(moduleDef, (context) => {
|
|
54
|
+
const inventory = buildInventoryTable(context);
|
|
55
|
+
return { inventory };
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// In module's executors that need dependency module tables:
|
|
59
|
+
export default withModuleConfiguration(moduleDef, async (context, loadedModules) => {
|
|
60
|
+
const { productVariant } = await loadedModules.getTables(commerceModuleTables);
|
|
61
|
+
return createExecutor({ ... });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// The wrapper file will call it like:
|
|
65
|
+
// import factory from "module/backend/tailordb";
|
|
66
|
+
// import modules from "../../modules";
|
|
67
|
+
// export default await factory(modules);
|
|
68
|
+
```
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[**@izumisy-tailor/omakase-modules**](../../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@izumisy-tailor/omakase-modules](../../modules.md) / [builder](../README.md) / AnyDefinedModule
|
|
6
|
+
|
|
7
|
+
# Type Alias: AnyDefinedModule
|
|
8
|
+
|
|
9
|
+
> **AnyDefinedModule** = `object`
|
|
10
|
+
|
|
11
|
+
Defined in: [builder/helpers.ts:127](https://github.com/tailor-sandbox/omakase-modules/blob/c8d6563533665d8bb159b4602b5c906b40e938f2/packages/core/src/builder/helpers.ts#L127)
|
|
12
|
+
|
|
13
|
+
A loosely-typed representation of any defined module.
|
|
14
|
+
|
|
15
|
+
This type is used in dependency records where the exact type parameters
|
|
16
|
+
of the module are not important. It provides the minimal interface needed
|
|
17
|
+
to work with modules as dependencies.
|
|
18
|
+
|
|
19
|
+
For strongly-typed module definitions, use [DefinedModule](DefinedModule.md) instead.
|
|
20
|
+
|
|
21
|
+
## See
|
|
22
|
+
|
|
23
|
+
[DefinedModule](DefinedModule.md) for the fully-typed module definition.
|
|
24
|
+
|
|
25
|
+
## Properties
|
|
26
|
+
|
|
27
|
+
### configure()
|
|
28
|
+
|
|
29
|
+
> **configure**: (`props`) => [`ConfiguredModule`](ConfiguredModule.md)\<`any`\>
|
|
30
|
+
|
|
31
|
+
Defined in: [builder/helpers.ts:130](https://github.com/tailor-sandbox/omakase-modules/blob/c8d6563533665d8bb159b4602b5c906b40e938f2/packages/core/src/builder/helpers.ts#L130)
|
|
32
|
+
|
|
33
|
+
#### Parameters
|
|
34
|
+
|
|
35
|
+
| Parameter | Type |
|
|
36
|
+
| ------ | ------ |
|
|
37
|
+
| `props` | `any` |
|
|
38
|
+
|
|
39
|
+
#### Returns
|
|
40
|
+
|
|
41
|
+
[`ConfiguredModule`](ConfiguredModule.md)\<`any`\>
|
|
42
|
+
|
|
43
|
+
***
|
|
44
|
+
|
|
45
|
+
### dependencies
|
|
46
|
+
|
|
47
|
+
> **dependencies**: `Record`\<`string`, `any`\>
|
|
48
|
+
|
|
49
|
+
Defined in: [builder/helpers.ts:129](https://github.com/tailor-sandbox/omakase-modules/blob/c8d6563533665d8bb159b4602b5c906b40e938f2/packages/core/src/builder/helpers.ts#L129)
|
|
50
|
+
|
|
51
|
+
***
|
|
52
|
+
|
|
53
|
+
### packageName
|
|
54
|
+
|
|
55
|
+
> **packageName**: `string`
|
|
56
|
+
|
|
57
|
+
Defined in: [builder/helpers.ts:128](https://github.com/tailor-sandbox/omakase-modules/blob/c8d6563533665d8bb159b4602b5c906b40e938f2/packages/core/src/builder/helpers.ts#L128)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[**@izumisy-tailor/omakase-modules**](../../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@izumisy-tailor/omakase-modules](../../modules.md) / [builder](../README.md) / ConfiguredDependencies
|
|
6
|
+
|
|
7
|
+
# Type Alias: ConfiguredDependencies\<Deps\>
|
|
8
|
+
|
|
9
|
+
> **ConfiguredDependencies**\<`Deps`\> = `{ [K in keyof Deps as K extends "__empty" ? never : K]: Deps[K] extends { __configBrand?: infer C } ? C extends Record<string, unknown> ? ConfiguredModule<C> : never : never }`
|
|
10
|
+
|
|
11
|
+
Defined in: [builder/helpers.ts:170](https://github.com/tailor-sandbox/omakase-modules/blob/c8d6563533665d8bb159b4602b5c906b40e938f2/packages/core/src/builder/helpers.ts#L170)
|
|
12
|
+
|
|
13
|
+
Transforms a record of [DefinedModule](DefinedModule.md)s into a record of [ConfiguredModule](ConfiguredModule.md)s.
|
|
14
|
+
|
|
15
|
+
This utility type is used to derive the expected shape of the `dependencies`
|
|
16
|
+
property when configuring a module that has dependencies. It preserves
|
|
17
|
+
the exact configuration type for each dependency module.
|
|
18
|
+
|
|
19
|
+
## Type Parameters
|
|
20
|
+
|
|
21
|
+
| Type Parameter |
|
|
22
|
+
| ------ |
|
|
23
|
+
| `Deps` *extends* [`DependencyModules`](DependencyModules.md) |
|
|
24
|
+
|
|
25
|
+
## Example
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
// When a module is defined with dependencies:
|
|
29
|
+
defineModule<MyConfig, MyTables>({
|
|
30
|
+
packageName: "my-module",
|
|
31
|
+
}).withDependencies({
|
|
32
|
+
commerce: commerceModule,
|
|
33
|
+
order: orderModule,
|
|
34
|
+
}).build();
|
|
35
|
+
|
|
36
|
+
// The configure() method will expect:
|
|
37
|
+
myModule.configure({
|
|
38
|
+
config: { ... },
|
|
39
|
+
dependencies: {
|
|
40
|
+
commerce: ConfiguredModule<CommerceConfig>,
|
|
41
|
+
order: ConfiguredModule<OrderConfig>,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
```
|