@fjell/lib-sequelize 4.4.11 → 4.4.12
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 +266 -0
- package/dist/cjs/{Instance.cjs → SequelizeLibrary.cjs} +13 -13
- package/dist/cjs/{InstanceFactory.cjs → SequelizeLibraryFactory.cjs} +6 -6
- package/dist/cjs/contained/{Instance.cjs → SequelizeLibrary.cjs} +5 -2
- package/dist/cjs/contained/index.cjs +4 -3
- package/dist/cjs/index.cjs +5 -5
- package/dist/cjs/primary/{Instance.cjs → SequelizeLibrary.cjs} +6 -3
- package/dist/cjs/primary/index.cjs +4 -3
- package/dist/es/SequelizeLibrary.js +32 -0
- package/dist/es/SequelizeLibraryFactory.js +21 -0
- package/dist/es/contained/{Instance.js → SequelizeLibrary.js} +5 -3
- package/dist/es/contained/index.js +1 -1
- package/dist/es/index.js +2 -2
- package/dist/es/primary/{Instance.js → SequelizeLibrary.js} +6 -4
- package/dist/es/primary/index.js +1 -1
- package/dist/index.cjs +58 -52
- package/dist/index.cjs.map +1 -1
- package/dist/types/SequelizeLibrary.d.ts +28 -0
- package/dist/types/SequelizeLibraryFactory.d.ts +14 -0
- package/dist/types/contained/SequelizeLibrary.d.ts +11 -0
- package/dist/types/contained/index.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/primary/SequelizeLibrary.d.ts +11 -0
- package/dist/types/primary/index.d.ts +1 -1
- package/package.json +3 -3
- package/dist/es/Instance.js +0 -32
- package/dist/es/InstanceFactory.js +0 -21
- package/dist/types/Instance.d.ts +0 -28
- package/dist/types/InstanceFactory.d.ts +0 -14
- package/dist/types/contained/Instance.d.ts +0 -9
- package/dist/types/primary/Instance.d.ts +0 -9
package/README.md
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# @fjell/lib-sequelize
|
|
2
|
+
|
|
3
|
+
Sequelize integration for the Fjell ecosystem providing database-specific implementations for relational databases.
|
|
4
|
+
|
|
5
|
+
## New Architecture (v4.4.12+)
|
|
6
|
+
|
|
7
|
+
This library now uses the new **SequelizeLibrary** architecture that extends `@fjell/lib`:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
fjell-registry.Instance
|
|
11
|
+
↓ extends
|
|
12
|
+
fjell-lib.Library
|
|
13
|
+
↓ extends
|
|
14
|
+
fjell-lib-sequelize.SequelizeLibrary
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @fjell/lib-sequelize @fjell/lib @fjell/registry sequelize
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
### New SequelizeLibrary API (v4.4.12+)
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { createRegistry } from '@fjell/registry';
|
|
29
|
+
import { createSequelizeLibrary, SequelizeLibrary } from '@fjell/lib-sequelize';
|
|
30
|
+
import { User } from './models/User'; // Your Sequelize model
|
|
31
|
+
|
|
32
|
+
// Create a SequelizeLibrary
|
|
33
|
+
const userLibrary: SequelizeLibrary<UserItem, 'user'> = createSequelizeLibrary(
|
|
34
|
+
registry,
|
|
35
|
+
{ keyType: 'user' },
|
|
36
|
+
[User], // Sequelize models
|
|
37
|
+
{
|
|
38
|
+
validators: {
|
|
39
|
+
email: (email) => email.includes('@')
|
|
40
|
+
},
|
|
41
|
+
hooks: {
|
|
42
|
+
beforeCreate: async (user) => {
|
|
43
|
+
user.createdAt = new Date();
|
|
44
|
+
return user;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// Use the library
|
|
51
|
+
const users = await userLibrary.operations.all({});
|
|
52
|
+
const newUser = await userLibrary.operations.create({
|
|
53
|
+
name: 'Alice Johnson',
|
|
54
|
+
email: 'alice@example.com'
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Access Sequelize-specific features
|
|
58
|
+
console.log('Available models:', userLibrary.models.map(m => m.name));
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
## Features
|
|
64
|
+
|
|
65
|
+
### SequelizeLibrary Extends Library
|
|
66
|
+
|
|
67
|
+
The `SequelizeLibrary` interface adds:
|
|
68
|
+
- **models**: Array of Sequelize model classes
|
|
69
|
+
- **All Library features**: operations, options, coordinate, registry
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
interface SequelizeLibrary<T, S> extends Library<T, S> {
|
|
73
|
+
models: ModelStatic<any>[];
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Database Operations
|
|
78
|
+
|
|
79
|
+
Built-in operations automatically use your Sequelize models:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// CRUD operations use Sequelize under the hood
|
|
83
|
+
await userLibrary.operations.create(userData);
|
|
84
|
+
await userLibrary.operations.find({ filter: { email: 'alice@example.com' } });
|
|
85
|
+
await userLibrary.operations.update(['user-123'], { name: 'Alice Smith' });
|
|
86
|
+
await userLibrary.operations.remove(['user-123']);
|
|
87
|
+
|
|
88
|
+
// Advanced queries
|
|
89
|
+
await userLibrary.operations.all({
|
|
90
|
+
filter: { status: 'active' },
|
|
91
|
+
sort: { createdAt: -1 },
|
|
92
|
+
limit: 10
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Model Integration
|
|
97
|
+
|
|
98
|
+
Your Sequelize models are automatically integrated:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
// Define your Sequelize model
|
|
102
|
+
const User = sequelize.define('User', {
|
|
103
|
+
id: { type: DataTypes.UUID, primaryKey: true },
|
|
104
|
+
name: { type: DataTypes.STRING, allowNull: false },
|
|
105
|
+
email: { type: DataTypes.STRING, unique: true }
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Create SequelizeLibrary with the model
|
|
109
|
+
const userLibrary = createSequelizeLibrary(
|
|
110
|
+
registry,
|
|
111
|
+
{ keyType: 'user' },
|
|
112
|
+
[User], // Pass your models here
|
|
113
|
+
options
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
// Operations automatically use the User model
|
|
117
|
+
const users = await userLibrary.operations.all({}); // SELECT * FROM users
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Advanced Usage
|
|
121
|
+
|
|
122
|
+
### Multiple Models
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { User, UserProfile, UserSettings } from './models';
|
|
126
|
+
|
|
127
|
+
const userLibrary = createSequelizeLibrary(
|
|
128
|
+
registry,
|
|
129
|
+
{ keyType: 'user' },
|
|
130
|
+
[User, UserProfile, UserSettings], // Multiple related models
|
|
131
|
+
{
|
|
132
|
+
hooks: {
|
|
133
|
+
afterCreate: async (user) => {
|
|
134
|
+
// Automatically create profile and settings
|
|
135
|
+
await UserProfile.create({ userId: user.id });
|
|
136
|
+
await UserSettings.create({ userId: user.id });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Custom Operations
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { createOperations } from '@fjell/lib-sequelize';
|
|
147
|
+
|
|
148
|
+
const customOperations = createOperations([User], coordinate, registry, {
|
|
149
|
+
// Custom business logic
|
|
150
|
+
actions: {
|
|
151
|
+
activate: async (keys, params) => {
|
|
152
|
+
const user = await User.findByPk(keys[0]);
|
|
153
|
+
user.status = 'active';
|
|
154
|
+
user.activatedAt = new Date();
|
|
155
|
+
await user.save();
|
|
156
|
+
return { success: true };
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
// Custom analytics
|
|
161
|
+
facets: {
|
|
162
|
+
userStats: async (query, options) => {
|
|
163
|
+
const users = await User.findAll();
|
|
164
|
+
return {
|
|
165
|
+
total: users.length,
|
|
166
|
+
active: users.filter(u => u.status === 'active').length,
|
|
167
|
+
byRegion: groupBy(users, 'region')
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Hierarchical Data
|
|
175
|
+
|
|
176
|
+
Support for contained items with location hierarchies:
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
// Department library with location hierarchy
|
|
180
|
+
const deptLibrary = createSequelizeLibrary(
|
|
181
|
+
registry,
|
|
182
|
+
{ keyType: 'department' },
|
|
183
|
+
[Department],
|
|
184
|
+
options
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
// Query departments by location
|
|
188
|
+
const usDepartments = await deptLibrary.operations.all({}, ['us', 'usa']);
|
|
189
|
+
const westCoastDepts = await deptLibrary.operations.all({}, ['us', 'west']);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Migration Guide
|
|
193
|
+
|
|
194
|
+
### From v4.4.11 and earlier
|
|
195
|
+
|
|
196
|
+
1. **No breaking changes** - existing code continues to work
|
|
197
|
+
2. **Optional migration** to new naming:
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
// Clean Library architecture
|
|
201
|
+
import { createSequelizeLibrary, SequelizeLibrary } from '@fjell/lib-sequelize';
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
3. **Benefits of the new architecture**:
|
|
205
|
+
- Clear naming that shows inheritance hierarchy
|
|
206
|
+
- Better TypeScript autocomplete and documentation
|
|
207
|
+
- Future-proof as the ecosystem evolves
|
|
208
|
+
|
|
209
|
+
### Simple Setup
|
|
210
|
+
|
|
211
|
+
Use the SequelizeLibrary for all new development:
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
// Clean, consistent API
|
|
215
|
+
const userLibrary = createSequelizeLibrary(registry, coordinate, models, options);
|
|
216
|
+
const orderLibrary = createSequelizeLibrary(registry, orderCoordinate, orderModels, orderOptions);
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Architecture Benefits
|
|
220
|
+
|
|
221
|
+
1. **Clear Inheritance**: Shows how SequelizeLibrary extends Library
|
|
222
|
+
2. **Type Safety**: Full TypeScript support throughout the hierarchy
|
|
223
|
+
3. **Database Focus**: SequelizeLibrary is clearly Sequelize-specific
|
|
224
|
+
4. **Extensibility**: Easy to add new database-specific libraries
|
|
225
|
+
5. **Clean API**: Consistent naming and patterns across all libraries
|
|
226
|
+
|
|
227
|
+
## Examples
|
|
228
|
+
|
|
229
|
+
See the `examples/` directory for complete working examples:
|
|
230
|
+
- Basic Sequelize integration
|
|
231
|
+
- Advanced business logic
|
|
232
|
+
- Multi-model applications
|
|
233
|
+
- Location-based data organization
|
|
234
|
+
|
|
235
|
+
## TypeScript Support
|
|
236
|
+
|
|
237
|
+
Full TypeScript support with proper type inference:
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
import { Item } from '@fjell/core';
|
|
241
|
+
|
|
242
|
+
interface User extends Item<'user'> {
|
|
243
|
+
id: string;
|
|
244
|
+
name: string;
|
|
245
|
+
email: string;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const userLibrary: SequelizeLibrary<User, 'user'> = createSequelizeLibrary(
|
|
249
|
+
registry,
|
|
250
|
+
{ keyType: 'user' },
|
|
251
|
+
[UserModel],
|
|
252
|
+
options
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
// Full type safety
|
|
256
|
+
const user: User = await userLibrary.operations.create({
|
|
257
|
+
name: 'Alice',
|
|
258
|
+
email: 'alice@example.com'
|
|
259
|
+
});
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Next Steps
|
|
263
|
+
|
|
264
|
+
- Check out `@fjell/lib-firestore` for Firestore integration
|
|
265
|
+
- See `@fjell/lib` for core Library functionality
|
|
266
|
+
- Read `@fjell/registry` for base coordination features
|
|
@@ -25,12 +25,12 @@ function _interopNamespaceDefault(e) {
|
|
|
25
25
|
|
|
26
26
|
const Library__namespace = /*#__PURE__*/_interopNamespaceDefault(Library);
|
|
27
27
|
|
|
28
|
-
const logger = logger$1.default.get("
|
|
28
|
+
const logger = logger$1.default.get("SequelizeLibrary");
|
|
29
29
|
/**
|
|
30
|
-
* Creates a new
|
|
30
|
+
* Creates a new SequelizeLibrary that extends the fjell-lib Library
|
|
31
31
|
* with Sequelize-specific functionality
|
|
32
|
-
*/ const
|
|
33
|
-
logger.debug("
|
|
32
|
+
*/ const createSequelizeLibrary = (registry, coordinate, models, options)=>{
|
|
33
|
+
logger.debug("createSequelizeLibrary", {
|
|
34
34
|
coordinate,
|
|
35
35
|
models,
|
|
36
36
|
registry,
|
|
@@ -38,19 +38,19 @@ const logger = logger$1.default.get("Instance");
|
|
|
38
38
|
});
|
|
39
39
|
// Create Sequelize-specific operations
|
|
40
40
|
const operations = Operations.createOperations(models, coordinate, registry, options);
|
|
41
|
-
// Create the base fjell-lib
|
|
42
|
-
const
|
|
41
|
+
// Create the base fjell-lib library
|
|
42
|
+
const libLibrary = Library__namespace.createLibrary(registry, coordinate, operations, options);
|
|
43
43
|
return {
|
|
44
|
-
...
|
|
44
|
+
...libLibrary,
|
|
45
45
|
models
|
|
46
46
|
};
|
|
47
47
|
};
|
|
48
48
|
/**
|
|
49
|
-
* Type guard to check if an object is a
|
|
50
|
-
*/ const
|
|
51
|
-
return
|
|
49
|
+
* Type guard to check if an object is a SequelizeLibrary
|
|
50
|
+
*/ const isSequelizeLibrary = (library)=>{
|
|
51
|
+
return library != null && library.coordinate != null && library.operations != null && library.options != null && library.registry != null && library.models != null && Array.isArray(library.models);
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
exports.
|
|
55
|
-
exports.
|
|
56
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
54
|
+
exports.createSequelizeLibrary = createSequelizeLibrary;
|
|
55
|
+
exports.isSequelizeLibrary = isSequelizeLibrary;
|
|
56
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2VxdWVsaXplTGlicmFyeS5janMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const SequelizeLibrary = require('./SequelizeLibrary.cjs');
|
|
6
6
|
const logger$1 = require('./logger.cjs');
|
|
7
7
|
|
|
8
8
|
const logger = logger$1.default.get("InstanceFactory");
|
|
9
9
|
/**
|
|
10
|
-
* Factory function for creating Sequelize
|
|
10
|
+
* Factory function for creating Sequelize libraries
|
|
11
11
|
* This extends the fjell-lib pattern by adding Sequelize-specific models
|
|
12
|
-
*/ const
|
|
12
|
+
*/ const createSequelizeLibraryFactory = (models, options)=>{
|
|
13
13
|
return (coordinate, context)=>{
|
|
14
14
|
logger.debug("Creating Sequelize instance", {
|
|
15
15
|
coordinate,
|
|
@@ -17,9 +17,9 @@ const logger = logger$1.default.get("InstanceFactory");
|
|
|
17
17
|
models: models.map((m)=>m.name),
|
|
18
18
|
options
|
|
19
19
|
});
|
|
20
|
-
return
|
|
20
|
+
return SequelizeLibrary.createSequelizeLibrary(context.registry, coordinate, models, options);
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
exports.
|
|
25
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
24
|
+
exports.createSequelizeLibraryFactory = createSequelizeLibraryFactory;
|
|
25
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2VxdWVsaXplTGlicmFyeUZhY3RvcnkuY2pzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -7,7 +7,7 @@ const Operations = require('../Operations.cjs');
|
|
|
7
7
|
const Options = require('../Options.cjs');
|
|
8
8
|
const Coordinate = require('../Coordinate.cjs');
|
|
9
9
|
|
|
10
|
-
function
|
|
10
|
+
function createSequelizeLibrary(keyTypes, models, libOptions = {}, scopes = [], registry) {
|
|
11
11
|
// Create coordinate and options separately following new pattern
|
|
12
12
|
const coordinate = Coordinate.createCoordinate(keyTypes, scopes);
|
|
13
13
|
const options = Options.createOptions(libOptions);
|
|
@@ -23,6 +23,9 @@ function createInstance(keyTypes, models, libOptions = {}, scopes = [], registry
|
|
|
23
23
|
models
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
+
// Legacy exports for backwards compatibility
|
|
27
|
+
const createInstance = createSequelizeLibrary;
|
|
26
28
|
|
|
27
29
|
exports.createInstance = createInstance;
|
|
28
|
-
|
|
30
|
+
exports.createSequelizeLibrary = createSequelizeLibrary;
|
|
31
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2VxdWVsaXplTGlicmFyeS5janMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const SequelizeLibrary = require('./SequelizeLibrary.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
exports.createInstance =
|
|
10
|
-
|
|
9
|
+
exports.createInstance = SequelizeLibrary.createInstance;
|
|
10
|
+
exports.createSequelizeLibrary = SequelizeLibrary.createSequelizeLibrary;
|
|
11
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguY2pzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OyJ9
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
5
|
const Definition = require('./Definition.cjs');
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const SequelizeLibrary = require('./SequelizeLibrary.cjs');
|
|
7
|
+
const SequelizeLibraryFactory = require('./SequelizeLibraryFactory.cjs');
|
|
8
8
|
const Options = require('./Options.cjs');
|
|
9
9
|
const Operations = require('./Operations.cjs');
|
|
10
10
|
const index = require('./contained/index.cjs');
|
|
@@ -14,9 +14,9 @@ const Coordinate = require('./Coordinate.cjs');
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
exports.createDefinition = Definition.createDefinition;
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
19
|
-
exports.
|
|
17
|
+
exports.createSequelizeLibrary = SequelizeLibrary.createSequelizeLibrary;
|
|
18
|
+
exports.isSequelizeLibrary = SequelizeLibrary.isSequelizeLibrary;
|
|
19
|
+
exports.createSequelizeLibraryFactory = SequelizeLibraryFactory.createSequelizeLibraryFactory;
|
|
20
20
|
exports.createOptions = Options.createOptions;
|
|
21
21
|
exports.createOperations = Operations.createOperations;
|
|
22
22
|
exports.Contained = index;
|
|
@@ -9,8 +9,8 @@ const Coordinate = require('../Coordinate.cjs');
|
|
|
9
9
|
const logger$1 = require('../logger.cjs');
|
|
10
10
|
|
|
11
11
|
const logger = logger$1.default.get('lib-sequelize', 'primary', 'instance');
|
|
12
|
-
function
|
|
13
|
-
logger.debug('
|
|
12
|
+
function createSequelizeLibrary(keyType, models, libOptions = {}, scopes = [], registry) {
|
|
13
|
+
logger.debug('createSequelizeLibrary', {
|
|
14
14
|
keyType,
|
|
15
15
|
models,
|
|
16
16
|
libOptions,
|
|
@@ -33,6 +33,9 @@ function createInstance(keyType, models, libOptions = {}, scopes = [], registry)
|
|
|
33
33
|
models
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
+
// Legacy exports for backwards compatibility
|
|
37
|
+
const createInstance = createSequelizeLibrary;
|
|
36
38
|
|
|
37
39
|
exports.createInstance = createInstance;
|
|
38
|
-
|
|
40
|
+
exports.createSequelizeLibrary = createSequelizeLibrary;
|
|
41
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2VxdWVsaXplTGlicmFyeS5janMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const SequelizeLibrary = require('./SequelizeLibrary.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
exports.createInstance =
|
|
10
|
-
|
|
9
|
+
exports.createInstance = SequelizeLibrary.createInstance;
|
|
10
|
+
exports.createSequelizeLibrary = SequelizeLibrary.createSequelizeLibrary;
|
|
11
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguY2pzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as Library from '@fjell/lib';
|
|
2
|
+
import { createOperations } from './Operations.js';
|
|
3
|
+
import LibLogger from './logger.js';
|
|
4
|
+
|
|
5
|
+
const logger = LibLogger.get("SequelizeLibrary");
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new SequelizeLibrary that extends the fjell-lib Library
|
|
8
|
+
* with Sequelize-specific functionality
|
|
9
|
+
*/ const createSequelizeLibrary = (registry, coordinate, models, options)=>{
|
|
10
|
+
logger.debug("createSequelizeLibrary", {
|
|
11
|
+
coordinate,
|
|
12
|
+
models,
|
|
13
|
+
registry,
|
|
14
|
+
options
|
|
15
|
+
});
|
|
16
|
+
// Create Sequelize-specific operations
|
|
17
|
+
const operations = createOperations(models, coordinate, registry, options);
|
|
18
|
+
// Create the base fjell-lib library
|
|
19
|
+
const libLibrary = Library.createLibrary(registry, coordinate, operations, options);
|
|
20
|
+
return {
|
|
21
|
+
...libLibrary,
|
|
22
|
+
models
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Type guard to check if an object is a SequelizeLibrary
|
|
27
|
+
*/ const isSequelizeLibrary = (library)=>{
|
|
28
|
+
return library != null && library.coordinate != null && library.operations != null && library.options != null && library.registry != null && library.models != null && Array.isArray(library.models);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { createSequelizeLibrary, isSequelizeLibrary };
|
|
32
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2VxdWVsaXplTGlicmFyeS5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createSequelizeLibrary } from './SequelizeLibrary.js';
|
|
2
|
+
import LibLogger from './logger.js';
|
|
3
|
+
|
|
4
|
+
const logger = LibLogger.get("InstanceFactory");
|
|
5
|
+
/**
|
|
6
|
+
* Factory function for creating Sequelize libraries
|
|
7
|
+
* This extends the fjell-lib pattern by adding Sequelize-specific models
|
|
8
|
+
*/ const createSequelizeLibraryFactory = (models, options)=>{
|
|
9
|
+
return (coordinate, context)=>{
|
|
10
|
+
logger.debug("Creating Sequelize instance", {
|
|
11
|
+
coordinate,
|
|
12
|
+
registry: context.registry,
|
|
13
|
+
models: models.map((m)=>m.name),
|
|
14
|
+
options
|
|
15
|
+
});
|
|
16
|
+
return createSequelizeLibrary(context.registry, coordinate, models, options);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { createSequelizeLibraryFactory };
|
|
21
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2VxdWVsaXplTGlicmFyeUZhY3RvcnkuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
|
@@ -3,7 +3,7 @@ import { createOperations } from '../Operations.js';
|
|
|
3
3
|
import { createOptions } from '../Options.js';
|
|
4
4
|
import { createCoordinate } from '../Coordinate.js';
|
|
5
5
|
|
|
6
|
-
function
|
|
6
|
+
function createSequelizeLibrary(keyTypes, models, libOptions = {}, scopes = [], registry) {
|
|
7
7
|
// Create coordinate and options separately following new pattern
|
|
8
8
|
const coordinate = createCoordinate(keyTypes, scopes);
|
|
9
9
|
const options = createOptions(libOptions);
|
|
@@ -19,6 +19,8 @@ function createInstance(keyTypes, models, libOptions = {}, scopes = [], registry
|
|
|
19
19
|
models
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
+
// Legacy exports for backwards compatibility
|
|
23
|
+
const createInstance = createSequelizeLibrary;
|
|
22
24
|
|
|
23
|
-
export { createInstance };
|
|
24
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
25
|
+
export { createInstance, createSequelizeLibrary };
|
|
26
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2VxdWVsaXplTGlicmFyeS5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createInstance } from './
|
|
1
|
+
export { createInstance, createSequelizeLibrary } from './SequelizeLibrary.js';
|
|
2
2
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|
package/dist/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createDefinition } from './Definition.js';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
2
|
+
export { createSequelizeLibrary, isSequelizeLibrary } from './SequelizeLibrary.js';
|
|
3
|
+
export { createSequelizeLibraryFactory } from './SequelizeLibraryFactory.js';
|
|
4
4
|
export { createOptions } from './Options.js';
|
|
5
5
|
export { createOperations } from './Operations.js';
|
|
6
6
|
import * as index from './contained/index.js';
|
|
@@ -5,8 +5,8 @@ import { createCoordinate } from '../Coordinate.js';
|
|
|
5
5
|
import LibLogger from '../logger.js';
|
|
6
6
|
|
|
7
7
|
const logger = LibLogger.get('lib-sequelize', 'primary', 'instance');
|
|
8
|
-
function
|
|
9
|
-
logger.debug('
|
|
8
|
+
function createSequelizeLibrary(keyType, models, libOptions = {}, scopes = [], registry) {
|
|
9
|
+
logger.debug('createSequelizeLibrary', {
|
|
10
10
|
keyType,
|
|
11
11
|
models,
|
|
12
12
|
libOptions,
|
|
@@ -29,6 +29,8 @@ function createInstance(keyType, models, libOptions = {}, scopes = [], registry)
|
|
|
29
29
|
models
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
// Legacy exports for backwards compatibility
|
|
33
|
+
const createInstance = createSequelizeLibrary;
|
|
32
34
|
|
|
33
|
-
export { createInstance };
|
|
34
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
35
|
+
export { createInstance, createSequelizeLibrary };
|
|
36
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2VxdWVsaXplTGlicmFyeS5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
package/dist/es/primary/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createInstance } from './
|
|
1
|
+
export { createInstance, createSequelizeLibrary } from './SequelizeLibrary.js';
|
|
2
2
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|
package/dist/index.cjs
CHANGED
|
@@ -79,7 +79,7 @@ const createDefinition = (kta, scopes, libOptions)=>{
|
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
//Recursive implementation of jSON.stringify;
|
|
82
|
-
const stringifyJSON = function(obj, visited = new Set()) {
|
|
82
|
+
const general.stringifyJSON = function(obj, visited = new Set()) {
|
|
83
83
|
const arrOfKeyVals = [];
|
|
84
84
|
const arrVals = [];
|
|
85
85
|
let objKeys = [];
|
|
@@ -94,7 +94,7 @@ const stringifyJSON = function(obj, visited = new Set()) {
|
|
|
94
94
|
// Add array to visited before processing its elements
|
|
95
95
|
visited.add(obj);
|
|
96
96
|
obj.forEach(function(el) {
|
|
97
|
-
arrVals.push(stringifyJSON(el, visited));
|
|
97
|
+
arrVals.push(general.stringifyJSON(el, visited));
|
|
98
98
|
});
|
|
99
99
|
return '[' + arrVals + ']';
|
|
100
100
|
}
|
|
@@ -112,7 +112,7 @@ const stringifyJSON = function(obj, visited = new Set()) {
|
|
|
112
112
|
else if (typeof keyValOut === 'string') arrOfKeyVals.push(keyOut + '"' + keyValOut + '"');
|
|
113
113
|
else if (typeof keyValOut === 'boolean' || typeof keyValOut === 'number' || keyValOut === null) arrOfKeyVals.push(keyOut + keyValOut);
|
|
114
114
|
else if (keyValOut instanceof Object) {
|
|
115
|
-
arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut, visited));
|
|
115
|
+
arrOfKeyVals.push(keyOut + general.stringifyJSON(keyValOut, visited));
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
118
|
return '{' + arrOfKeyVals + '}';
|
|
@@ -122,7 +122,7 @@ const stringifyJSON = function(obj, visited = new Set()) {
|
|
|
122
122
|
|
|
123
123
|
const logger$g = logger$1.default.get('sequelize', 'QueryBuilder');
|
|
124
124
|
const addDeleteQuery = (options, model)=>{
|
|
125
|
-
logger$g.default(`QueryBuilder adding delete query with options: ${stringifyJSON(options)}`);
|
|
125
|
+
logger$g.default(`QueryBuilder adding delete query with options: ${general.stringifyJSON(options)}`);
|
|
126
126
|
if (model.getAttributes().deletedAt) {
|
|
127
127
|
options.where['deletedAt'] = {
|
|
128
128
|
[sequelize.Op.eq]: null
|
|
@@ -135,7 +135,7 @@ const addDeleteQuery = (options, model)=>{
|
|
|
135
135
|
return options;
|
|
136
136
|
};
|
|
137
137
|
const addEventQueries = (options, events, model)=>{
|
|
138
|
-
logger$g.default(`QueryBuilder adding event queries with options: ${stringifyJSON(options)}, events: ${stringifyJSON(events)}`);
|
|
138
|
+
logger$g.default(`QueryBuilder adding event queries with options: ${general.stringifyJSON(options)}, events: ${general.stringifyJSON(events)}`);
|
|
139
139
|
Object.keys(events).forEach((key)=>{
|
|
140
140
|
if (!model.getAttributes()[`${key}At`]) {
|
|
141
141
|
throw new Error(`Event ${key} is not supported on this model, column ${key}At not found`);
|
|
@@ -169,22 +169,22 @@ const addEventQueries = (options, events, model)=>{
|
|
|
169
169
|
};
|
|
170
170
|
// Add the references to the query
|
|
171
171
|
const addReferenceQueries = (options, references, model)=>{
|
|
172
|
-
logger$g.default(`QueryBuilder adding reference queries with options: ${stringifyJSON(options)}, references: ${stringifyJSON(references)}`);
|
|
172
|
+
logger$g.default(`QueryBuilder adding reference queries with options: ${general.stringifyJSON(options)}, references: ${general.stringifyJSON(references)}`);
|
|
173
173
|
Object.keys(references).forEach((key)=>{
|
|
174
|
-
logger$g.default(`QueryBuilder adding reference query for key: ${key}, references: ${stringifyJSON(references)}`);
|
|
174
|
+
logger$g.default(`QueryBuilder adding reference query for key: ${key}, references: ${general.stringifyJSON(references)}`);
|
|
175
175
|
if (!model.getAttributes()[`${key}Id`]) {
|
|
176
176
|
throw new Error(`Reference ${key} is not supported on this model, column ${key}Id not found`);
|
|
177
177
|
}
|
|
178
178
|
if (core.isPriKey(references[key])) {
|
|
179
179
|
const priKey = references[key];
|
|
180
180
|
if (priKey.pk == null || priKey.pk === '' || typeof priKey.pk === 'object' && Object.keys(priKey.pk).length === 0) {
|
|
181
|
-
logger$g.error(`Reference key '${key}' has invalid pk value: ${stringifyJSON(priKey.pk)}`, {
|
|
181
|
+
logger$g.error(`Reference key '${key}' has invalid pk value: ${general.stringifyJSON(priKey.pk)}`, {
|
|
182
182
|
priKey,
|
|
183
183
|
references
|
|
184
184
|
});
|
|
185
|
-
throw new Error(`Reference key '${key}' has invalid pk value: ${stringifyJSON(priKey.pk)}`);
|
|
185
|
+
throw new Error(`Reference key '${key}' has invalid pk value: ${general.stringifyJSON(priKey.pk)}`);
|
|
186
186
|
}
|
|
187
|
-
logger$g.trace(`[QueryBuilder] Setting reference where clause: ${key}Id = ${stringifyJSON(priKey.pk)} (type: ${typeof priKey.pk})`);
|
|
187
|
+
logger$g.trace(`[QueryBuilder] Setting reference where clause: ${key}Id = ${general.stringifyJSON(priKey.pk)} (type: ${typeof priKey.pk})`);
|
|
188
188
|
options.where[`${key}Id`] = {
|
|
189
189
|
[sequelize.Op.eq]: priKey.pk
|
|
190
190
|
};
|
|
@@ -267,7 +267,7 @@ const addAssociationCondition = (conditions, condition, model)=>{
|
|
|
267
267
|
});
|
|
268
268
|
throw new Error(`Association condition for '${associationName}.${attributeName}' has undefined/null value`);
|
|
269
269
|
}
|
|
270
|
-
logger$g.trace(`[QueryBuilder] Setting association condition: ${sequelizeAssociationColumn} = ${stringifyJSON(condition.value)} (type: ${typeof condition.value})`);
|
|
270
|
+
logger$g.trace(`[QueryBuilder] Setting association condition: ${sequelizeAssociationColumn} = ${general.stringifyJSON(condition.value)} (type: ${typeof condition.value})`);
|
|
271
271
|
conditions[sequelizeAssociationColumn] = {
|
|
272
272
|
[conditionOp]: condition.value
|
|
273
273
|
};
|
|
@@ -285,7 +285,7 @@ const addAttributeCondition = (conditions, condition, model)=>{
|
|
|
285
285
|
});
|
|
286
286
|
throw new Error(`Attribute condition for '${conditionColumn}' has undefined/null value`);
|
|
287
287
|
}
|
|
288
|
-
logger$g.trace(`[QueryBuilder] Setting attribute condition: ${conditionColumn} = ${stringifyJSON(condition.value)} (type: ${typeof condition.value})`);
|
|
288
|
+
logger$g.trace(`[QueryBuilder] Setting attribute condition: ${conditionColumn} = ${general.stringifyJSON(condition.value)} (type: ${typeof condition.value})`);
|
|
289
289
|
conditions[conditionColumn] = {
|
|
290
290
|
[conditionOp]: condition.value
|
|
291
291
|
};
|
|
@@ -356,12 +356,12 @@ const addAssociationIncludes = (options, model)=>{
|
|
|
356
356
|
return options;
|
|
357
357
|
};
|
|
358
358
|
const buildQuery = (itemQuery, model)=>{
|
|
359
|
-
logger$g.default(`QueryBuilder build called with itemQuery: ${stringifyJSON(itemQuery)}`);
|
|
359
|
+
logger$g.default(`QueryBuilder build called with itemQuery: ${general.stringifyJSON(itemQuery)}`);
|
|
360
360
|
let options = {
|
|
361
361
|
where: {}
|
|
362
362
|
};
|
|
363
363
|
if (itemQuery.compoundCondition) {
|
|
364
|
-
logger$g.default(`QueryBuilder adding conditions: ${stringifyJSON(itemQuery.compoundCondition)}`);
|
|
364
|
+
logger$g.default(`QueryBuilder adding conditions: ${general.stringifyJSON(itemQuery.compoundCondition)}`);
|
|
365
365
|
options = addCompoundCondition(options, itemQuery.compoundCondition, model);
|
|
366
366
|
}
|
|
367
367
|
// If the model has a deletedAt column, we need to add a delete query
|
|
@@ -983,22 +983,22 @@ const processRow = async (row, keyTypes, referenceDefinitions, aggregationDefini
|
|
|
983
983
|
let item = row.get({
|
|
984
984
|
plain: true
|
|
985
985
|
});
|
|
986
|
-
logger$a.default('Adding Key to Item with Key Types: %s', stringifyJSON(keyTypes));
|
|
986
|
+
logger$a.default('Adding Key to Item with Key Types: %s', general.stringifyJSON(keyTypes));
|
|
987
987
|
item = addKey(row, item, keyTypes);
|
|
988
988
|
item = populateEvents(item);
|
|
989
|
-
logger$a.default('Key Added to Item: %s', stringifyJSON(item.key));
|
|
989
|
+
logger$a.default('Key Added to Item: %s', general.stringifyJSON(item.key));
|
|
990
990
|
// Mark this item as in progress to detect circular references
|
|
991
991
|
operationContext.markInProgress(item.key);
|
|
992
992
|
try {
|
|
993
993
|
if (referenceDefinitions && referenceDefinitions.length > 0) {
|
|
994
994
|
for (const referenceDefinition of referenceDefinitions){
|
|
995
|
-
logger$a.default('Processing Reference for %s to %s', item.key.kt, stringifyJSON(referenceDefinition.kta));
|
|
995
|
+
logger$a.default('Processing Reference for %s to %s', item.key.kt, general.stringifyJSON(referenceDefinition.kta));
|
|
996
996
|
item = await buildReference(item, referenceDefinition, registry, operationContext);
|
|
997
997
|
}
|
|
998
998
|
}
|
|
999
999
|
if (aggregationDefinitions && aggregationDefinitions.length > 0) {
|
|
1000
1000
|
for (const aggregationDefinition of aggregationDefinitions){
|
|
1001
|
-
logger$a.default('Processing Aggregation for %s from %s', item.key.kt, stringifyJSON(aggregationDefinition.kta));
|
|
1001
|
+
logger$a.default('Processing Aggregation for %s from %s', item.key.kt, general.stringifyJSON(aggregationDefinition.kta));
|
|
1002
1002
|
item = await buildAggregation(item, aggregationDefinition, registry, operationContext);
|
|
1003
1003
|
}
|
|
1004
1004
|
}
|
|
@@ -1008,7 +1008,7 @@ const processRow = async (row, keyTypes, referenceDefinitions, aggregationDefini
|
|
|
1008
1008
|
// Mark this item as complete
|
|
1009
1009
|
operationContext.markComplete(item.key);
|
|
1010
1010
|
}
|
|
1011
|
-
logger$a.default('Processed Row: %j', stringifyJSON(item));
|
|
1011
|
+
logger$a.default('Processed Row: %j', general.stringifyJSON(item));
|
|
1012
1012
|
return item;
|
|
1013
1013
|
});
|
|
1014
1014
|
};
|
|
@@ -1071,11 +1071,11 @@ const all.getAllOperation = (models, definition, registry)=>{
|
|
|
1071
1071
|
// Handle direct location keys (simple foreign key constraints)
|
|
1072
1072
|
for (const locKey of directLocations){
|
|
1073
1073
|
if (locKey.lk === undefined || locKey.lk == null || locKey.lk === '' || typeof locKey.lk === 'object' && Object.keys(locKey.lk).length === 0) {
|
|
1074
|
-
logger$9.error(`Location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`, {
|
|
1074
|
+
logger$9.error(`Location key '${locKey.kt}' has invalid lk value: ${general.stringifyJSON(locKey.lk)}`, {
|
|
1075
1075
|
locKey,
|
|
1076
1076
|
locations: loc
|
|
1077
1077
|
});
|
|
1078
|
-
throw new Error(`Location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`);
|
|
1078
|
+
throw new Error(`Location key '${locKey.kt}' has invalid lk value: ${general.stringifyJSON(locKey.lk)}`);
|
|
1079
1079
|
}
|
|
1080
1080
|
const foreignKeyField = locKey.kt + 'Id';
|
|
1081
1081
|
// Check if this field already has a condition from the itemQuery
|
|
@@ -1083,7 +1083,7 @@ const all.getAllOperation = (models, definition, registry)=>{
|
|
|
1083
1083
|
logger$9.debug(`[ALL] Field ${foreignKeyField} already constrained by itemQuery, skipping location constraint to avoid conflicts`);
|
|
1084
1084
|
continue; // Skip this location constraint to avoid conflicts
|
|
1085
1085
|
}
|
|
1086
|
-
logger$9.trace(`[ALL] Setting direct location where clause: ${foreignKeyField} = ${stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
|
|
1086
|
+
logger$9.trace(`[ALL] Setting direct location where clause: ${foreignKeyField} = ${general.stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
|
|
1087
1087
|
options.where[foreignKeyField] = {
|
|
1088
1088
|
[sequelize.Op.eq]: locKey.lk
|
|
1089
1089
|
};
|
|
@@ -1091,11 +1091,11 @@ const all.getAllOperation = (models, definition, registry)=>{
|
|
|
1091
1091
|
// Handle hierarchical location keys (requires relationship traversal)
|
|
1092
1092
|
for (const locKey of hierarchicalLocations){
|
|
1093
1093
|
if (locKey.lk === undefined || locKey.lk == null || locKey.lk === '' || typeof locKey.lk === 'object' && Object.keys(locKey.lk).length === 0) {
|
|
1094
|
-
logger$9.error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`, {
|
|
1094
|
+
logger$9.error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${general.stringifyJSON(locKey.lk)}`, {
|
|
1095
1095
|
locKey,
|
|
1096
1096
|
locations: loc
|
|
1097
1097
|
});
|
|
1098
|
-
throw new Error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`);
|
|
1098
|
+
throw new Error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${general.stringifyJSON(locKey.lk)}`);
|
|
1099
1099
|
}
|
|
1100
1100
|
const relationshipInfo = relationshipUtils.buildRelationshipPath(model, locKey.kt, kta);
|
|
1101
1101
|
if (relationshipInfo.found && relationshipInfo.path) {
|
|
@@ -1105,7 +1105,7 @@ const all.getAllOperation = (models, definition, registry)=>{
|
|
|
1105
1105
|
continue; // Skip this location constraint to avoid conflicts
|
|
1106
1106
|
}
|
|
1107
1107
|
// Add the relationship constraint using the path
|
|
1108
|
-
logger$9.trace(`[ALL] Setting hierarchical location where clause: ${relationshipInfo.path} = ${stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
|
|
1108
|
+
logger$9.trace(`[ALL] Setting hierarchical location where clause: ${relationshipInfo.path} = ${general.stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
|
|
1109
1109
|
options.where[relationshipInfo.path] = {
|
|
1110
1110
|
[sequelize.Op.eq]: locKey.lk
|
|
1111
1111
|
};
|
|
@@ -1368,7 +1368,7 @@ const getCreateOperation = (models, definition, registry)=>{
|
|
|
1368
1368
|
}
|
|
1369
1369
|
// Create the record
|
|
1370
1370
|
try {
|
|
1371
|
-
logger$8.trace(`[CREATE] Executing ${model.name}.create() with data: ${stringifyJSON(itemData)}`);
|
|
1371
|
+
logger$8.trace(`[CREATE] Executing ${model.name}.create() with data: ${general.stringifyJSON(itemData)}`);
|
|
1372
1372
|
const createdRecord = await model.create(itemData);
|
|
1373
1373
|
// Add key and events
|
|
1374
1374
|
const processedRecord = await processRow(createdRecord, kta, references, aggregations, registry);
|
|
@@ -1393,7 +1393,7 @@ const getFindOperation = (models, definition, registry)=>{
|
|
|
1393
1393
|
if (finders && finders[finder]) {
|
|
1394
1394
|
const finderMethod = finders[finder];
|
|
1395
1395
|
if (finderMethod) {
|
|
1396
|
-
logger$7.trace(`[FIND] Executing finder '${finder}' on ${models[0].name} with params: ${stringifyJSON(finderParams)}, locations: ${stringifyJSON(locations)}`);
|
|
1396
|
+
logger$7.trace(`[FIND] Executing finder '${finder}' on ${models[0].name} with params: ${general.stringifyJSON(finderParams)}, locations: ${general.stringifyJSON(locations)}`);
|
|
1397
1397
|
const results = await finderMethod(finderParams, locations);
|
|
1398
1398
|
if (results && results.length > 0) {
|
|
1399
1399
|
const processedResults = await Promise.all(results.map(async (row)=>{
|
|
@@ -1480,7 +1480,7 @@ const getGetOperation = (models, definition, registry)=>{
|
|
|
1480
1480
|
logger$6.default('Composite key query', {
|
|
1481
1481
|
queryOptions
|
|
1482
1482
|
});
|
|
1483
|
-
logger$6.trace(`[GET] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
|
|
1483
|
+
logger$6.trace(`[GET] Executing ${model.name}.findOne() with options: ${general.stringifyJSON(queryOptions)}`);
|
|
1484
1484
|
item = await model.findOne(queryOptions);
|
|
1485
1485
|
}
|
|
1486
1486
|
if (!item) {
|
|
@@ -1575,7 +1575,7 @@ registry)=>{
|
|
|
1575
1575
|
const comKey = key;
|
|
1576
1576
|
const queryOptions = processCompositeKey(comKey, model, kta);
|
|
1577
1577
|
logger$4.default(`Remove composite key query for ${model.name} with where fields: ${queryOptions.where ? Object.keys(queryOptions.where).join(', ') : 'none'}`);
|
|
1578
|
-
logger$4.debug(`[REMOVE] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
|
|
1578
|
+
logger$4.debug(`[REMOVE] Executing ${model.name}.findOne() with options: ${general.stringifyJSON(queryOptions)}`);
|
|
1579
1579
|
item = await model.findOne(queryOptions);
|
|
1580
1580
|
}
|
|
1581
1581
|
if (!item) {
|
|
@@ -1693,7 +1693,7 @@ const getUpdateOperation = (models, definition, registry)=>{
|
|
|
1693
1693
|
queryOptions.include = mergeIncludes([], additionalIncludes);
|
|
1694
1694
|
}
|
|
1695
1695
|
logger$3.default(`Update composite key query for ${model.name} with where fields: ${queryOptions.where ? Object.keys(queryOptions.where).join(', ') : 'none'}`);
|
|
1696
|
-
logger$3.trace(`[UPDATE] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
|
|
1696
|
+
logger$3.trace(`[UPDATE] Executing ${model.name}.findOne() with options: ${general.stringifyJSON(queryOptions)}`);
|
|
1697
1697
|
response = await model.findOne(queryOptions);
|
|
1698
1698
|
}
|
|
1699
1699
|
if (response) {
|
|
@@ -1705,7 +1705,7 @@ const getUpdateOperation = (models, definition, registry)=>{
|
|
|
1705
1705
|
logger$3.default(`Update found ${model.name} record to modify`);
|
|
1706
1706
|
logger$3.default(`Update properties configured: ${Object.keys(updateProps).join(', ')}`);
|
|
1707
1707
|
// Update the object
|
|
1708
|
-
logger$3.trace(`[UPDATE] Executing ${model.name}.update() with properties: ${stringifyJSON(updateProps)}`);
|
|
1708
|
+
logger$3.trace(`[UPDATE] Executing ${model.name}.update() with properties: ${general.stringifyJSON(updateProps)}`);
|
|
1709
1709
|
response = await response.update(updateProps);
|
|
1710
1710
|
// Populate the key and events
|
|
1711
1711
|
const processedItem = await processRow(response, kta, references, aggregations, registry);
|
|
@@ -1739,12 +1739,12 @@ const createOperations = (models, coordinate, registry, options)=>{
|
|
|
1739
1739
|
return operations;
|
|
1740
1740
|
};
|
|
1741
1741
|
|
|
1742
|
-
const logger$2 = logger$1.default.get("
|
|
1742
|
+
const logger$2 = logger$1.default.get("SequelizeLibrary");
|
|
1743
1743
|
/**
|
|
1744
|
-
* Creates a new
|
|
1744
|
+
* Creates a new SequelizeLibrary that extends the fjell-lib Library
|
|
1745
1745
|
* with Sequelize-specific functionality
|
|
1746
|
-
*/ const
|
|
1747
|
-
logger$2.debug("
|
|
1746
|
+
*/ const createSequelizeLibrary$2 = (registry, coordinate, models, options)=>{
|
|
1747
|
+
logger$2.debug("createSequelizeLibrary", {
|
|
1748
1748
|
coordinate,
|
|
1749
1749
|
models,
|
|
1750
1750
|
registry,
|
|
@@ -1752,24 +1752,24 @@ const logger$2 = logger$1.default.get("Instance");
|
|
|
1752
1752
|
});
|
|
1753
1753
|
// Create Sequelize-specific operations
|
|
1754
1754
|
const operations = createOperations(models, coordinate, registry, options);
|
|
1755
|
-
// Create the base fjell-lib
|
|
1756
|
-
const
|
|
1755
|
+
// Create the base fjell-lib library
|
|
1756
|
+
const libLibrary = Library__namespace.createLibrary(registry, coordinate, operations, options);
|
|
1757
1757
|
return {
|
|
1758
|
-
...
|
|
1758
|
+
...libLibrary,
|
|
1759
1759
|
models
|
|
1760
1760
|
};
|
|
1761
1761
|
};
|
|
1762
1762
|
/**
|
|
1763
|
-
* Type guard to check if an object is a
|
|
1764
|
-
*/ const
|
|
1765
|
-
return
|
|
1763
|
+
* Type guard to check if an object is a SequelizeLibrary
|
|
1764
|
+
*/ const isSequelizeLibrary = (library)=>{
|
|
1765
|
+
return library != null && library.coordinate != null && library.operations != null && library.options != null && library.registry != null && library.models != null && Array.isArray(library.models);
|
|
1766
1766
|
};
|
|
1767
1767
|
|
|
1768
1768
|
const logger$1 = logger$1.default.get("InstanceFactory");
|
|
1769
1769
|
/**
|
|
1770
|
-
* Factory function for creating Sequelize
|
|
1770
|
+
* Factory function for creating Sequelize libraries
|
|
1771
1771
|
* This extends the fjell-lib pattern by adding Sequelize-specific models
|
|
1772
|
-
*/ const
|
|
1772
|
+
*/ const createSequelizeLibraryFactory = (models, options)=>{
|
|
1773
1773
|
return (coordinate, context)=>{
|
|
1774
1774
|
logger$1.debug("Creating Sequelize instance", {
|
|
1775
1775
|
coordinate,
|
|
@@ -1777,11 +1777,11 @@ const logger$1 = logger$1.default.get("InstanceFactory");
|
|
|
1777
1777
|
models: models.map((m)=>m.name),
|
|
1778
1778
|
options
|
|
1779
1779
|
});
|
|
1780
|
-
return
|
|
1780
|
+
return createSequelizeLibrary$2(context.registry, coordinate, models, options);
|
|
1781
1781
|
};
|
|
1782
1782
|
};
|
|
1783
1783
|
|
|
1784
|
-
function
|
|
1784
|
+
function createSequelizeLibrary$1(keyTypes, models, libOptions = {}, scopes = [], registry) {
|
|
1785
1785
|
// Create coordinate and options separately following new pattern
|
|
1786
1786
|
const coordinate = createCoordinate(keyTypes, scopes);
|
|
1787
1787
|
const options = createOptions(libOptions);
|
|
@@ -1797,15 +1797,18 @@ function createInstance$1(keyTypes, models, libOptions = {}, scopes = [], regist
|
|
|
1797
1797
|
models
|
|
1798
1798
|
};
|
|
1799
1799
|
}
|
|
1800
|
+
// Legacy exports for backwards compatibility
|
|
1801
|
+
const createInstance$1 = createSequelizeLibrary$1;
|
|
1800
1802
|
|
|
1801
1803
|
const index$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
1802
1804
|
__proto__: null,
|
|
1803
|
-
createInstance: createInstance$1
|
|
1805
|
+
createInstance: createInstance$1,
|
|
1806
|
+
createSequelizeLibrary: createSequelizeLibrary$1
|
|
1804
1807
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
1805
1808
|
|
|
1806
1809
|
const logger = logger$1.default.get('lib-sequelize', 'primary', 'instance');
|
|
1807
|
-
function
|
|
1808
|
-
logger.debug('
|
|
1810
|
+
function createSequelizeLibrary(keyType, models, libOptions = {}, scopes = [], registry) {
|
|
1811
|
+
logger.debug('createSequelizeLibrary', {
|
|
1809
1812
|
keyType,
|
|
1810
1813
|
models,
|
|
1811
1814
|
libOptions,
|
|
@@ -1828,10 +1831,13 @@ function createInstance(keyType, models, libOptions = {}, scopes = [], registry)
|
|
|
1828
1831
|
models
|
|
1829
1832
|
};
|
|
1830
1833
|
}
|
|
1834
|
+
// Legacy exports for backwards compatibility
|
|
1835
|
+
const createInstance = createSequelizeLibrary;
|
|
1831
1836
|
|
|
1832
1837
|
const index = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
1833
1838
|
__proto__: null,
|
|
1834
|
-
createInstance
|
|
1839
|
+
createInstance,
|
|
1840
|
+
createSequelizeLibrary
|
|
1835
1841
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
1836
1842
|
|
|
1837
1843
|
exports.Contained = index$1;
|
|
@@ -1839,9 +1845,9 @@ exports.Primary = index;
|
|
|
1839
1845
|
exports.SCOPE_SEQUELIZE = SCOPE_SEQUELIZE;
|
|
1840
1846
|
exports.createCoordinate = createCoordinate;
|
|
1841
1847
|
exports.createDefinition = createDefinition;
|
|
1842
|
-
exports.createInstance = createInstance$2;
|
|
1843
|
-
exports.createInstanceFactory = createInstanceFactory;
|
|
1844
1848
|
exports.createOperations = createOperations;
|
|
1845
1849
|
exports.createOptions = createOptions;
|
|
1846
|
-
exports.
|
|
1850
|
+
exports.createSequelizeLibrary = createSequelizeLibrary$2;
|
|
1851
|
+
exports.createSequelizeLibraryFactory = createSequelizeLibraryFactory;
|
|
1852
|
+
exports.isSequelizeLibrary = isSequelizeLibrary;
|
|
1847
1853
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Item } from '@fjell/core';
|
|
2
|
+
import { Coordinate } from '@fjell/registry';
|
|
3
|
+
import { Registry } from './Registry';
|
|
4
|
+
import { ModelStatic } from 'sequelize';
|
|
5
|
+
import { Options } from './Options';
|
|
6
|
+
import * as Library from '@fjell/lib';
|
|
7
|
+
/**
|
|
8
|
+
* The SequelizeLibrary interface extends the fjell-lib Library
|
|
9
|
+
* and adds Sequelize-specific functionality:
|
|
10
|
+
* - models: Array of Sequelize model classes for this library
|
|
11
|
+
*
|
|
12
|
+
* @template V - The type of the data model item, extending Item
|
|
13
|
+
* @template S - The string literal type representing the model's key type
|
|
14
|
+
* @template L1-L5 - Optional string literal types for location hierarchy levels
|
|
15
|
+
*/
|
|
16
|
+
export interface SequelizeLibrary<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> extends Library.Library<V, S, L1, L2, L3, L4, L5> {
|
|
17
|
+
/** Array of Sequelize model classes associated with this library */
|
|
18
|
+
models: ModelStatic<any>[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new SequelizeLibrary that extends the fjell-lib Library
|
|
22
|
+
* with Sequelize-specific functionality
|
|
23
|
+
*/
|
|
24
|
+
export declare const createSequelizeLibrary: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(registry: Registry, coordinate: Coordinate<S, L1, L2, L3, L4, L5>, models: ModelStatic<any>[], options: Options<V, S, L1, L2, L3, L4, L5>) => SequelizeLibrary<V, S, L1, L2, L3, L4, L5>;
|
|
25
|
+
/**
|
|
26
|
+
* Type guard to check if an object is a SequelizeLibrary
|
|
27
|
+
*/
|
|
28
|
+
export declare const isSequelizeLibrary: (library: any) => library is SequelizeLibrary<any, any, any, any, any, any, any>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Item } from '@fjell/core';
|
|
2
|
+
import { Options } from './Options';
|
|
3
|
+
import { InstanceFactory as BaseInstanceFactory } from '@fjell/registry';
|
|
4
|
+
import { ModelStatic } from 'sequelize';
|
|
5
|
+
/**
|
|
6
|
+
* Sequelize Library Factory type that extends the base factory
|
|
7
|
+
* to include Sequelize-specific models parameter
|
|
8
|
+
*/
|
|
9
|
+
export type SequelizeLibraryFactory<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> = (models: ModelStatic<any>[], options: Options<V, S, L1, L2, L3, L4, L5>) => BaseInstanceFactory<S, L1, L2, L3, L4, L5>;
|
|
10
|
+
/**
|
|
11
|
+
* Factory function for creating Sequelize libraries
|
|
12
|
+
* This extends the fjell-lib pattern by adding Sequelize-specific models
|
|
13
|
+
*/
|
|
14
|
+
export declare const createSequelizeLibraryFactory: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(models: ModelStatic<any>[], options: Options<V, S, L1, L2, L3, L4, L5>) => BaseInstanceFactory<S, L1, L2, L3, L4, L5>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SequelizeLibrary as AbstractSequelizeLibrary } from '../SequelizeLibrary';
|
|
2
|
+
import { Item, ItemTypeArray } from '@fjell/core';
|
|
3
|
+
import { ModelStatic } from 'sequelize';
|
|
4
|
+
import { Registry } from '../Registry';
|
|
5
|
+
import { Options } from '../Options';
|
|
6
|
+
export interface SequelizeLibrary<V extends Item<S>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> extends AbstractSequelizeLibrary<V, S, L1, L2, L3, L4, L5> {
|
|
7
|
+
models: ModelStatic<any>[];
|
|
8
|
+
}
|
|
9
|
+
export declare function createSequelizeLibrary<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(keyTypes: ItemTypeArray<S, L1, L2, L3, L4, L5>, models: ModelStatic<any>[], libOptions: Partial<Options<V, S, L1, L2, L3, L4, L5>> | undefined, scopes: string[] | undefined, registry: Registry): SequelizeLibrary<V, S, L1, L2, L3, L4, L5>;
|
|
10
|
+
export declare const createInstance: typeof createSequelizeLibrary;
|
|
11
|
+
export type Instance<V extends Item<S>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> = SequelizeLibrary<V, S, L1, L2, L3, L4, L5>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './SequelizeLibrary';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './Definition';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
2
|
+
export * from './SequelizeLibrary';
|
|
3
|
+
export * from './SequelizeLibraryFactory';
|
|
4
4
|
export * from './Options';
|
|
5
5
|
export * from './Operations';
|
|
6
6
|
export * from './Registry';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SequelizeLibrary as AbstractSequelizeLibrary } from '../SequelizeLibrary';
|
|
2
|
+
import { Item } from '@fjell/core';
|
|
3
|
+
import { ModelStatic } from 'sequelize';
|
|
4
|
+
import { Options } from '../Options';
|
|
5
|
+
import { Registry } from '../Registry';
|
|
6
|
+
export interface SequelizeLibrary<V extends Item<S>, S extends string> extends AbstractSequelizeLibrary<V, S> {
|
|
7
|
+
models: ModelStatic<any>[];
|
|
8
|
+
}
|
|
9
|
+
export declare function createSequelizeLibrary<V extends Item<S>, S extends string>(keyType: S, models: ModelStatic<any>[], libOptions: Partial<Options<V, S>> | undefined, scopes: string[] | undefined, registry: Registry): SequelizeLibrary<V, S>;
|
|
10
|
+
export declare const createInstance: typeof createSequelizeLibrary;
|
|
11
|
+
export type Instance<V extends Item<S>, S extends string> = SequelizeLibrary<V, S>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './SequelizeLibrary';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fjell/lib-sequelize",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.12",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"library",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@fjell/core": "^4.4.7",
|
|
33
|
-
"@fjell/lib": "^4.4.
|
|
33
|
+
"@fjell/lib": "^4.4.13",
|
|
34
34
|
"@fjell/logging": "^4.4.7",
|
|
35
|
-
"@fjell/registry": "^4.4.
|
|
35
|
+
"@fjell/registry": "^4.4.11",
|
|
36
36
|
"dayjs": "^1.11.13",
|
|
37
37
|
"deepmerge": "^4.3.1",
|
|
38
38
|
"sequelize": "^6.37.7"
|
package/dist/es/Instance.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as Library from '@fjell/lib';
|
|
2
|
-
import { createOperations } from './Operations.js';
|
|
3
|
-
import LibLogger from './logger.js';
|
|
4
|
-
|
|
5
|
-
const logger = LibLogger.get("Instance");
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new Sequelize instance that extends the fjell-lib instance
|
|
8
|
-
* with Sequelize-specific functionality
|
|
9
|
-
*/ const createInstance = (registry, coordinate, models, options)=>{
|
|
10
|
-
logger.debug("createInstance", {
|
|
11
|
-
coordinate,
|
|
12
|
-
models,
|
|
13
|
-
registry,
|
|
14
|
-
options
|
|
15
|
-
});
|
|
16
|
-
// Create Sequelize-specific operations
|
|
17
|
-
const operations = createOperations(models, coordinate, registry, options);
|
|
18
|
-
// Create the base fjell-lib instance
|
|
19
|
-
const libInstance = Library.createInstance(registry, coordinate, operations, options);
|
|
20
|
-
return {
|
|
21
|
-
...libInstance,
|
|
22
|
-
models
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Type guard to check if an object is a Sequelize Instance
|
|
27
|
-
*/ const isInstance = (instance)=>{
|
|
28
|
-
return instance != null && instance.coordinate != null && instance.operations != null && instance.options != null && instance.registry != null && instance.models != null && Array.isArray(instance.models);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export { createInstance, isInstance };
|
|
32
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { createInstance } from './Instance.js';
|
|
2
|
-
import LibLogger from './logger.js';
|
|
3
|
-
|
|
4
|
-
const logger = LibLogger.get("InstanceFactory");
|
|
5
|
-
/**
|
|
6
|
-
* Factory function for creating Sequelize instances
|
|
7
|
-
* This extends the fjell-lib pattern by adding Sequelize-specific models
|
|
8
|
-
*/ const createInstanceFactory = (models, options)=>{
|
|
9
|
-
return (coordinate, context)=>{
|
|
10
|
-
logger.debug("Creating Sequelize instance", {
|
|
11
|
-
coordinate,
|
|
12
|
-
registry: context.registry,
|
|
13
|
-
models: models.map((m)=>m.name),
|
|
14
|
-
options
|
|
15
|
-
});
|
|
16
|
-
return createInstance(context.registry, coordinate, models, options);
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export { createInstanceFactory };
|
|
21
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2VGYWN0b3J5LmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
package/dist/types/Instance.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Item } from '@fjell/core';
|
|
2
|
-
import { Coordinate } from '@fjell/registry';
|
|
3
|
-
import { Registry } from './Registry';
|
|
4
|
-
import { ModelStatic } from 'sequelize';
|
|
5
|
-
import { Options } from './Options';
|
|
6
|
-
import * as Library from '@fjell/lib';
|
|
7
|
-
/**
|
|
8
|
-
* The Sequelize Instance interface extends the fjell-lib Instance
|
|
9
|
-
* and adds Sequelize-specific functionality:
|
|
10
|
-
* - models: Array of Sequelize model classes for this instance
|
|
11
|
-
*
|
|
12
|
-
* @template V - The type of the data model item, extending Item
|
|
13
|
-
* @template S - The string literal type representing the model's key type
|
|
14
|
-
* @template L1-L5 - Optional string literal types for location hierarchy levels
|
|
15
|
-
*/
|
|
16
|
-
export interface Instance<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> extends Library.Instance<V, S, L1, L2, L3, L4, L5> {
|
|
17
|
-
/** Array of Sequelize model classes associated with this instance */
|
|
18
|
-
models: ModelStatic<any>[];
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Creates a new Sequelize instance that extends the fjell-lib instance
|
|
22
|
-
* with Sequelize-specific functionality
|
|
23
|
-
*/
|
|
24
|
-
export declare const createInstance: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(registry: Registry, coordinate: Coordinate<S, L1, L2, L3, L4, L5>, models: ModelStatic<any>[], options: Options<V, S, L1, L2, L3, L4, L5>) => Instance<V, S, L1, L2, L3, L4, L5>;
|
|
25
|
-
/**
|
|
26
|
-
* Type guard to check if an object is a Sequelize Instance
|
|
27
|
-
*/
|
|
28
|
-
export declare const isInstance: (instance: any) => instance is Instance<any, any, any, any, any, any, any>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Item } from '@fjell/core';
|
|
2
|
-
import { Options } from './Options';
|
|
3
|
-
import { InstanceFactory as BaseInstanceFactory } from '@fjell/registry';
|
|
4
|
-
import { ModelStatic } from 'sequelize';
|
|
5
|
-
/**
|
|
6
|
-
* Sequelize Instance Factory type that extends the base factory
|
|
7
|
-
* to include Sequelize-specific models parameter
|
|
8
|
-
*/
|
|
9
|
-
export type InstanceFactory<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> = (models: ModelStatic<any>[], options: Options<V, S, L1, L2, L3, L4, L5>) => BaseInstanceFactory<S, L1, L2, L3, L4, L5>;
|
|
10
|
-
/**
|
|
11
|
-
* Factory function for creating Sequelize instances
|
|
12
|
-
* This extends the fjell-lib pattern by adding Sequelize-specific models
|
|
13
|
-
*/
|
|
14
|
-
export declare const createInstanceFactory: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(models: ModelStatic<any>[], options: Options<V, S, L1, L2, L3, L4, L5>) => BaseInstanceFactory<S, L1, L2, L3, L4, L5>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Instance as AbstractSequelizeInstance } from '../Instance';
|
|
2
|
-
import { Item, ItemTypeArray } from '@fjell/core';
|
|
3
|
-
import { ModelStatic } from 'sequelize';
|
|
4
|
-
import { Registry } from '../Registry';
|
|
5
|
-
import { Options } from '../Options';
|
|
6
|
-
export interface Instance<V extends Item<S>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> extends AbstractSequelizeInstance<V, S, L1, L2, L3, L4, L5> {
|
|
7
|
-
models: ModelStatic<any>[];
|
|
8
|
-
}
|
|
9
|
-
export declare function createInstance<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(keyTypes: ItemTypeArray<S, L1, L2, L3, L4, L5>, models: ModelStatic<any>[], libOptions: Partial<Options<V, S, L1, L2, L3, L4, L5>> | undefined, scopes: string[] | undefined, registry: Registry): Instance<V, S, L1, L2, L3, L4, L5>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Instance as AbstractSequelizeInstance } from '../Instance';
|
|
2
|
-
import { Item } from '@fjell/core';
|
|
3
|
-
import { ModelStatic } from 'sequelize';
|
|
4
|
-
import { Options } from '../Options';
|
|
5
|
-
import { Registry } from '../Registry';
|
|
6
|
-
export interface Instance<V extends Item<S>, S extends string> extends AbstractSequelizeInstance<V, S> {
|
|
7
|
-
models: ModelStatic<any>[];
|
|
8
|
-
}
|
|
9
|
-
export declare function createInstance<V extends Item<S>, S extends string>(keyType: S, models: ModelStatic<any>[], libOptions: Partial<Options<V, S>> | undefined, scopes: string[] | undefined, registry: Registry): Instance<V, S>;
|