@appweaver/data 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/config.d.ts +2 -0
  2. package/config.js +2 -0
  3. package/database/prisma-database.js +7 -1
  4. package/database/sqlserver-extension.d.ts +18 -0
  5. package/database/sqlserver-extension.js +269 -0
  6. package/factory/create-model.js +60 -1
  7. package/index.d.ts +1 -0
  8. package/index.js +1 -0
  9. package/module.js +19 -2
  10. package/package.json +3 -3
  11. package/prisma/client/browser.d.ts +10 -0
  12. package/prisma/client/client.d.ts +10 -0
  13. package/prisma/client/commonInputTypes.d.ts +81 -0
  14. package/prisma/client/enums.d.ts +6 -1
  15. package/prisma/client/enums.js +6 -0
  16. package/prisma/client/internal/class.d.ts +22 -0
  17. package/prisma/client/internal/class.js +4 -4
  18. package/prisma/client/internal/prismaNamespace.d.ts +175 -1
  19. package/prisma/client/internal/prismaNamespace.js +19 -1
  20. package/prisma/client/internal/prismaNamespaceBrowser.d.ts +20 -0
  21. package/prisma/client/internal/prismaNamespaceBrowser.js +19 -1
  22. package/prisma/client/models/TwoFactorMethod.d.ts +1140 -0
  23. package/prisma/client/models/TwoFactorMethod.js +2 -0
  24. package/prisma/client/models/TwoFactorRecoveryCode.d.ts +1005 -0
  25. package/prisma/client/models/TwoFactorRecoveryCode.js +2 -0
  26. package/prisma/client/models.d.ts +2 -0
  27. package/resource/resource-service.js +4 -0
  28. package/resource/utils/prune-util.js +3 -1
  29. package/resources.d.ts +4 -0
  30. package/resources.js +17 -9
  31. package/security/auth-config.d.ts +3 -0
  32. package/security/auth-config.js +6 -1
  33. package/security/create-auth-resources.d.ts +3 -3
  34. package/security/create-auth-resources.js +44 -7
  35. package/security/helper.d.ts +6 -0
  36. package/security/helper.js +11 -0
  37. package/security/resources/two-factor-method/model.d.ts +2 -0
  38. package/security/resources/two-factor-method/model.js +64 -0
  39. package/security/resources/two-factor-method/service.d.ts +2 -0
  40. package/security/resources/two-factor-method/service.js +7 -0
  41. package/security/resources/two-factor-recovery-code/model.d.ts +2 -0
  42. package/security/resources/two-factor-recovery-code/model.js +49 -0
  43. package/security/resources/two-factor-recovery-code/service.d.ts +2 -0
  44. package/security/resources/two-factor-recovery-code/service.js +7 -0
  45. package/security/store/database-security-store.d.ts +2 -2
  46. package/security/store/database-security-store.js +11 -1
  47. package/seeder/create-seeder.js +5 -1
  48. package/timeseries/database-series-config.d.ts +5 -0
  49. package/timeseries/database-series-config.js +15 -0
  50. package/timeseries/database-time-series.d.ts +36 -0
  51. package/timeseries/database-time-series.js +158 -0
  52. package/timeseries/index.d.ts +2 -0
  53. package/timeseries/index.js +18 -0
  54. package/timeseries/timescale-config.d.ts +6 -0
  55. package/timeseries/timescale-config.js +19 -0
  56. package/timeseries/timescale-time-series.d.ts +19 -0
  57. package/timeseries/timescale-time-series.js +131 -0
  58. package/timeseries/utils/series-sql-util.d.ts +90 -0
  59. package/timeseries/utils/series-sql-util.js +313 -0
  60. package/types/generated.d.ts +92 -0
package/config.d.ts CHANGED
@@ -4,3 +4,5 @@ export * from './export/export-config';
4
4
  export * from './resource/resource-config';
5
5
  export * from './security/auth-config';
6
6
  export * from './storage/image-config';
7
+ export * from './timeseries/database-series-config';
8
+ export * from './timeseries/timescale-config';
package/config.js CHANGED
@@ -20,3 +20,5 @@ __exportStar(require("./export/export-config"), exports);
20
20
  __exportStar(require("./resource/resource-config"), exports);
21
21
  __exportStar(require("./security/auth-config"), exports);
22
22
  __exportStar(require("./storage/image-config"), exports);
23
+ __exportStar(require("./timeseries/database-series-config"), exports);
24
+ __exportStar(require("./timeseries/timescale-config"), exports);
@@ -4,6 +4,7 @@ exports.PrismaDatabase = void 0;
4
4
  const common_1 = require("@appweaver/common");
5
5
  const database_config_1 = require("./database-config");
