@autofleet/sadot 1.0.36 → 1.1.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/v1/validator/validations.d.cts +23 -0
- package/dist/api/v1/validator/validations.d.ts +23 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/models/CustomFieldDefinition.d.cts +31 -2
- package/dist/models/CustomFieldDefinition.d.ts +30 -3
- package/dist/models/CustomFieldEntries.d.cts +16 -0
- package/dist/models/CustomFieldEntries.d.ts +16 -2
- package/dist/models/CustomFieldValue.d.cts +22 -1
- package/dist/models/CustomFieldValue.d.ts +21 -2
- package/dist/models/CustomValidator.d.cts +19 -0
- package/dist/models/CustomValidator.d.ts +19 -3
- package/dist/models/index.cjs +1 -1
- package/dist/models/index.cjs.map +1 -1
- package/dist/models/index.d.cts +4 -2
- package/dist/models/index.d.ts +4 -4
- package/dist/models/index.js +1 -1
- package/dist/models/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Joi from "joi";
|
|
2
|
+
|
|
3
|
+
//#region src/api/v1/validator/validations.d.ts
|
|
4
|
+
interface SchemaObject {
|
|
5
|
+
type: "object";
|
|
6
|
+
properties?: {
|
|
7
|
+
before?: object;
|
|
8
|
+
after?: object;
|
|
9
|
+
};
|
|
10
|
+
required?: string[];
|
|
11
|
+
allOf?: object[];
|
|
12
|
+
anyOf?: object[];
|
|
13
|
+
oneOf?: object[];
|
|
14
|
+
additionalProperties?: boolean | object;
|
|
15
|
+
$id?: string;
|
|
16
|
+
$schema?: string;
|
|
17
|
+
if?: object;
|
|
18
|
+
then?: object;
|
|
19
|
+
else?: object;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { SchemaObject };
|
|
23
|
+
//# sourceMappingURL=validations.d.cts.map
|
|
@@ -1 +1,23 @@
|
|
|
1
|
-
import Joi from "joi";
|
|
1
|
+
import Joi from "joi";
|
|
2
|
+
|
|
3
|
+
//#region src/api/v1/validator/validations.d.ts
|
|
4
|
+
interface SchemaObject {
|
|
5
|
+
type: "object";
|
|
6
|
+
properties?: {
|
|
7
|
+
before?: object;
|
|
8
|
+
after?: object;
|
|
9
|
+
};
|
|
10
|
+
required?: string[];
|
|
11
|
+
allOf?: object[];
|
|
12
|
+
anyOf?: object[];
|
|
13
|
+
oneOf?: object[];
|
|
14
|
+
additionalProperties?: boolean | object;
|
|
15
|
+
$id?: string;
|
|
16
|
+
$schema?: string;
|
|
17
|
+
if?: object;
|
|
18
|
+
then?: object;
|
|
19
|
+
else?: object;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { SchemaObject };
|
|
23
|
+
//# sourceMappingURL=validations.d.ts.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./utils/logger/index.cjs`),t=require(`./utils/constants/index.cjs`),n=require(`./models/
|
|
1
|
+
Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./utils/logger/index.cjs`),t=require(`./utils/constants/index.cjs`),n=require(`./models/CustomFieldDefinition.cjs`),r=require(`./models/CustomFieldValue.cjs`),i=require(`./models/CustomFieldEntries.cjs`),a=require(`./models/CustomValidator.cjs`),o=require(`./models/index.cjs`),s=require(`./api/index.cjs`),c=require(`./utils/db/index.cjs`),l=require(`./utils/helpers/index.cjs`),u=require(`./scopes/filter.cjs`),d=require(`./utils/init.cjs`),f=require(`./utils/validations/schema/custom-fields.cjs`),p=async(t,n,r)=>{e.tryAddingTraceIdMiddleware();let{models:i,useCustomFieldsEntries:a}=r;t&&t.use(`/api`,s.default);let l=r.sequelize??c.default(r.databaseConfig);return process.env.NODE_ENV===`test`&&await o.initTestModels(l),d.addHooks(i,n,{useCustomFieldsEntries:a}),await o.initTables(l,r.getUser,{useCustomFieldsEntries:a}),d.addScopes(i,n,{useCustomFieldsEntries:a}),d.applyCustomAssociation(i),e.default.debug(`sadot - custom fields finished initializing with models`,i),l};var m=p;const h=(e,t)=>{d.removeHooks(e,t)};exports.CUSTOM_FIELDS_FILTER_SCOPE=t.CUSTOM_FIELDS_FILTER_SCOPE,exports.CustomFieldDefinition=n.default,exports.CustomFieldDefinitionType=t.CustomFieldDefinitionType,exports.CustomFieldEntries=i.default,exports.CustomFieldValue=r.default,exports.CustomFieldsSchema=f.CustomFieldsSchema,exports.CustomValidator=a.default,exports.customFieldsSortScope=u.customFieldsSortScope,exports.default=m,exports.disableCustomFields=h,exports.generateCustomFieldSearchQueryPayload=l.generateCustomFieldSearchQueryPayload,exports.generateRandomString=l.generateRandomString,exports.supportedEntities=t.supportedEntities;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["api","initDB","initTestModels","initTables"],"sources":["../src/index.ts"],"sourcesContent":["import type { Application } from 'express';\nimport type { Sequelize } from 'sequelize-typescript';\nimport {\n initTables, initTestModels,\n} from './models';\nimport api from './api';\nimport initDB from './utils/db';\nimport logger, { tryAddingTraceIdMiddleware } from './utils/logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from './types';\nimport {\n addHooks, addScopes, applyCustomAssociation, removeHooks,\n} from './utils/init';\n\nexport * from './utils/validations/schema/custom-fields';\n\nexport * from './utils/constants';\n\nexport * from './utils/helpers';\n\nexport { customFieldsSortScope } from './scopes/filter';\n\n/**\n * Adding custom fields enrichment to the models inside the MODELS_FILE_NAME json file\n * @see {@link 'custom-fields/config'} for configurations\n */\nconst useCustomFields = async (\n app: Pick<Application, 'use'> | null,\n getModel: ModelFetcher,\n options: CustomFieldOptions,\n): Promise<Sequelize> => {\n tryAddingTraceIdMiddleware();\n const { models, useCustomFieldsEntries } = options;\n if (app) {\n app.use('/api', api);\n }\n const sequelize = options.sequelize ?? initDB(options.databaseConfig);\n if (process.env.NODE_ENV === 'test') {\n await initTestModels(sequelize);\n }\n // The order is important\n addHooks(models, getModel, { useCustomFieldsEntries });\n await initTables(sequelize, options.getUser, { useCustomFieldsEntries });\n addScopes(models, getModel, { useCustomFieldsEntries });\n applyCustomAssociation(models);\n\n logger.debug('sadot - custom fields finished initializing with models', models);\n return sequelize;\n};\n\nexport default useCustomFields;\n\nexport const disableCustomFields = (models: Models[], getModel: ModelFetcher): void => {\n removeHooks(models, getModel);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["api","initDB","initTestModels","initTables"],"sources":["../src/index.ts"],"sourcesContent":["import type { Application } from 'express';\nimport type { Sequelize } from 'sequelize-typescript';\nimport {\n initTables, initTestModels,\n} from './models';\nimport api from './api';\nimport initDB from './utils/db';\nimport logger, { tryAddingTraceIdMiddleware } from './utils/logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from './types';\nimport {\n addHooks, addScopes, applyCustomAssociation, removeHooks,\n} from './utils/init';\n\nexport * from './utils/validations/schema/custom-fields';\n\nexport * from './utils/constants';\n\nexport * from './utils/helpers';\n\nexport { customFieldsSortScope } from './scopes/filter';\nexport {\n CustomFieldDefinition,\n CustomFieldEntries,\n CustomFieldValue,\n CustomValidator,\n} from './models';\n\n/**\n * Adding custom fields enrichment to the models inside the MODELS_FILE_NAME json file\n * @see {@link 'custom-fields/config'} for configurations\n */\nconst useCustomFields = async (\n app: Pick<Application, 'use'> | null,\n getModel: ModelFetcher,\n options: CustomFieldOptions,\n): Promise<Sequelize> => {\n tryAddingTraceIdMiddleware();\n const { models, useCustomFieldsEntries } = options;\n if (app) {\n app.use('/api', api);\n }\n const sequelize = options.sequelize ?? initDB(options.databaseConfig);\n if (process.env.NODE_ENV === 'test') {\n await initTestModels(sequelize);\n }\n // The order is important\n addHooks(models, getModel, { useCustomFieldsEntries });\n await initTables(sequelize, options.getUser, { useCustomFieldsEntries });\n addScopes(models, getModel, { useCustomFieldsEntries });\n applyCustomAssociation(models);\n\n logger.debug('sadot - custom fields finished initializing with models', models);\n return sequelize;\n};\n\nexport default useCustomFields;\n\nexport const disableCustomFields = (models: Models[], getModel: ModelFetcher): void => {\n removeHooks(models, getModel);\n};\n"],"mappings":"6jBA+BM,EAAkB,MACtB,EACA,EACA,IACuB,CACvB,EAAA,4BAA4B,CAC5B,GAAM,CAAE,SAAQ,0BAA2B,EACvC,GACF,EAAI,IAAI,OAAQA,EAAAA,QAAI,CAEtB,IAAM,EAAY,EAAQ,WAAaC,EAAAA,QAAO,EAAQ,eAAe,CAWrE,OAVI,QAAQ,IAAI,WAAa,QAC3B,MAAMC,EAAAA,eAAe,EAAU,CAGjC,EAAA,SAAS,EAAQ,EAAU,CAAE,yBAAwB,CAAC,CACtD,MAAMC,EAAAA,WAAW,EAAW,EAAQ,QAAS,CAAE,yBAAwB,CAAC,CACxE,EAAA,UAAU,EAAQ,EAAU,CAAE,yBAAwB,CAAC,CACvD,EAAA,uBAAuB,EAAO,CAE9B,EAAA,QAAO,MAAM,0DAA2D,EAAO,CACxE,GAGT,IAAA,EAAe,EAEf,MAAa,GAAuB,EAAkB,IAAiC,CACrF,EAAA,YAAY,EAAQ,EAAS"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, supportedEntities } from "./utils/constants/index.cjs";
|
|
2
|
+
import { CustomFieldValue } from "./models/CustomFieldValue.cjs";
|
|
3
|
+
import { CustomFieldEntries } from "./models/CustomFieldEntries.cjs";
|
|
4
|
+
import { CustomValidator } from "./models/CustomValidator.cjs";
|
|
5
|
+
import "./models/index.cjs";
|
|
6
|
+
import { CustomFieldDefinition } from "./models/CustomFieldDefinition.cjs";
|
|
2
7
|
import { CustomFieldOptions, ModelFetcher, Models } from "./types/index.cjs";
|
|
3
8
|
import { CustomFieldsSchema } from "./utils/validations/schema/custom-fields.cjs";
|
|
4
9
|
import { generateCustomFieldSearchQueryPayload, generateRandomString } from "./utils/helpers/index.cjs";
|
|
@@ -7,7 +12,6 @@ import { Application } from "express";
|
|
|
7
12
|
import { Sequelize } from "sequelize-typescript";
|
|
8
13
|
|
|
9
14
|
//#region src/index.d.ts
|
|
10
|
-
|
|
11
15
|
/**
|
|
12
16
|
* Adding custom fields enrichment to the models inside the MODELS_FILE_NAME json file
|
|
13
17
|
* @see {@link 'custom-fields/config'} for configurations
|
|
@@ -15,5 +19,5 @@ import { Sequelize } from "sequelize-typescript";
|
|
|
15
19
|
declare const useCustomFields: (app: Pick<Application, "use"> | null, getModel: ModelFetcher, options: CustomFieldOptions) => Promise<Sequelize>;
|
|
16
20
|
declare const disableCustomFields: (models: Models[], getModel: ModelFetcher) => void;
|
|
17
21
|
//#endregion
|
|
18
|
-
export { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, CustomFieldsSchema, customFieldsSortScope, useCustomFields as default, disableCustomFields, generateCustomFieldSearchQueryPayload, generateRandomString, supportedEntities };
|
|
22
|
+
export { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinition, CustomFieldDefinitionType, CustomFieldEntries, CustomFieldValue, CustomFieldsSchema, CustomValidator, customFieldsSortScope, useCustomFields as default, disableCustomFields, generateCustomFieldSearchQueryPayload, generateRandomString, supportedEntities };
|
|
19
23
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, supportedEntities } from "./utils/constants/index.js";
|
|
2
|
+
import { CustomFieldValue } from "./models/CustomFieldValue.js";
|
|
3
|
+
import { CustomFieldEntries } from "./models/CustomFieldEntries.js";
|
|
4
|
+
import { CustomValidator } from "./models/CustomValidator.js";
|
|
5
|
+
import "./models/index.js";
|
|
6
|
+
import { CustomFieldDefinition } from "./models/CustomFieldDefinition.js";
|
|
2
7
|
import { CustomFieldOptions, ModelFetcher, Models } from "./types/index.js";
|
|
3
8
|
import { CustomFieldsSchema } from "./utils/validations/schema/custom-fields.js";
|
|
4
9
|
import { generateCustomFieldSearchQueryPayload, generateRandomString } from "./utils/helpers/index.js";
|
|
@@ -7,7 +12,6 @@ import { Sequelize } from "sequelize-typescript";
|
|
|
7
12
|
import { Application } from "express";
|
|
8
13
|
|
|
9
14
|
//#region src/index.d.ts
|
|
10
|
-
|
|
11
15
|
/**
|
|
12
16
|
* Adding custom fields enrichment to the models inside the MODELS_FILE_NAME json file
|
|
13
17
|
* @see {@link 'custom-fields/config'} for configurations
|
|
@@ -15,5 +19,5 @@ import { Application } from "express";
|
|
|
15
19
|
declare const useCustomFields: (app: Pick<Application, "use"> | null, getModel: ModelFetcher, options: CustomFieldOptions) => Promise<Sequelize>;
|
|
16
20
|
declare const disableCustomFields: (models: Models[], getModel: ModelFetcher) => void;
|
|
17
21
|
//#endregion
|
|
18
|
-
export { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, CustomFieldsSchema, customFieldsSortScope, useCustomFields as default, disableCustomFields, generateCustomFieldSearchQueryPayload, generateRandomString, supportedEntities };
|
|
22
|
+
export { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinition, CustomFieldDefinitionType, CustomFieldEntries, CustomFieldValue, CustomFieldsSchema, CustomValidator, customFieldsSortScope, useCustomFields as default, disableCustomFields, generateCustomFieldSearchQueryPayload, generateRandomString, supportedEntities };
|
|
19
23
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e,{tryAddingTraceIdMiddleware as t}from"./utils/logger/index.js";import{CUSTOM_FIELDS_FILTER_SCOPE as n,CustomFieldDefinitionType as r,supportedEntities as i}from"./utils/constants/index.js";import{initTables as
|
|
1
|
+
import e,{tryAddingTraceIdMiddleware as t}from"./utils/logger/index.js";import{CUSTOM_FIELDS_FILTER_SCOPE as n,CustomFieldDefinitionType as r,supportedEntities as i}from"./utils/constants/index.js";import a from"./models/CustomFieldDefinition.js";import o from"./models/CustomFieldValue.js";import s from"./models/CustomFieldEntries.js";import c from"./models/CustomValidator.js";import{initTables as l,initTestModels as u}from"./models/index.js";import d from"./api/index.js";import f from"./utils/db/index.js";import{generateCustomFieldSearchQueryPayload as p,generateRandomString as m}from"./utils/helpers/index.js";import{customFieldsSortScope as h}from"./scopes/filter.js";import{addHooks as g,addScopes as _,applyCustomAssociation as v,removeHooks as y}from"./utils/init.js";import{CustomFieldsSchema as b}from"./utils/validations/schema/custom-fields.js";var x=async(n,r,i)=>{t();let{models:a,useCustomFieldsEntries:o}=i;n&&n.use(`/api`,d);let s=i.sequelize??f(i.databaseConfig);return process.env.NODE_ENV===`test`&&await u(s),g(a,r,{useCustomFieldsEntries:o}),await l(s,i.getUser,{useCustomFieldsEntries:o}),_(a,r,{useCustomFieldsEntries:o}),v(a),e.debug(`sadot - custom fields finished initializing with models`,a),s};const S=(e,t)=>{y(e,t)};export{n as CUSTOM_FIELDS_FILTER_SCOPE,a as CustomFieldDefinition,r as CustomFieldDefinitionType,s as CustomFieldEntries,o as CustomFieldValue,b as CustomFieldsSchema,c as CustomValidator,h as customFieldsSortScope,x as default,S as disableCustomFields,p as generateCustomFieldSearchQueryPayload,m as generateRandomString,i as supportedEntities};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["api","initDB"],"sources":["../src/index.ts"],"sourcesContent":["import type { Application } from 'express';\nimport type { Sequelize } from 'sequelize-typescript';\nimport {\n initTables, initTestModels,\n} from './models';\nimport api from './api';\nimport initDB from './utils/db';\nimport logger, { tryAddingTraceIdMiddleware } from './utils/logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from './types';\nimport {\n addHooks, addScopes, applyCustomAssociation, removeHooks,\n} from './utils/init';\n\nexport * from './utils/validations/schema/custom-fields';\n\nexport * from './utils/constants';\n\nexport * from './utils/helpers';\n\nexport { customFieldsSortScope } from './scopes/filter';\n\n/**\n * Adding custom fields enrichment to the models inside the MODELS_FILE_NAME json file\n * @see {@link 'custom-fields/config'} for configurations\n */\nconst useCustomFields = async (\n app: Pick<Application, 'use'> | null,\n getModel: ModelFetcher,\n options: CustomFieldOptions,\n): Promise<Sequelize> => {\n tryAddingTraceIdMiddleware();\n const { models, useCustomFieldsEntries } = options;\n if (app) {\n app.use('/api', api);\n }\n const sequelize = options.sequelize ?? initDB(options.databaseConfig);\n if (process.env.NODE_ENV === 'test') {\n await initTestModels(sequelize);\n }\n // The order is important\n addHooks(models, getModel, { useCustomFieldsEntries });\n await initTables(sequelize, options.getUser, { useCustomFieldsEntries });\n addScopes(models, getModel, { useCustomFieldsEntries });\n applyCustomAssociation(models);\n\n logger.debug('sadot - custom fields finished initializing with models', models);\n return sequelize;\n};\n\nexport default useCustomFields;\n\nexport const disableCustomFields = (models: Models[], getModel: ModelFetcher): void => {\n removeHooks(models, getModel);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["api","initDB"],"sources":["../src/index.ts"],"sourcesContent":["import type { Application } from 'express';\nimport type { Sequelize } from 'sequelize-typescript';\nimport {\n initTables, initTestModels,\n} from './models';\nimport api from './api';\nimport initDB from './utils/db';\nimport logger, { tryAddingTraceIdMiddleware } from './utils/logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from './types';\nimport {\n addHooks, addScopes, applyCustomAssociation, removeHooks,\n} from './utils/init';\n\nexport * from './utils/validations/schema/custom-fields';\n\nexport * from './utils/constants';\n\nexport * from './utils/helpers';\n\nexport { customFieldsSortScope } from './scopes/filter';\nexport {\n CustomFieldDefinition,\n CustomFieldEntries,\n CustomFieldValue,\n CustomValidator,\n} from './models';\n\n/**\n * Adding custom fields enrichment to the models inside the MODELS_FILE_NAME json file\n * @see {@link 'custom-fields/config'} for configurations\n */\nconst useCustomFields = async (\n app: Pick<Application, 'use'> | null,\n getModel: ModelFetcher,\n options: CustomFieldOptions,\n): Promise<Sequelize> => {\n tryAddingTraceIdMiddleware();\n const { models, useCustomFieldsEntries } = options;\n if (app) {\n app.use('/api', api);\n }\n const sequelize = options.sequelize ?? initDB(options.databaseConfig);\n if (process.env.NODE_ENV === 'test') {\n await initTestModels(sequelize);\n }\n // The order is important\n addHooks(models, getModel, { useCustomFieldsEntries });\n await initTables(sequelize, options.getUser, { useCustomFieldsEntries });\n addScopes(models, getModel, { useCustomFieldsEntries });\n applyCustomAssociation(models);\n\n logger.debug('sadot - custom fields finished initializing with models', models);\n return sequelize;\n};\n\nexport default useCustomFields;\n\nexport const disableCustomFields = (models: Models[], getModel: ModelFetcher): void => {\n removeHooks(models, getModel);\n};\n"],"mappings":"81BAuDA,IAAA,EAxBwB,MACtB,EACA,EACA,IACuB,CACvB,GAA4B,CAC5B,GAAM,CAAE,SAAQ,0BAA2B,EACvC,GACF,EAAI,IAAI,OAAQA,EAAI,CAEtB,IAAM,EAAY,EAAQ,WAAaC,EAAO,EAAQ,eAAe,CAWrE,OAVI,QAAQ,IAAI,WAAa,QAC3B,MAAM,EAAe,EAAU,CAGjC,EAAS,EAAQ,EAAU,CAAE,yBAAwB,CAAC,CACtD,MAAM,EAAW,EAAW,EAAQ,QAAS,CAAE,yBAAwB,CAAC,CACxE,EAAU,EAAQ,EAAU,CAAE,yBAAwB,CAAC,CACvD,EAAuB,EAAO,CAE9B,EAAO,MAAM,0DAA2D,EAAO,CACxE,GAKT,MAAa,GAAuB,EAAkB,IAAiC,CACrF,EAAY,EAAQ,EAAS"}
|
|
@@ -1,2 +1,31 @@
|
|
|
1
|
-
import "../utils/constants/index.cjs";
|
|
2
|
-
import "./
|
|
1
|
+
import { CustomFieldDefinitionType } from "../utils/constants/index.cjs";
|
|
2
|
+
import { CustomFieldValue } from "./CustomFieldValue.cjs";
|
|
3
|
+
import "./index.cjs";
|
|
4
|
+
import { Model } from "sequelize-typescript";
|
|
5
|
+
import { CreateOptions } from "sequelize";
|
|
6
|
+
|
|
7
|
+
//#region src/models/CustomFieldDefinition.d.ts
|
|
8
|
+
declare class CustomFieldDefinition extends Model {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
displayName?: string;
|
|
12
|
+
fieldType: CustomFieldDefinitionType;
|
|
13
|
+
validation?: any;
|
|
14
|
+
entityId: string;
|
|
15
|
+
entityType: string;
|
|
16
|
+
modelType: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
required?: boolean;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
defaultValue?: any;
|
|
21
|
+
createdAt?: Date;
|
|
22
|
+
updatedAt?: Date;
|
|
23
|
+
deletedAt?: Date;
|
|
24
|
+
blockEditingFromUI: boolean;
|
|
25
|
+
values: CustomFieldValue[];
|
|
26
|
+
static displayNameDefaultValue(instance: CustomFieldDefinition): void;
|
|
27
|
+
static afterSaveHandler(instance: CustomFieldDefinition, options: CreateOptions): void;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { CustomFieldDefinition };
|
|
31
|
+
//# sourceMappingURL=CustomFieldDefinition.d.cts.map
|
|
@@ -1,4 +1,31 @@
|
|
|
1
|
-
import "../utils/constants/index.js";
|
|
1
|
+
import { CustomFieldDefinitionType } from "../utils/constants/index.js";
|
|
2
|
+
import { CustomFieldValue } from "./CustomFieldValue.js";
|
|
2
3
|
import "./index.js";
|
|
3
|
-
import "sequelize";
|
|
4
|
-
import { Model } from "sequelize-typescript";
|
|
4
|
+
import { CreateOptions } from "sequelize";
|
|
5
|
+
import { Model } from "sequelize-typescript";
|
|
6
|
+
|
|
7
|
+
//#region src/models/CustomFieldDefinition.d.ts
|
|
8
|
+
declare class CustomFieldDefinition extends Model {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
displayName?: string;
|
|
12
|
+
fieldType: CustomFieldDefinitionType;
|
|
13
|
+
validation?: any;
|
|
14
|
+
entityId: string;
|
|
15
|
+
entityType: string;
|
|
16
|
+
modelType: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
required?: boolean;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
defaultValue?: any;
|
|
21
|
+
createdAt?: Date;
|
|
22
|
+
updatedAt?: Date;
|
|
23
|
+
deletedAt?: Date;
|
|
24
|
+
blockEditingFromUI: boolean;
|
|
25
|
+
values: CustomFieldValue[];
|
|
26
|
+
static displayNameDefaultValue(instance: CustomFieldDefinition): void;
|
|
27
|
+
static afterSaveHandler(instance: CustomFieldDefinition, options: CreateOptions): void;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { CustomFieldDefinition };
|
|
31
|
+
//# sourceMappingURL=CustomFieldDefinition.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Model } from "sequelize-typescript";
|
|
2
|
+
import { CreateOptions } from "sequelize";
|
|
3
|
+
|
|
4
|
+
//#region src/models/CustomFieldEntries.d.ts
|
|
5
|
+
declare class CustomFieldEntries extends Model {
|
|
6
|
+
modelId: string;
|
|
7
|
+
entityId: string;
|
|
8
|
+
customFields: Record<string, any>;
|
|
9
|
+
modelType: string;
|
|
10
|
+
createdAt?: Date;
|
|
11
|
+
updatedAt?: Date;
|
|
12
|
+
static afterSaveHandler(instance: CustomFieldEntries[], options: CreateOptions): void;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { CustomFieldEntries };
|
|
16
|
+
//# sourceMappingURL=CustomFieldEntries.d.cts.map
|
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
import "sequelize";
|
|
2
|
-
import { Model } from "sequelize-typescript";
|
|
1
|
+
import { CreateOptions } from "sequelize";
|
|
2
|
+
import { Model } from "sequelize-typescript";
|
|
3
|
+
|
|
4
|
+
//#region src/models/CustomFieldEntries.d.ts
|
|
5
|
+
declare class CustomFieldEntries extends Model {
|
|
6
|
+
modelId: string;
|
|
7
|
+
entityId: string;
|
|
8
|
+
customFields: Record<string, any>;
|
|
9
|
+
modelType: string;
|
|
10
|
+
createdAt?: Date;
|
|
11
|
+
updatedAt?: Date;
|
|
12
|
+
static afterSaveHandler(instance: CustomFieldEntries[], options: CreateOptions): void;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { CustomFieldEntries };
|
|
16
|
+
//# sourceMappingURL=CustomFieldEntries.d.ts.map
|
|
@@ -1 +1,22 @@
|
|
|
1
|
-
import "./index.cjs";
|
|
1
|
+
import "./index.cjs";
|
|
2
|
+
import { CustomFieldDefinition } from "./CustomFieldDefinition.cjs";
|
|
3
|
+
import { Model } from "sequelize-typescript";
|
|
4
|
+
import { CreateOptions } from "sequelize";
|
|
5
|
+
|
|
6
|
+
//#region src/models/CustomFieldValue.d.ts
|
|
7
|
+
declare class CustomFieldValue extends Model {
|
|
8
|
+
modelId: string;
|
|
9
|
+
customFieldDefinitionId: string;
|
|
10
|
+
value: any;
|
|
11
|
+
createdAt?: Date;
|
|
12
|
+
updatedAt?: Date;
|
|
13
|
+
deletedAt?: Date;
|
|
14
|
+
customFieldDefinition: CustomFieldDefinition;
|
|
15
|
+
private static validateValueAgainstDefinition;
|
|
16
|
+
static validateCustomFieldValues(instances: CustomFieldValue[]): Promise<void>;
|
|
17
|
+
static validateCustomFieldValue(instance: CustomFieldValue): Promise<void>;
|
|
18
|
+
static afterSaveHandler(instance: CustomFieldValue[], options: CreateOptions): void;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { CustomFieldValue };
|
|
22
|
+
//# sourceMappingURL=CustomFieldValue.d.cts.map
|
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
import "./index.js";
|
|
2
|
-
import "
|
|
3
|
-
import {
|
|
2
|
+
import { CustomFieldDefinition } from "./CustomFieldDefinition.js";
|
|
3
|
+
import { CreateOptions } from "sequelize";
|
|
4
|
+
import { Model } from "sequelize-typescript";
|
|
5
|
+
|
|
6
|
+
//#region src/models/CustomFieldValue.d.ts
|
|
7
|
+
declare class CustomFieldValue extends Model {
|
|
8
|
+
modelId: string;
|
|
9
|
+
customFieldDefinitionId: string;
|
|
10
|
+
value: any;
|
|
11
|
+
createdAt?: Date;
|
|
12
|
+
updatedAt?: Date;
|
|
13
|
+
deletedAt?: Date;
|
|
14
|
+
customFieldDefinition: CustomFieldDefinition;
|
|
15
|
+
private static validateValueAgainstDefinition;
|
|
16
|
+
static validateCustomFieldValues(instances: CustomFieldValue[]): Promise<void>;
|
|
17
|
+
static validateCustomFieldValue(instance: CustomFieldValue): Promise<void>;
|
|
18
|
+
static afterSaveHandler(instance: CustomFieldValue[], options: CreateOptions): void;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { CustomFieldValue };
|
|
22
|
+
//# sourceMappingURL=CustomFieldValue.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SchemaObject } from "../api/v1/validator/validations.cjs";
|
|
2
|
+
import { Model } from "sequelize-typescript";
|
|
3
|
+
import { CreateOptions } from "sequelize";
|
|
4
|
+
|
|
5
|
+
//#region src/models/CustomValidator.d.ts
|
|
6
|
+
declare class CustomValidator extends Model {
|
|
7
|
+
id: string;
|
|
8
|
+
entityId: string;
|
|
9
|
+
entityType: string;
|
|
10
|
+
modelType: string;
|
|
11
|
+
schema: SchemaObject;
|
|
12
|
+
disabled: boolean;
|
|
13
|
+
createdAt?: Date;
|
|
14
|
+
updatedAt?: Date;
|
|
15
|
+
static afterSaveHandler(instance: CustomValidator, options: CreateOptions): void;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { CustomValidator };
|
|
19
|
+
//# sourceMappingURL=CustomValidator.d.cts.map
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
import "../api/v1/validator/validations.js";
|
|
2
|
-
import "sequelize";
|
|
3
|
-
import { Model } from "sequelize-typescript";
|
|
1
|
+
import { SchemaObject } from "../api/v1/validator/validations.js";
|
|
2
|
+
import { CreateOptions } from "sequelize";
|
|
3
|
+
import { Model } from "sequelize-typescript";
|
|
4
|
+
|
|
5
|
+
//#region src/models/CustomValidator.d.ts
|
|
6
|
+
declare class CustomValidator extends Model {
|
|
7
|
+
id: string;
|
|
8
|
+
entityId: string;
|
|
9
|
+
entityType: string;
|
|
10
|
+
modelType: string;
|
|
11
|
+
schema: SchemaObject;
|
|
12
|
+
disabled: boolean;
|
|
13
|
+
createdAt?: Date;
|
|
14
|
+
updatedAt?: Date;
|
|
15
|
+
static afterSaveHandler(instance: CustomValidator, options: CreateOptions): void;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { CustomValidator };
|
|
19
|
+
//# sourceMappingURL=CustomValidator.d.ts.map
|
package/dist/models/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/logger/index.cjs`),n=require(`./CustomFieldDefinition.cjs`),r=require(`./CustomFieldValue.cjs`),i=require(`./tests/AssociatedTestModel.cjs`),a=require(`./tests/TestModel.cjs`),o=require(`./tests/contextAwareModels/ContextTestModel.cjs`),s=require(`./tests/contextAwareModels/ContextAwareTestModel.cjs`),c=require(`./CustomFieldEntries.cjs`),l=require(`./CustomValidator.cjs`);let u=require(`sequelize`);const d=[
|
|
1
|
+
const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/logger/index.cjs`),n=require(`./CustomFieldDefinition.cjs`),r=require(`./CustomFieldValue.cjs`),i=require(`./tests/AssociatedTestModel.cjs`),a=require(`./tests/TestModel.cjs`),o=require(`./tests/contextAwareModels/ContextTestModel.cjs`),s=require(`./tests/contextAwareModels/ContextAwareTestModel.cjs`),c=require(`./CustomFieldEntries.cjs`),l=require(`./CustomValidator.cjs`);let u=require(`sequelize`);const d=[a.default,i.default,s.default,o.default],f=`sadot-migration`,p=`49c9dd1d-b1cc-445b-a911-fd349d783110`,m=async(e,i,{schemaPrefix:a=`sadot-migration`,schemaVersion:o=`49c9dd1d-b1cc-445b-a911-fd349d783110`,useCustomFieldsEntries:s=!1}={})=>{let d=`${a}_${o}${s?`_withEntries`:``}`;if(t.default.info(`custom-fields: initialize custom-fields tables`),!e.addModels)throw Error(`sequelize instance must have addModels function`);let f=[n.default,r.default,l.default,...s?[c.default]:[]];e.addModels(f),n.default.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),l.default.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),t.default.info(`custom-fields: models added`);let p=e.define(`SequelizeMeta`,{name:{type:u.DataTypes.STRING,allowNull:!1,unique:!0,primaryKey:!0,autoIncrement:!1}},{tableName:`SequelizeMeta`,timestamps:!1,schema:`public`});t.default.info(`custom-fields: starting migrations`);let m=await p.findAll({where:{name:{[u.Op.like]:`${a}%`}},raw:!0}),h=m.at(-1),g=m.findIndex(e=>e.name===d);if(t.default.info(`custom-fields: migrations`,{migrations:m,currentSadotSchemaVersion:h,expectedSchemaVersionIndex:g}),(!h||h.name!==d)&&(t.default.info(`custom-fields: syncing models`),await n.default.sync({alter:!0}),await r.default.sync({alter:!0}),s&&await c.default.sync({alter:!0}),await l.default.sync({alter:!0}),g===-1&&await p.create({name:d}),t.default.info(`custom-fields: models synced`),m.length&&g!==-1&&g<m.length-1)){let e=m.slice(g+1);await p.destroy({where:{name:{[u.Op.in]:e.map(e=>e.name)}}})}},h=async e=>{if(t.default.info(`custom-fields: initialize custom-fields test models`),!e.addModels)throw Error(`sequelize instance must have addModels function`);e.addModels(d),await e.dropSchema(`custom-fields`,{logging:!1}),await e.createSchema(`custom-fields`,{logging:!1}),t.default.info(`custom-fields: test models added`),await a.default.sync({alter:!0}),await i.default.sync({alter:!0}),await o.default.sync({alter:!0}),await s.default.sync({alter:!0}),t.default.info(`custom-fields: test models synced`)};exports.initTables=m,exports.initTestModels=h;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["TestModel","AssociatedTestModel","ContextAwareTestModel","ContextTestModel","sequelize","productionModels: ProductionModel[]","CustomFieldDefinition","CustomFieldValue","CustomValidator","CustomFieldEntries","DataTypes","Op"],"sources":["../../src/models/index.ts"],"sourcesContent":["import { DataTypes, Op } from 'sequelize';\nimport type { Sequelize } from 'sequelize-typescript';\nimport logger from '../utils/logger';\nimport CustomFieldDefinition from './CustomFieldDefinition';\nimport CustomFieldValue from './CustomFieldValue';\nimport TestModel from './tests/TestModel';\nimport ContextAwareTestModel from './tests/contextAwareModels/ContextAwareTestModel';\nimport ContextTestModel from './tests/contextAwareModels/ContextTestModel';\nimport AssociatedTestModel from './tests/AssociatedTestModel';\nimport type { CustomFieldOptions } from '../types';\nimport CustomFieldEntries from './CustomFieldEntries';\nimport CustomValidator from './CustomValidator';\n\ntype ProductionModel = typeof CustomFieldDefinition | typeof CustomFieldValue | typeof CustomFieldEntries | typeof CustomValidator;\ninterface InitTablesOptions {\n schemaPrefix?: string;\n schemaVersion?: string;\n useCustomFieldsEntries?: boolean;\n}\n\nconst testModels = [TestModel, AssociatedTestModel, ContextAwareTestModel, ContextTestModel];\n\nconst SADOT_MIGRATION_PREFIX = 'sadot-migration';\nconst SCHEMA_VERSION = '49c9dd1d-b1cc-445b-a911-fd349d783110';\n\nconst initTables = async (\n sequelize: Sequelize,\n getUser: CustomFieldOptions['getUser'],\n {\n schemaPrefix = SADOT_MIGRATION_PREFIX,\n schemaVersion = SCHEMA_VERSION,\n useCustomFieldsEntries = false,\n }: InitTablesOptions = {},\n): Promise<void> => {\n const CUSTOM_FIELDS_SCHEMA_VERSION = `${schemaPrefix}_${schemaVersion}${useCustomFieldsEntries ? '_withEntries' : ''}`;\n logger.info('custom-fields: initialize custom-fields tables');\n // Detect models and import them to the orm\n if (!sequelize.addModels) {\n throw new Error('sequelize instance must have addModels function');\n }\n const productionModels: ProductionModel[] = [\n CustomFieldDefinition,\n CustomFieldValue,\n CustomValidator,\n ...(useCustomFieldsEntries ? [CustomFieldEntries] : []),\n ];\n\n sequelize.addModels(productionModels);\n\n CustomFieldDefinition.addScope('userScope', () => {\n const user = getUser();\n if (!user?.permissions) {\n return {};\n }\n return {\n where: {\n entityId: [\n ...Object.keys(user.permissions.fleets),\n ...Object.keys(user.permissions.businessModels),\n ...Object.keys(user.permissions.demandSources),\n ],\n },\n };\n });\n\n CustomValidator.addScope('userScope', () => {\n const user = getUser();\n if (!user?.permissions) {\n return {};\n }\n return {\n where: {\n entityId: [\n ...Object.keys(user.permissions.fleets),\n ...Object.keys(user.permissions.businessModels),\n ...Object.keys(user.permissions.demandSources),\n ],\n },\n };\n });\n\n logger.info('custom-fields: models added');\n\n const SequelizeMeta = sequelize.define(\n 'SequelizeMeta',\n {\n name: {\n type: DataTypes.STRING,\n allowNull: false,\n unique: true,\n primaryKey: true,\n autoIncrement: false,\n },\n },\n {\n tableName: 'SequelizeMeta',\n timestamps: false,\n schema: 'public',\n },\n );\n\n logger.info('custom-fields: starting migrations');\n const migrations = await SequelizeMeta.findAll({ where: { name: { [Op.like]: `${schemaPrefix}%` } }, raw: true });\n const currentSadotSchemaVersion = migrations.at(-1);\n const expectedSchemaVersionIndex = migrations.findIndex(m => (m as any).name === CUSTOM_FIELDS_SCHEMA_VERSION);\n\n logger.info('custom-fields: migrations', { migrations, currentSadotSchemaVersion, expectedSchemaVersionIndex });\n if (!currentSadotSchemaVersion || (currentSadotSchemaVersion as any).name !== CUSTOM_FIELDS_SCHEMA_VERSION) {\n logger.info('custom-fields: syncing models');\n await CustomFieldDefinition.sync({ alter: true });\n await CustomFieldValue.sync({ alter: true });\n // T.Y TODO: Remove the if statement once we're ready to add the new entries table for all MS\n if (useCustomFieldsEntries) {\n await CustomFieldEntries.sync({ alter: true });\n }\n\n // Always sync CustomValidator\n await CustomValidator.sync({ alter: true });\n\n if (expectedSchemaVersionIndex === -1) {\n await SequelizeMeta.create({ name: CUSTOM_FIELDS_SCHEMA_VERSION });\n }\n logger.info('custom-fields: models synced');\n if (migrations.length && expectedSchemaVersionIndex !== -1 && expectedSchemaVersionIndex < migrations.length - 1) {\n // We have existing migrations, and we are calling `sync`.\n // This means we are in a `down` migration, and hence we should delete newer migrations to ensure we can reapply them.\n const migrationsToDelete = migrations.slice(expectedSchemaVersionIndex + 1);\n await SequelizeMeta.destroy({ where: { name: { [Op.in]: migrationsToDelete.map(m => (m as any).name) } } });\n }\n }\n};\n\nconst initTestModels = async (sequelize: Sequelize): Promise<void> => {\n logger.info('custom-fields: initialize custom-fields test models');\n // Detect models and import them to the orm\n if (!sequelize.addModels) {\n throw new Error('sequelize instance must have addModels function');\n }\n\n sequelize.addModels(testModels);\n await sequelize.dropSchema('custom-fields', { logging: false });\n await sequelize.createSchema('custom-fields', { logging: false });\n\n logger.info('custom-fields: test models added');\n await TestModel.sync({ alter: true });\n await AssociatedTestModel.sync({ alter: true });\n await ContextTestModel.sync({ alter: true });\n await ContextAwareTestModel.sync({ alter: true });\n logger.info('custom-fields: test models synced');\n};\n\nexport {\n CustomFieldValue,\n CustomFieldDefinition,\n CustomFieldEntries,\n CustomValidator,\n TestModel,\n AssociatedTestModel,\n ContextAwareTestModel,\n ContextTestModel,\n initTables,\n initTestModels,\n};\n"],"mappings":"2dAoBA,MAAM,EAAa,CAACA,EAAAA,QAAWC,EAAAA,QAAqBC,EAAAA,QAAuBC,EAAAA,QAAiB,CAEtF,EAAyB,kBACzB,EAAiB,uCAEjB,EAAa,MACjB,EACA,EACA,CACE,eAAe,kBACf,gBAAgB,uCAChB,yBAAyB,IACJ,EAAE,GACP,CAClB,IAAM,EAA+B,GAAG,EAAa,GAAG,IAAgB,EAAyB,eAAiB,KAGlH,GAFA,EAAA,QAA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K,oCAAoC"}
|
package/dist/models/index.d.cts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import "./CustomFieldValue.cjs";
|
|
2
|
-
import "./
|
|
1
|
+
import { CustomFieldValue } from "./CustomFieldValue.cjs";
|
|
2
|
+
import { CustomFieldEntries } from "./CustomFieldEntries.cjs";
|
|
3
|
+
import { CustomValidator } from "./CustomValidator.cjs";
|
|
4
|
+
import { CustomFieldDefinition } from "./CustomFieldDefinition.cjs";
|
|
3
5
|
import "../types/index.cjs";
|
|
4
6
|
import { Sequelize } from "sequelize-typescript";
|
package/dist/models/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./CustomFieldValue.js";
|
|
2
|
-
import "./CustomFieldEntries.js";
|
|
3
|
-
import "./CustomValidator.js";
|
|
4
|
-
import "./CustomFieldDefinition.js";
|
|
1
|
+
import { CustomFieldValue } from "./CustomFieldValue.js";
|
|
2
|
+
import { CustomFieldEntries } from "./CustomFieldEntries.js";
|
|
3
|
+
import { CustomValidator } from "./CustomValidator.js";
|
|
4
|
+
import { CustomFieldDefinition } from "./CustomFieldDefinition.js";
|
|
5
5
|
import "../types/index.js";
|
|
6
6
|
import { Sequelize } from "sequelize-typescript";
|
package/dist/models/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"../utils/logger/index.js";import t from"./CustomFieldDefinition.js";import n from"./CustomFieldValue.js";import r from"./tests/AssociatedTestModel.js";import i from"./tests/TestModel.js";import a from"./tests/contextAwareModels/ContextTestModel.js";import o from"./tests/contextAwareModels/ContextAwareTestModel.js";import s from"./CustomFieldEntries.js";import c from"./CustomValidator.js";import{DataTypes as l,Op as u}from"sequelize";const d=[
|
|
1
|
+
import e from"../utils/logger/index.js";import t from"./CustomFieldDefinition.js";import n from"./CustomFieldValue.js";import r from"./tests/AssociatedTestModel.js";import i from"./tests/TestModel.js";import a from"./tests/contextAwareModels/ContextTestModel.js";import o from"./tests/contextAwareModels/ContextAwareTestModel.js";import s from"./CustomFieldEntries.js";import c from"./CustomValidator.js";import{DataTypes as l,Op as u}from"sequelize";const d=[i,r,o,a],f=async(r,i,{schemaPrefix:a=`sadot-migration`,schemaVersion:o=`49c9dd1d-b1cc-445b-a911-fd349d783110`,useCustomFieldsEntries:d=!1}={})=>{let f=`${a}_${o}${d?`_withEntries`:``}`;if(e.info(`custom-fields: initialize custom-fields tables`),!r.addModels)throw Error(`sequelize instance must have addModels function`);let p=[t,n,c,...d?[s]:[]];r.addModels(p),t.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),c.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),e.info(`custom-fields: models added`);let m=r.define(`SequelizeMeta`,{name:{type:l.STRING,allowNull:!1,unique:!0,primaryKey:!0,autoIncrement:!1}},{tableName:`SequelizeMeta`,timestamps:!1,schema:`public`});e.info(`custom-fields: starting migrations`);let h=await m.findAll({where:{name:{[u.like]:`${a}%`}},raw:!0}),g=h.at(-1),_=h.findIndex(e=>e.name===f);if(e.info(`custom-fields: migrations`,{migrations:h,currentSadotSchemaVersion:g,expectedSchemaVersionIndex:_}),(!g||g.name!==f)&&(e.info(`custom-fields: syncing models`),await t.sync({alter:!0}),await n.sync({alter:!0}),d&&await s.sync({alter:!0}),await c.sync({alter:!0}),_===-1&&await m.create({name:f}),e.info(`custom-fields: models synced`),h.length&&_!==-1&&_<h.length-1)){let e=h.slice(_+1);await m.destroy({where:{name:{[u.in]:e.map(e=>e.name)}}})}},p=async t=>{if(e.info(`custom-fields: initialize custom-fields test models`),!t.addModels)throw Error(`sequelize instance must have addModels function`);t.addModels(d),await t.dropSchema(`custom-fields`,{logging:!1}),await t.createSchema(`custom-fields`,{logging:!1}),e.info(`custom-fields: test models added`),await i.sync({alter:!0}),await r.sync({alter:!0}),await a.sync({alter:!0}),await o.sync({alter:!0}),e.info(`custom-fields: test models synced`)};export{f as initTables,p as initTestModels};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/models/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["TestModel","AssociatedTestModel","ContextAwareTestModel","ContextTestModel","productionModels: ProductionModel[]","CustomFieldDefinition","CustomFieldValue","CustomValidator","CustomFieldEntries"],"sources":["../../src/models/index.ts"],"sourcesContent":["import { DataTypes, Op } from 'sequelize';\nimport type { Sequelize } from 'sequelize-typescript';\nimport logger from '../utils/logger';\nimport CustomFieldDefinition from './CustomFieldDefinition';\nimport CustomFieldValue from './CustomFieldValue';\nimport TestModel from './tests/TestModel';\nimport ContextAwareTestModel from './tests/contextAwareModels/ContextAwareTestModel';\nimport ContextTestModel from './tests/contextAwareModels/ContextTestModel';\nimport AssociatedTestModel from './tests/AssociatedTestModel';\nimport type { CustomFieldOptions } from '../types';\nimport CustomFieldEntries from './CustomFieldEntries';\nimport CustomValidator from './CustomValidator';\n\ntype ProductionModel = typeof CustomFieldDefinition | typeof CustomFieldValue | typeof CustomFieldEntries | typeof CustomValidator;\ninterface InitTablesOptions {\n schemaPrefix?: string;\n schemaVersion?: string;\n useCustomFieldsEntries?: boolean;\n}\n\nconst testModels = [TestModel, AssociatedTestModel, ContextAwareTestModel, ContextTestModel];\n\nconst SADOT_MIGRATION_PREFIX = 'sadot-migration';\nconst SCHEMA_VERSION = '49c9dd1d-b1cc-445b-a911-fd349d783110';\n\nconst initTables = async (\n sequelize: Sequelize,\n getUser: CustomFieldOptions['getUser'],\n {\n schemaPrefix = SADOT_MIGRATION_PREFIX,\n schemaVersion = SCHEMA_VERSION,\n useCustomFieldsEntries = false,\n }: InitTablesOptions = {},\n): Promise<void> => {\n const CUSTOM_FIELDS_SCHEMA_VERSION = `${schemaPrefix}_${schemaVersion}${useCustomFieldsEntries ? '_withEntries' : ''}`;\n logger.info('custom-fields: initialize custom-fields tables');\n // Detect models and import them to the orm\n if (!sequelize.addModels) {\n throw new Error('sequelize instance must have addModels function');\n }\n const productionModels: ProductionModel[] = [\n CustomFieldDefinition,\n CustomFieldValue,\n CustomValidator,\n ...(useCustomFieldsEntries ? [CustomFieldEntries] : []),\n ];\n\n sequelize.addModels(productionModels);\n\n CustomFieldDefinition.addScope('userScope', () => {\n const user = getUser();\n if (!user?.permissions) {\n return {};\n }\n return {\n where: {\n entityId: [\n ...Object.keys(user.permissions.fleets),\n ...Object.keys(user.permissions.businessModels),\n ...Object.keys(user.permissions.demandSources),\n ],\n },\n };\n });\n\n CustomValidator.addScope('userScope', () => {\n const user = getUser();\n if (!user?.permissions) {\n return {};\n }\n return {\n where: {\n entityId: [\n ...Object.keys(user.permissions.fleets),\n ...Object.keys(user.permissions.businessModels),\n ...Object.keys(user.permissions.demandSources),\n ],\n },\n };\n });\n\n logger.info('custom-fields: models added');\n\n const SequelizeMeta = sequelize.define(\n 'SequelizeMeta',\n {\n name: {\n type: DataTypes.STRING,\n allowNull: false,\n unique: true,\n primaryKey: true,\n autoIncrement: false,\n },\n },\n {\n tableName: 'SequelizeMeta',\n timestamps: false,\n schema: 'public',\n },\n );\n\n logger.info('custom-fields: starting migrations');\n const migrations = await SequelizeMeta.findAll({ where: { name: { [Op.like]: `${schemaPrefix}%` } }, raw: true });\n const currentSadotSchemaVersion = migrations.at(-1);\n const expectedSchemaVersionIndex = migrations.findIndex(m => (m as any).name === CUSTOM_FIELDS_SCHEMA_VERSION);\n\n logger.info('custom-fields: migrations', { migrations, currentSadotSchemaVersion, expectedSchemaVersionIndex });\n if (!currentSadotSchemaVersion || (currentSadotSchemaVersion as any).name !== CUSTOM_FIELDS_SCHEMA_VERSION) {\n logger.info('custom-fields: syncing models');\n await CustomFieldDefinition.sync({ alter: true });\n await CustomFieldValue.sync({ alter: true });\n // T.Y TODO: Remove the if statement once we're ready to add the new entries table for all MS\n if (useCustomFieldsEntries) {\n await CustomFieldEntries.sync({ alter: true });\n }\n\n // Always sync CustomValidator\n await CustomValidator.sync({ alter: true });\n\n if (expectedSchemaVersionIndex === -1) {\n await SequelizeMeta.create({ name: CUSTOM_FIELDS_SCHEMA_VERSION });\n }\n logger.info('custom-fields: models synced');\n if (migrations.length && expectedSchemaVersionIndex !== -1 && expectedSchemaVersionIndex < migrations.length - 1) {\n // We have existing migrations, and we are calling `sync`.\n // This means we are in a `down` migration, and hence we should delete newer migrations to ensure we can reapply them.\n const migrationsToDelete = migrations.slice(expectedSchemaVersionIndex + 1);\n await SequelizeMeta.destroy({ where: { name: { [Op.in]: migrationsToDelete.map(m => (m as any).name) } } });\n }\n }\n};\n\nconst initTestModels = async (sequelize: Sequelize): Promise<void> => {\n logger.info('custom-fields: initialize custom-fields test models');\n // Detect models and import them to the orm\n if (!sequelize.addModels) {\n throw new Error('sequelize instance must have addModels function');\n }\n\n sequelize.addModels(testModels);\n await sequelize.dropSchema('custom-fields', { logging: false });\n await sequelize.createSchema('custom-fields', { logging: false });\n\n logger.info('custom-fields: test models added');\n await TestModel.sync({ alter: true });\n await AssociatedTestModel.sync({ alter: true });\n await ContextTestModel.sync({ alter: true });\n await ContextAwareTestModel.sync({ alter: true });\n logger.info('custom-fields: test models synced');\n};\n\nexport {\n CustomFieldValue,\n CustomFieldDefinition,\n CustomFieldEntries,\n CustomValidator,\n TestModel,\n AssociatedTestModel,\n ContextAwareTestModel,\n ContextTestModel,\n initTables,\n initTestModels,\n};\n"],"mappings":"mcAoBA,MAAM,EAAa,CAACA,EAAWC,EAAqBC,EAAuBC,EAAiB,CAKtF,EAAa,MACjB,EACA,EACA,CACE,eAAe,kBACf,gBAAgB,uCAChB,yBAAyB,IACJ,EAAE,GACP,CAClB,IAAM,EAA+B,GAAG,EAAa,GAAG,IAAgB,EAAyB,eAAiB,KAGlH,GAFA,EAAO,KAAK,iDAAiD,CAEz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