6
6
  const create_client_1 = require("./create-client");
7
+ const sqlserver_extension_1 = require("./sqlserver-extension");
7
8
  const internal_1 = require("@appweaver/core/internal");
8
9
  const logger = (0, common_1.createLogger)('database');
9
10
  // Members that act on the connection itself, never on a transaction
@@ -125,7 +126,12 @@ class PrismaDatabase extends common_1.Database {
125
126
  /** @internal */
126
127
  clientInstance() {
127
128
  if (!this._client) {
128
- this._client = (0, create_client_1.createClient)();
129
+ const client = (0, create_client_1.createClient)();
130
+ const dbType = (0, common_1.resolveDatabaseType)(database_config_1.databaseConfig.TYPE, database_config_1.databaseConfig.URL);
131
+ this._client =
132
+ dbType === common_1.DatabaseType.SQLServer
133
+ ? client.$extends((0, sqlserver_extension_1.sqlServerExtension)(this))
134
+ : client;
129
135
  }
130
136
  return this._client;
131
137
  }
@@ -0,0 +1,18 @@
1
+ /** The database the extension runs its queries on. */
2
+ export type ExtendedDatabase = {
3
+ /** Returns the client running in the transaction of the current call */
4
+ client<T = any>(): T;
5
+ /** Runs a function in a transaction, or in the current one */
6
+ transaction<T>(fn: (tx: any) => Promise<T>): Promise<T>;
7
+ };
8
+ /**
9
+ * Creates the Prisma client extension of SQL Server, which has no JSON type and rejects the referential actions forming
10
+ * a cycle or a second path between two tables. The JSON fields are stored serialized in a string column, so they are
11
+ * serialized on every write and parsed in every result. A delete first applies the actions on delete SQL Server leaves
12
+ * to the data layer (see `sqlServerForeignKeys`), cascading to or setting null the referencing records, in the
13
+ * transaction of the delete.
14
+ *
15
+ * @param {ExtendedDatabase} database - The database whose transaction-aware client runs the referential actions.
16
+ * @return {Object} The Prisma client extension.
17
+ */
18
+ export declare function sqlServerExtension(database: ExtendedDatabase): any;
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sqlServerExtension = sqlServerExtension;
4
+ const common_1 = require("@appweaver/common");
5
+ const internal_1 = require("@appweaver/core/internal");
6
+ // The operations whose result holds no records
7
+ const COUNT_OPERATIONS = new Set([
8
+ 'count',
9
+ 'aggregate',
10
+ 'groupBy',
11
+ 'createMany',
12
+ 'updateMany',
13
+ 'deleteMany'
14
+ ]);
15
+ let cached;
16
+ /**
17
+ * Creates the Prisma client extension of SQL Server, which has no JSON type and rejects the referential actions forming
18
+ * a cycle or a second path between two tables. The JSON fields are stored serialized in a string column, so they are
19
+ * serialized on every write and parsed in every result. A delete first applies the actions on delete SQL Server leaves
20
+ * to the data layer (see `sqlServerForeignKeys`), cascading to or setting null the referencing records, in the
21
+ * transaction of the delete.
22
+ *
23
+ * @param {ExtendedDatabase} database - The database whose transaction-aware client runs the referential actions.
24
+ * @return {Object} The Prisma client extension.
25
+ */
26
+ function sqlServerExtension(database) {
27
+ return {
28
+ name: 'appweaver-sqlserver',
29
+ query: {
30
+ $allModels: {
31
+ async $allOperations({ model, operation, args, query }) {
32
+ const schema = sqlServerSchema();
33
+ if ((operation === 'delete' || operation === 'deleteMany') &&
34
+ schema.deleteActions.has(model)) {
35
+ if (!(0, internal_1.currentTransaction)()) {
36
+ return database.transaction((tx) => tx[(0, common_1.uncapitalize)(model)][operation](args));
37
+ }
38
+ const client = database.client();
39
+ const records = await client[(0, common_1.uncapitalize)(model)].findMany({
40
+ where: args?.where,
41
+ select: { id: true }
42
+ });
43
+ await applyDeleteActions(client, model, records.map((record) => record.id));
44
+ }
45
+ const result = await query(serializeArgs(model, operation, args));
46
+ return COUNT_OPERATIONS.has(operation)
47
+ ? result
48
+ : parseJsonFields(model, result);
49
+ }
50
+ }
51
+ }
52
+ };
53
+ }
54
+ /**
55
+ * Cascades to or sets null the records referencing the deleted ones through a foreign key whose action on delete
56
+ * SQL Server leaves to the data layer, and does the same for the records the database cascade deletes with them. A
57
+ * cascade of the data layer deletes through the extension again, so it applies the actions of its records too.
58
+ */
59
+ async function applyDeleteActions(client, modelName, ids) {
60
+ const { foreignKeys, deleteActions } = sqlServerSchema();
61
+ if (ids.length === 0) {
62
+ return;
63
+ }
64
+ for (const fk of foreignKeys) {
65
+ if (fk.referencedName !== modelName ||
66
+ fk.dbOnDelete !== 'cascade' ||
67
+ !deleteActions.has(fk.modelName)) {
68
+ continue;
69
+ }
70
+ const cascaded = await client[(0, common_1.uncapitalize)(fk.modelName)].findMany({
71
+ where: { [fk.foreignKey]: { in: ids } },
72
+ select: { id: true }
73
+ });
74
+ await applyDeleteActions(client, fk.modelName, cascaded.map((record) => record.id));
75
+ }
76
+ for (const fk of (0, common_1.emulatedForeignKeys)(foreignKeys, modelName)) {
77
+ const delegate = client[(0, common_1.uncapitalize)(fk.modelName)];
78
+ const referencing = {
79
+ [fk.foreignKey]: { in: ids },
80
+ // The deleted records referencing each other are deleted anyway
81
+ ...(fk.modelName === modelName ? { id: { notIn: ids } } : {})
82
+ };
83
+ if (fk.onDelete === 'cascade') {
84
+ await delegate.deleteMany({ where: referencing });
85
+ }
86
+ else {
87
+ await delegate.updateMany({
88
+ where: referencing,
89
+ data: { [fk.foreignKey]: null }
90
+ });
91
+ }
92
+ }
93
+ }
94
+ /** Serializes the JSON fields of the data a write operation stores. */
95
+ function serializeArgs(modelName, operation, args) {
96
+ if (!(0, common_1.isPlainObject)(args)) {
97
+ return args;
98
+ }
99
+ switch (operation) {
100
+ case 'create':
101
+ case 'createMany':
102
+ case 'createManyAndReturn':
103
+ case 'update':
104
+ case 'updateMany':
105
+ case 'updateManyAndReturn':
106
+ return { ...args, data: serializeData(modelName, args.data) };
107
+ case 'upsert':
108
+ return {
109
+ ...args,
110
+ create: serializeData(modelName, args.create),
111
+ update: serializeData(modelName, args.update)
112
+ };
113
+ default:
114
+ return args;
115
+ }
116
+ }
117
+ /** Serializes the JSON fields of a record's data, and of the nested writes of its relations. */
118
+ function serializeData(modelName, data) {
119
+ if ((0, common_1.isArray)(data)) {
120
+ return data.map((item) => serializeData(modelName, item));
121
+ }
122
+ if (!(0, common_1.isPlainObject)(data)) {
123
+ return data;
124
+ }
125
+ const schema = sqlServerSchema();
126
+ const jsonFields = schema.jsonFields.get(modelName);
127
+ const relatedModels = schema.relatedModels.get(modelName);
128
+ const serialized = { ...data };
129
+ for (const [key, value] of Object.entries(data)) {
130
+ if (jsonFields?.has(key) && value !== undefined) {
131
+ serialized[key] = serializeJson(value);
132
+ }
133
+ else if (relatedModels?.has(key) && (0, common_1.isPlainObject)(value)) {
134
+ serialized[key] = serializeNestedWrites(relatedModels.get(key), value);
135
+ }
136
+ }
137
+ return serialized;
138
+ }
139
+ /** Serializes the JSON fields of the records a nested relation write stores. */
140
+ function serializeNestedWrites(modelName, writes) {
141
+ const each = (value, fn) => (0, common_1.isArray)(value) ? value.map(fn) : fn(value);
142
+ const withData = (item) => (0, common_1.isPlainObject)(item) && 'data' in item
143
+ ? { ...item, data: serializeData(modelName, item.data) }
144
+ : serializeData(modelName, item);
145
+ const serialized = { ...writes };
146
+ for (const [action, value] of Object.entries(writes)) {
147
+ switch (action) {
148
+ case 'create':
149
+ serialized[action] = serializeData(modelName, value);
150
+ break;
151
+ case 'createMany':
152
+ serialized[action] = {
153
+ ...value,
154
+ data: serializeData(modelName, value?.data)
155
+ };
156
+ break;
157
+ case 'update':
158
+ case 'updateMany':
159
+ serialized[action] = each(value, withData);
160
+ break;
161
+ case 'upsert':
162
+ serialized[action] = each(value, (item) => ({
163
+ ...item,
164
+ create: serializeData(modelName, item?.create),
165
+ update: serializeData(modelName, item?.update)
166
+ }));
167
+ break;
168
+ case 'connectOrCreate':
169
+ serialized[action] = each(value, (item) => ({
170
+ ...item,
171
+ create: serializeData(modelName, item?.create)
172
+ }));
173
+ break;
174
+ }
175
+ }
176
+ return serialized;
177
+ }
178
+ /** Serializes a JSON value, storing the null sentinels of Prisma as null. */
179
+ function serializeJson(value) {
180
+ if (value === null || isNullSentinel(value)) {
181
+ return null;
182
+ }
183
+ return JSON.stringify(value);
184
+ }
185
+ /** Whether a value is `Prisma.DbNull`, `Prisma.JsonNull` or `Prisma.AnyNull`. */
186
+ function isNullSentinel(value) {
187
+ return (typeof value === 'object' &&
188
+ value !== null &&
189
+ /^(Db|Json|Any)Null(Class)?$/.test(value.constructor?.name ?? ''));
190
+ }
191
+ /** Parses the JSON fields of the records of a result, and of their included relations. */
192
+ function parseJsonFields(modelName, result) {
193
+ if ((0, common_1.isArray)(result)) {
194
+ return result.map((item) => parseJsonFields(modelName, item));
195
+ }
196
+ if (!(0, common_1.isPlainObject)(result)) {
197
+ return result;
198
+ }
199
+ const schema = sqlServerSchema();
200
+ const jsonFields = schema.jsonFields.get(modelName);
201
+ const relatedModels = schema.relatedModels.get(modelName);
202
+ for (const [key, value] of Object.entries(result)) {
203
+ if (jsonFields?.has(key) && typeof value === 'string') {
204
+ result[key] = JSON.parse(value);
205
+ }
206
+ else if (relatedModels?.has(key) && value !== null) {
207
+ result[key] = parseJsonFields(relatedModels.get(key), value);
208
+ }
209
+ }
210
+ return result;
211
+ }
212
+ /**
213
+ * The models whose delete needs the actions of the data layer: the ones referenced through a foreign key whose action
214
+ * the database leaves out, and the ones the database cascades from to such a model.
215
+ */
216
+ function deleteActionModels(foreignKeys) {
217
+ const models = new Set(foreignKeys
218
+ .filter((fk) => (0, common_1.emulatedForeignKeys)([fk], fk.referencedName).length > 0)
219
+ .map((fk) => fk.referencedName));
220
+ for (let size = -1; size !== models.size;) {
221
+ size = models.size;
222
+ for (const fk of foreignKeys) {
223
+ if (fk.dbOnDelete === 'cascade' && models.has(fk.modelName)) {
224
+ models.add(fk.referencedName);
225
+ }
226
+ }
227
+ }
228
+ return models;
229
+ }
230
+ /** Derives the schema of the loaded models, recomputed when the models change. */
231
+ function sqlServerSchema() {
232
+ const loaded = [
233
+ ...internal_1.context.resource.models.values()
234
+ ];
235
+ if (cached?.models.length === loaded.length &&
236
+ cached.models.every((model, i) => model === loaded[i])) {
237
+ return cached.schema;
238
+ }
239
+ const models = Object.fromEntries(loaded.map((m) => [m.name, m]));
240
+ const authModel = Object.values(models).find(common_1.isResourceAuthModel);
241
+ const jsonFields = new Map();
242
+ const relatedModels = new Map();
243
+ for (const model of Object.values(models)) {
244
+ jsonFields.set(model.name, new Set(Object.entries(model.config.scalars ?? {})
245
+ .filter(([, scalar]) => scalar.type === 'json')
246
+ .map(([field]) => field)));
247
+ const related = new Map();
248
+ for (const [field, relation] of Object.entries(model.config.relations ?? {})) {
249
+ related.set(field, (0, common_1.capitalize)(relation.model));
250
+ }
251
+ for (const field of Object.keys(model.config.files ?? {})) {
252
+ related.set(field, 'File');
253
+ }
254
+ if (authModel) {
255
+ related.set('createdBy', authModel.name);
256
+ related.set('deletedBy', authModel.name);
257
+ }
258
+ relatedModels.set(model.name, related);
259
+ }
260
+ const foreignKeys = (0, common_1.sqlServerForeignKeys)(models);
261
+ const schema = {
262
+ foreignKeys,
263
+ deleteActions: deleteActionModels(foreignKeys),
264
+ jsonFields,
265
+ relatedModels
266
+ };
267
+ cached = { models: loaded, schema };
268
+ return schema;
269
+ }
@@ -18,6 +18,7 @@ const logger = (0, common_1.createLogger)('resource');
18
18
  */
19
19
  function createModel(modelConfig, override = false) {
20
20
  const config = normalizeRelations(modelConfig);
21
+ validateSeries(config);
21
22
  const resourceModel = buildModel(config);
22
23
  logger.debug({ modelName: resourceModel.name }, 'Created resource model');
23
24
  (0, core_1.define)(resourceModel, undefined, override ? 'override' : undefined);
@@ -52,6 +53,62 @@ function normalizeRelations(config) {
52
53
  }
53
54
  return { ...config, relations };
54
55
  }
56
+ const SERIES_RESERVED_NAMES = ['time', 'resourceId'];
57
+ const SERIES_TYPES = ['float', 'int', 'boolean'];
58
+ const SERIES_INGESTS = ['direct', 'queue', 'auto'];
59
+ /**
60
+ * Checks the series of a model: the types of its fields, names leaving the `time` and `resourceId` of a point free,
61
+ * and the durations and the ingest of its options.
62
+ *
63
+ * @throws {ConfigurationError} For a series field with a reserved name or an unknown type, or an invalid option.
64
+ */
65
+ function validateSeries(config) {
66
+ for (const [field, series] of Object.entries(config.series ?? {})) {
67
+ if (SERIES_RESERVED_NAMES.includes(field) || !/^[A-Za-z]\w*$/.test(field)) {
68
+ throw new common_1.ConfigurationError(common_1.ErrorCode.ConfigurationInvalid, `Series field '${config.name}.${field}' must be an identifier other than ${SERIES_RESERVED_NAMES.join(' and ')}`);
69
+ }
70
+ if (!SERIES_TYPES.includes(series.type)) {
71
+ throw new common_1.ConfigurationError(common_1.ErrorCode.ConfigurationInvalid, `Series field '${config.name}.${field}' has the type '${series.type}', not one of ${SERIES_TYPES.join(', ')}`);
72
+ }
73
+ }
74
+ const options = config.seriesOptions ?? {};
75
+ for (const option of [
76
+ 'retention',
77
+ 'chunkInterval',
78
+ 'compressAfter'
79
+ ]) {
80
+ const duration = options[option];
81
+ if (duration === undefined) {
82
+ continue;
83
+ }
84
+ const seconds = (0, common_1.parseDuration)(duration);
85
+ if (!seconds || !Number.isInteger(seconds)) {
86
+ throw new common_1.ConfigurationError(common_1.ErrorCode.ConfigurationInvalid, `Series option '${config.name}.${option}' is '${duration}', not a duration of whole seconds, i.e. 30d`);
87
+ }
88
+ }
89
+ if (options.ingest && !SERIES_INGESTS.includes(options.ingest)) {
90
+ throw new common_1.ConfigurationError(common_1.ErrorCode.ConfigurationInvalid, `Series option '${config.name}.ingest' is '${options.ingest}', not one of ${SERIES_INGESTS.join(', ')}`);
91
+ }
92
+ }
93
+ /** The values of the series fields, each optional and nullable, a null leaving the stored value unchanged. */
94
+ function buildSeriesModel(series) {
95
+ const properties = {};
96
+ for (const [name, field] of Object.entries(series ?? {})) {
97
+ const options = (0, common_1.pickProperties)(field, [
98
+ 'minimum',
99
+ 'maximum',
100
+ 'description',
101
+ 'example'
102
+ ]);
103
+ const schema = field.type === 'boolean'
104
+ ? typebox_1.Type.Boolean((0, common_1.pickProperties)(field, ['description', 'example']))
105
+ : field.type === 'int'
106
+ ? typebox_1.Type.Integer(options)
107
+ : typebox_1.Type.Number(options);
108
+ properties[name] = typebox_1.Type.Optional((0, common_1.Nullable)(schema));
109
+ }
110
+ return typebox_1.Type.Object(properties);
111
+ }
55
112
  function buildModel(config) {
56
113
  const name = (0, common_1.capitalize)(config.name);
57
114
  const idSchema = (0, model_schema_1.idSchema)(config?.id);
@@ -88,6 +145,7 @@ function buildModel(config) {
88
145
  const readOneNullableModel = buildNullableOutputModel(name);
89
146
  const { createOneModel, updateOneModel, replaceOneModel, relationCreateModel, relationUpdateModel } = buildInputModels(createModel, updateModel, replaceModel, relationsModel, idSchema, config);
90
147
  const { fileUploadModel, fileDeleteModel } = buildFileInputModels(config);
148
+ const seriesModel = buildSeriesModel(config.series);
91
149
  const resourceModel = {
92
150
  name,
93
151
  config: config,
@@ -107,7 +165,8 @@ function buildModel(config) {
107
165
  relationCreateModel,
108
166
  relationUpdateModel,
109
167
  fileUploadModel,
110
- fileDeleteModel
168
+ fileDeleteModel,
169
+ seriesModel
111
170
  };
112
171
  for (const value of Object.values(resourceModel)) {
113
172
  if ((0, common_1.isPlainObject)(value)) {
package/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export * from './security/create-auth-resources';
12
12
  export * from './security/helper';
13
13
  export * from './seeder';
14
14
  export * from './storage/file-service';
15
+ export * from './timeseries';
15
16
  export * from './types/auth';
16
17
  export * from './types/generated';
17
18
  export * from './types/storage';
package/index.js CHANGED
@@ -28,6 +28,7 @@ __exportStar(require("./security/create-auth-resources"), exports);
28
28
  __exportStar(require("./security/helper"), exports);
29
29
  __exportStar(require("./seeder"), exports);
30
30
  __exportStar(require("./storage/file-service"), exports);
31
+ __exportStar(require("./timeseries"), exports);
31
32
  __exportStar(require("./types/auth"), exports);
32
33
  __exportStar(require("./types/generated"), exports);
33
34
  __exportStar(require("./types/storage"), exports);
package/module.js CHANGED
@@ -39,6 +39,8 @@ const export_config_1 = require("./export/export-config");
39
39
  const resource_config_1 = require("./resource/resource-config");
40
40
  const auth_config_1 = require("./security/auth-config");
41
41
  const image_config_1 = require("./storage/image-config");
42
+ const database_series_config_1 = require("./timeseries/database-series-config");
43
+ const timescale_config_1 = require("./timeseries/timescale-config");
42
44
  /** The database, the resources and the auth data model, built on Prisma. */
43
45
  exports.default = (0, common_1.defineModule)({
44
46
  name: '@appweaver/data',
@@ -50,9 +52,12 @@ exports.default = (0, common_1.defineModule)({
50
52
  auth_config_1.passwordConfig,
51
53
  auth_config_1.apiKeyConfig,
52
54
  auth_config_1.connectedAccountConfig,
53
- auth_config_1.systemConfig
55
+ auth_config_1.twoFactorModelConfig,
56
+ auth_config_1.systemConfig,
57
+ database_series_config_1.databaseSeriesConfig,
58
+ timescale_config_1.timescaleConfig
54
59
  ],
55
- loggers: ['database', 'resource', 'storage'],
60
+ loggers: ['database', 'resource', 'storage', 'timeseries'],
56
61
  contracts: [
57
62
  { contract: common_1.Database, provider: () => database_config_1.databaseConfig.PROVIDER },
58
63
  { contract: common_1.ImageProcessor, provider: () => image_config_1.imageConfig.PROVIDER }
@@ -68,6 +73,18 @@ exports.default = (0, common_1.defineModule)({
68
73
  name: 'database',
69
74
  load: () => Promise.resolve().then(() => __importStar(require('./security/store/database-security-store'))),
70
75
  auto: 'fallback'
76
+ },
77
+ {
78
+ contract: common_1.TimeSeries,
79
+ name: 'database',
80
+ load: () => Promise.resolve().then(() => __importStar(require('./timeseries/database-time-series'))),
81
+ auto: 'fallback'
82
+ },
83
+ {
84
+ contract: common_1.TimeSeries,
85
+ name: 'timescale',
86
+ load: () => Promise.resolve().then(() => __importStar(require('./timeseries/timescale-time-series'))),
87
+ auto: false
71
88
  }
72
89
  ],
73
90
  services: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appweaver/data",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Appweaver - the backend framework for AI-first development (@data)",
5
5
  "author": "Luka Matosevic",
6
6
  "license": "MIT",
@@ -51,8 +51,8 @@
51
51
  "csv-stringify": "6.8.0"
52
52
  },
53
53
  "peerDependencies": {
54
- "@appweaver/common": "^2.4.0",
55
- "@appweaver/core": "^2.4.0",
54
+ "@appweaver/common": "^2.5.0",
55
+ "@appweaver/core": "^2.5.0",
56
56
  "@prisma/client": "^7.9.0"
57
57
  },
58
58
  "devDependencies": {
@@ -27,6 +27,16 @@ export type Permission = Prisma.PermissionModel;
27
27
  *
28
28
  */
29
29
  export type Role = Prisma.RoleModel;
30
+ /**
31
+ * Model TwoFactorMethod
32
+ *
33
+ */
34
+ export type TwoFactorMethod = Prisma.TwoFactorMethodModel;
35
+ /**
36
+ * Model TwoFactorRecoveryCode
37
+ *
38
+ */
39
+ export type TwoFactorRecoveryCode = Prisma.TwoFactorRecoveryCodeModel;
30
40
  /**
31
41
  * Model Seeder
32
42
  *
@@ -46,6 +46,16 @@ export type Permission = Prisma.PermissionModel;
46
46
  *
47
47
  */
48
48
  export type Role = Prisma.RoleModel;
49
+ /**
50
+ * Model TwoFactorMethod
51
+ *
52
+ */
53
+ export type TwoFactorMethod = Prisma.TwoFactorMethodModel;
54
+ /**
55
+ * Model TwoFactorRecoveryCode
56
+ *
57
+ */
58
+ export type TwoFactorRecoveryCode = Prisma.TwoFactorRecoveryCodeModel;
49
59
  /**
50
60
  * Model Seeder
51
61
  *
@@ -1,4 +1,5 @@
1
1
  import type * as runtime from "@prisma/client/runtime/client";
2
+ import * as $Enums from "./enums";
2
3
  import type * as Prisma from "./internal/prismaNamespace";
3
4
  export type IntFilter<$PrismaModel = never> = {
4
5
  equals?: number | Prisma.IntFieldRefInput<$PrismaModel>;
@@ -171,6 +172,46 @@ export type JsonWithAggregatesFilterBase<$PrismaModel = never> = {
171
172
  _min?: Prisma.NestedJsonFilter<$PrismaModel>;
172
173
  _max?: Prisma.NestedJsonFilter<$PrismaModel>;
173
174
  };
175
+ export type EnumTwoFactorMethodTypeFilter<$PrismaModel = never> = {
176
+ equals?: $Enums.TwoFactorMethodType | Prisma.EnumTwoFactorMethodTypeFieldRefInput<$PrismaModel>;
177
+ in?: $Enums.TwoFactorMethodType[];
178
+ notIn?: $Enums.TwoFactorMethodType[];
179
+ not?: Prisma.NestedEnumTwoFactorMethodTypeFilter<$PrismaModel> | $Enums.TwoFactorMethodType;
180
+ };
181
+ export type IntNullableFilter<$PrismaModel = never> = {
182
+ equals?: number | Prisma.IntFieldRefInput<$PrismaModel> | null;
183
+ in?: number[] | null;
184
+ notIn?: number[] | null;
185
+ lt?: number | Prisma.IntFieldRefInput<$PrismaModel>;
186
+ lte?: number | Prisma.IntFieldRefInput<$PrismaModel>;
187
+ gt?: number | Prisma.IntFieldRefInput<$PrismaModel>;
188
+ gte?: number | Prisma.IntFieldRefInput<$PrismaModel>;
189
+ not?: Prisma.NestedIntNullableFilter<$PrismaModel> | number | null;
190
+ };
191
+ export type EnumTwoFactorMethodTypeWithAggregatesFilter<$PrismaModel = never> = {
192
+ equals?: $Enums.TwoFactorMethodType | Prisma.EnumTwoFactorMethodTypeFieldRefInput<$PrismaModel>;
193
+ in?: $Enums.TwoFactorMethodType[];
194
+ notIn?: $Enums.TwoFactorMethodType[];
195
+ not?: Prisma.NestedEnumTwoFactorMethodTypeWithAggregatesFilter<$PrismaModel> | $Enums.TwoFactorMethodType;
196
+ _count?: Prisma.NestedIntFilter<$PrismaModel>;
197
+ _min?: Prisma.NestedEnumTwoFactorMethodTypeFilter<$PrismaModel>;
198
+ _max?: Prisma.NestedEnumTwoFactorMethodTypeFilter<$PrismaModel>;
199
+ };
200
+ export type IntNullableWithAggregatesFilter<$PrismaModel = never> = {
201
+ equals?: number | Prisma.IntFieldRefInput<$PrismaModel> | null;
202
+ in?: number[] | null;
203
+ notIn?: number[] | null;
204
+ lt?: number | Prisma.IntFieldRefInput<$PrismaModel>;
205
+ lte?: number | Prisma.IntFieldRefInput<$PrismaModel>;
206
+ gt?: number | Prisma.IntFieldRefInput<$PrismaModel>;
207
+ gte?: number | Prisma.IntFieldRefInput<$PrismaModel>;
208
+ not?: Prisma.NestedIntNullableWithAggregatesFilter<$PrismaModel> | number | null;
209
+ _count?: Prisma.NestedIntNullableFilter<$PrismaModel>;
210
+ _avg?: Prisma.NestedFloatNullableFilter<$PrismaModel>;
211
+ _sum?: Prisma.NestedIntNullableFilter<$PrismaModel>;
212
+ _min?: Prisma.NestedIntNullableFilter<$PrismaModel>;
213
+ _max?: Prisma.NestedIntNullableFilter<$PrismaModel>;
214
+ };
174
215
  export type NestedIntFilter<$PrismaModel = never> = {
175
216
  equals?: number | Prisma.IntFieldRefInput<$PrismaModel>;
176
217
  in?: number[];
@@ -343,3 +384,43 @@ export type NestedJsonFilterBase<$PrismaModel = never> = {
343
384
  array_ends_with?: runtime.InputJsonValue | Prisma.JsonFieldRefInput<$PrismaModel> | null;
344
385
  not?: runtime.InputJsonValue | Prisma.JsonFieldRefInput<$PrismaModel> | Prisma.JsonNullValueFilter;
345
386
  };
387
+ export type NestedEnumTwoFactorMethodTypeFilter<$PrismaModel = never> = {
388
+ equals?: $Enums.TwoFactorMethodType | Prisma.EnumTwoFactorMethodTypeFieldRefInput<$PrismaModel>;
389
+ in?: $Enums.TwoFactorMethodType[];
390
+ notIn?: $Enums.TwoFactorMethodType[];
391
+ not?: Prisma.NestedEnumTwoFactorMethodTypeFilter<$PrismaModel> | $Enums.TwoFactorMethodType;
392
+ };
393
+ export type NestedEnumTwoFactorMethodTypeWithAggregatesFilter<$PrismaModel = never> = {
394
+ equals?: $Enums.TwoFactorMethodType | Prisma.EnumTwoFactorMethodTypeFieldRefInput<$PrismaModel>;
395
+ in?: $Enums.TwoFactorMethodType[];
396
+ notIn?: $Enums.TwoFactorMethodType[];
397
+ not?: Prisma.NestedEnumTwoFactorMethodTypeWithAggregatesFilter<$PrismaModel> | $Enums.TwoFactorMethodType;
398
+ _count?: Prisma.NestedIntFilter<$PrismaModel>;
399
+ _min?: Prisma.NestedEnumTwoFactorMethodTypeFilter<$PrismaModel>;
400
+ _max?: Prisma.NestedEnumTwoFactorMethodTypeFilter<$PrismaModel>;
401
+ };
402
+ export type NestedIntNullableWithAggregatesFilter<$PrismaModel = never> = {
403
+ equals?: number | Prisma.IntFieldRefInput<$PrismaModel> | null;
404
+ in?: number[] | null;
405
+ notIn?: number[] | null;
406
+ lt?: number | Prisma.IntFieldRefInput<$PrismaModel>;
407
+ lte?: number | Prisma.IntFieldRefInput<$PrismaModel>;
408
+ gt?: number | Prisma.IntFieldRefInput<$PrismaModel>;
409
+ gte?: number | Prisma.IntFieldRefInput<$PrismaModel>;
410
+ not?: Prisma.NestedIntNullableWithAggregatesFilter<$PrismaModel> | number | null;
411
+ _count?: Prisma.NestedIntNullableFilter<$PrismaModel>;
412
+ _avg?: Prisma.NestedFloatNullableFilter<$PrismaModel>;
413
+ _sum?: Prisma.NestedIntNullableFilter<$PrismaModel>;
414
+ _min?: Prisma.NestedIntNullableFilter<$PrismaModel>;
415
+ _max?: Prisma.NestedIntNullableFilter<$PrismaModel>;
416
+ };
417
+ export type NestedFloatNullableFilter<$PrismaModel = never> = {
418
+ equals?: number | Prisma.FloatFieldRefInput<$PrismaModel> | null;
419
+ in?: number[] | null;
420
+ notIn?: number[] | null;
421
+ lt?: number | Prisma.FloatFieldRefInput<$PrismaModel>;
422
+ lte?: number | Prisma.FloatFieldRefInput<$PrismaModel>;
423
+ gt?: number | Prisma.FloatFieldRefInput<$PrismaModel>;
424
+ gte?: number | Prisma.FloatFieldRefInput<$PrismaModel>;
425
+ not?: Prisma.NestedFloatNullableFilter<$PrismaModel> | number | null;
426
+ };
@@ -1 +1,6 @@
1
- export {};
1
+ export declare const TwoFactorMethodType: {
2
+ readonly Email: "Email";
3
+ readonly Sms: "Sms";
4
+ readonly Totp: "Totp";
5
+ };
6
+ export type TwoFactorMethodType = (typeof TwoFactorMethodType)[keyof typeof TwoFactorMethodType];
@@ -9,3 +9,9 @@
9
9
  * 🟢 You can import this file directly.
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TwoFactorMethodType = void 0;
13
+ exports.TwoFactorMethodType = {
14
+ Email: 'Email',
15
+ Sms: 'Sms',
16
+ Totp: 'Totp'
17
+ };