New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@spinajs/intl-orm

Package Overview
Dependencies
Maintainers
1
Versions
304
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spinajs/intl-orm - npm Package Compare versions

Comparing version 2.0.46 to 2.0.48

lib/decorators.d.ts.map

1

lib/decorators.d.ts
export declare function Translate(): any;
//# sourceMappingURL=decorators.d.ts.map

10

lib/decorators.js

@@ -1,7 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Translate = void 0;
const orm_1 = require("@spinajs/orm");
function Translate() {
return (0, orm_1.extractDecoratorDescriptor)((model, _target, propertyKey) => {
import { extractDecoratorDescriptor } from '@spinajs/orm';
export function Translate() {
return extractDecoratorDescriptor((model, _target, propertyKey) => {
const columnDesc = model.Columns.find((c) => c.Name === propertyKey);

@@ -18,3 +15,2 @@ if (!columnDesc) {

}
exports.Translate = Translate;
//# sourceMappingURL=decorators.js.map
import { IModelDescriptor, ModelBase, Orm, OrmRelation, SelectQueryBuilder, QueryBuilder, QueryMiddleware, IBuilderMiddleware, IOrmRelation } from '@spinajs/orm';
import { TranslationSource } from '@spinajs/intl';
export * from './decorators';
export * from './model';
export * from './migrations/IntlOrm_2022_06_28_01_13_00';
export * from './models/IntlResource';
export * from './models/IntlTranslation';
export * from './decorators.js';
export * from './migrations/IntlOrm_2022_06_28_01_13_00.js';
export * from './models/IntlResource.js';
export * from './models/IntlTranslation.js';
declare module '@spinajs/orm' {

@@ -43,1 +42,2 @@ interface SelectQueryBuilder<T> {

}
//# sourceMappingURL=index.d.ts.map

@@ -1,13 +0,1 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

@@ -19,32 +7,23 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

};
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DbTranslationSource = exports.IntlQueryMiddleware = exports.IntlModelMiddleware = exports.IntlModelRelation = void 0;
const di_1 = require("@spinajs/di");
const orm_1 = require("@spinajs/orm");
const intl_1 = require("@spinajs/intl");
const lodash_1 = __importDefault(require("lodash"));
const IntlTranslation_1 = require("./models/IntlTranslation");
const IntlResource_1 = require("./models/IntlResource");
__exportStar(require("./decorators"), exports);
__exportStar(require("./model"), exports);
__exportStar(require("./migrations/IntlOrm_2022_06_28_01_13_00"), exports);
__exportStar(require("./models/IntlResource"), exports);
__exportStar(require("./models/IntlTranslation"), exports);
import { Injectable, NewInstance } from '@spinajs/di';
import { extractModelDescriptor, Orm, OrmRelation, RelationType, SelectQueryBuilder, QueryMiddleware, BelongsToRelation } from '@spinajs/orm';
import { TranslationSource, guessLanguage, defaultLanguage } from '@spinajs/intl';
import _ from 'lodash';
import { IntlTranslation } from './models/IntlTranslation.js';
import { IntlResource } from './models/IntlResource.js';
export * from './decorators.js';
export * from './migrations/IntlOrm_2022_06_28_01_13_00.js';
export * from './models/IntlResource.js';
export * from './models/IntlTranslation.js';
const { SelectQueryBuilder: SQB } = require('@spinajs/orm');
let IntlModelRelation = class IntlModelRelation extends orm_1.OrmRelation {
let IntlModelRelation = class IntlModelRelation extends OrmRelation {
constructor(_lang, _orm, _query, _mDescriptor, _parentRelation) {
super(_orm, _query, {
TargetModel: IntlResource_1.IntlResource,
TargetModelType: IntlResource_1.IntlResource,
TargetModel: IntlResource,
TargetModelType: IntlResource,
Name: 'Translations',
Type: orm_1.RelationType.Many,
Type: RelationType.Many,
SourceModel: null,

@@ -67,7 +46,7 @@ ForeignKey: '',

IntlModelRelation = __decorate([
(0, di_1.NewInstance)(),
__metadata("design:paramtypes", [String, orm_1.Orm, Object, Object, orm_1.OrmRelation])
NewInstance(),
__metadata("design:paramtypes", [String, Orm, SelectQueryBuilder, Object, OrmRelation])
], IntlModelRelation);
exports.IntlModelRelation = IntlModelRelation;
class IntlModelMiddleware {
export { IntlModelRelation };
export class IntlModelMiddleware {
constructor(_lang, _relationQuery, _description, _owner) {

@@ -105,3 +84,3 @@ this._lang = _lang;

relData.forEach((rd) => {
if (self._owner && self._owner instanceof orm_1.BelongsToRelation) {
if (self._owner && self._owner instanceof BelongsToRelation) {
let val = d;

@@ -139,3 +118,2 @@ let rel = self._owner;

}
exports.IntlModelMiddleware = IntlModelMiddleware;
SQB.prototype['translate'] = function (lang) {

@@ -149,4 +127,4 @@ /**

this.translated = true;
const descriptor = (0, orm_1.extractModelDescriptor)(this._model);
const relInstance = this._container.resolve(IntlModelRelation, [lang, this._container.get(orm_1.Orm), this, descriptor, this._owner]);
const descriptor = extractModelDescriptor(this._model);
const relInstance = this._container.resolve(IntlModelRelation, [lang, this._container.get(Orm), this, descriptor, this._owner]);
relInstance.execute();

@@ -162,7 +140,7 @@ // translate all other relations automatically

};
let IntlQueryMiddleware = class IntlQueryMiddleware extends orm_1.QueryMiddleware {
let IntlQueryMiddleware = class IntlQueryMiddleware extends QueryMiddleware {
afterQueryCreation(builder) {
if (builder instanceof SQB && !builder.translated) {
const lang = (0, intl_1.guessLanguage)();
const dLang = (0, intl_1.defaultLanguage)();
const lang = guessLanguage();
const dLang = defaultLanguage();
if (lang && dLang !== lang) {

@@ -175,13 +153,13 @@ builder.translate(lang);

IntlQueryMiddleware = __decorate([
(0, di_1.Injectable)(orm_1.QueryMiddleware)
Injectable(QueryMiddleware)
], IntlQueryMiddleware);
exports.IntlQueryMiddleware = IntlQueryMiddleware;
let DbTranslationSource = class DbTranslationSource extends intl_1.TranslationSource {
export { IntlQueryMiddleware };
let DbTranslationSource = class DbTranslationSource extends TranslationSource {
async load() {
const translations = await IntlTranslation_1.IntlTranslation.all();
return lodash_1.default.mapValues(lodash_1.default.groupBy(translations, 'Lang'), (t) => {
const translations = await IntlTranslation.all();
return _.mapValues(_.groupBy(translations, 'Lang'), (t) => {
const vals = t.map((tt) => {
return { [tt.Key]: tt.Value };
});
return lodash_1.default.assign.apply(lodash_1.default, vals);
return _.assign.apply(_, vals);
});

@@ -191,5 +169,5 @@ }

DbTranslationSource = __decorate([
(0, di_1.Injectable)(intl_1.TranslationSource)
Injectable(TranslationSource)
], DbTranslationSource);
exports.DbTranslationSource = DbTranslationSource;
export { DbTranslationSource };
//# sourceMappingURL=index.js.map

@@ -6,1 +6,2 @@ import { OrmMigration, OrmDriver } from '@spinajs/orm';

}
//# sourceMappingURL=IntlOrm_2022_06_28_01_13_00.d.ts.map

@@ -1,2 +0,1 @@

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

@@ -8,7 +7,5 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntlOrm_2022_06_28_01_13_00 = void 0;
/* eslint-disable @typescript-eslint/no-unused-vars */
const orm_1 = require("@spinajs/orm");
let IntlOrm_2022_06_28_01_13_00 = class IntlOrm_2022_06_28_01_13_00 extends orm_1.OrmMigration {
import { OrmMigration, Migration } from '@spinajs/orm';
let IntlOrm_2022_06_28_01_13_00 = class IntlOrm_2022_06_28_01_13_00 extends OrmMigration {
async up(connection) {

@@ -36,5 +33,5 @@ await connection.schema().createTable('intl_resources', (table) => {

IntlOrm_2022_06_28_01_13_00 = __decorate([
(0, orm_1.Migration)('default')
Migration('default')
], IntlOrm_2022_06_28_01_13_00);
exports.IntlOrm_2022_06_28_01_13_00 = IntlOrm_2022_06_28_01_13_00;
export { IntlOrm_2022_06_28_01_13_00 };
//# sourceMappingURL=IntlOrm_2022_06_28_01_13_00.js.map

@@ -13,1 +13,2 @@ import { ModelBase } from '@spinajs/orm';

}
//# sourceMappingURL=model.d.ts.map

@@ -1,14 +0,8 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Translatable = void 0;
const di_1 = require("@spinajs/di");
const orm_1 = require("@spinajs/orm");
const lodash_1 = __importDefault(require("lodash"));
const IntlResource_1 = require("./models/IntlResource");
const configuration_1 = require("@spinajs/configuration");
const intl_1 = require("@spinajs/intl");
class Translatable extends orm_1.ModelBase {
import { DI } from '@spinajs/di';
import { InsertBehaviour, ModelBase } from '@spinajs/orm';
import _ from 'lodash';
import { IntlResource } from './models/IntlResource.js';
import { Configuration } from '@spinajs/configuration';
import { guessLanguage } from '@spinajs/intl';
export class Translatable extends ModelBase {
/**

@@ -20,4 +14,4 @@ * Reloads entity with proper translation

async translate(lang) {
const selectedLang = (0, intl_1.guessLanguage)(lang);
const translations = await IntlResource_1.IntlResource.where({
const selectedLang = guessLanguage(lang);
const translations = await IntlResource.where({
ResourceId: this.PrimaryKeyValue,

@@ -36,4 +30,4 @@ Resource: this.constructor.name,

async update() {
const selectedLang = (0, intl_1.guessLanguage)(this.Language);
const defaultLanguage = di_1.DI.get(configuration_1.Configuration).get('intl.defaultLocale');
const selectedLang = guessLanguage(this.Language);
const defaultLanguage = DI.get(Configuration).get('intl.defaultLocale');
if (!selectedLang || defaultLanguage === selectedLang) {

@@ -45,3 +39,3 @@ await super.update();

// TODO: temporaty use uniqyBy, pls FIX model descriptor proper handling in ORM module
const tColumns = lodash_1.default.uniqBy(this.ModelDescriptor.Columns.filter((c) => c.Translate), 'Name');
const tColumns = _.uniqBy(this.ModelDescriptor.Columns.filter((c) => c.Translate), 'Name');
const { query } = this.createUpdateQuery();

@@ -53,3 +47,3 @@ if (this.ModelDescriptor.Timestamps.UpdatedAt) {

const cToDehydrate = [...tColumns.map((c) => c.Name)];
const dToUpdate = lodash_1.default.omit(this.toSql(), cToDehydrate);
const dToUpdate = _.omit(this.toSql(), cToDehydrate);
if (Object.keys(dToUpdate).length !== 0) {

@@ -59,3 +53,3 @@ await query.update(dToUpdate).where(this.PrimaryKeyName, this.PrimaryKeyValue);

const translations = tColumns.map((c) => {
return new IntlResource_1.IntlResource({
return new IntlResource({
ResourceId: this.PrimaryKeyValue,

@@ -70,3 +64,3 @@ Resource: this.constructor.name,

for (const t of translations) {
await t.insert(orm_1.InsertBehaviour.InsertOrUpdate);
await t.insert(InsertBehaviour.InsertOrUpdate);
}

@@ -76,3 +70,2 @@ }

}
exports.Translatable = Translatable;
//# sourceMappingURL=model.js.map

@@ -14,1 +14,2 @@ import { ModelBase } from '@spinajs/orm';

}
//# sourceMappingURL=IntlResource.d.ts.map

@@ -1,2 +0,1 @@

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

@@ -8,5 +7,3 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntlResource = void 0;
const orm_1 = require("@spinajs/orm");
import { ModelBase, Connection, Model } from '@spinajs/orm';
/**

@@ -17,9 +14,9 @@ * Base modele for users used by ACL

*/
let IntlResource = class IntlResource extends orm_1.ModelBase {
let IntlResource = class IntlResource extends ModelBase {
};
IntlResource = __decorate([
(0, orm_1.Connection)('default'),
(0, orm_1.Model)('intl_resources')
Connection('default'),
Model('intl_resources')
], IntlResource);
exports.IntlResource = IntlResource;
export { IntlResource };
//# sourceMappingURL=IntlResource.js.map

@@ -13,1 +13,2 @@ import { ModelBase } from '@spinajs/orm';

}
//# sourceMappingURL=IntlTranslation.d.ts.map

@@ -1,2 +0,1 @@

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

@@ -11,5 +10,3 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntlTranslation = void 0;
const orm_1 = require("@spinajs/orm");
import { ModelBase, Connection, Model, Primary } from '@spinajs/orm';
/**

@@ -20,13 +17,13 @@ * Base modele for users used by ACL

*/
let IntlTranslation = class IntlTranslation extends orm_1.ModelBase {
let IntlTranslation = class IntlTranslation extends ModelBase {
};
__decorate([
(0, orm_1.Primary)(),
Primary(),
__metadata("design:type", Number)
], IntlTranslation.prototype, "Id", void 0);
IntlTranslation = __decorate([
(0, orm_1.Connection)('default'),
(0, orm_1.Model)('intl_translations')
Connection('default'),
Model('intl_translations')
], IntlTranslation);
exports.IntlTranslation = IntlTranslation;
export { IntlTranslation };
//# sourceMappingURL=IntlTranslation.js.map
{
"name": "@spinajs/intl-orm",
"version": "2.0.46",
"version": "2.0.48",
"description": "Internationalization support for ORM module",
"main": "lib/index.js",
"exports": "./lib/index.js",
"type": "module",
"private": false,
"engines": {
"node": ">=16.11"
},
"scripts": {
"build": "npm run clean && npm run compile",
"compile": "tsc -p tsconfig.build.json",
"clean": "",
"compile": "tsc -b tsconfig.json",
"rimraf": "./node_modules/rimraf/bin.js",
"clean": "rimraf lib/ && rimraf tsconfig.tsbuildinfo",
"test": "ts-mocha -p tsconfig.json test/**/*.test.ts",
"coverage": "nyc npm run test",
"build-docs": "rimraf docs && typedoc --options typedoc.json src/",
"prepare": "npm run build",
"format": "prettier --write \"src/**/*.ts\"",
"lint": "eslint -c .eslintrc.js --ext .ts src --fix",
"prepublishOnly": "npm test && npm run lint",
"lint": "eslint -c .eslintrc.cjs --ext .ts src --fix",
"preversion": "npm run lint",
"version": "npm run format && git add -A src",
"postversion": "git push && git push --tags"
"postinstall": "npm run build"
},

@@ -48,3 +51,3 @@ "files": [

"@spinajs/reflection": "^2.0.46",
"luxon": "^2.4.0",
"luxon": "^3.2.1",
"typescript-mix": "^3.1.3"

@@ -55,3 +58,3 @@ },

},
"gitHead": "bd560afd6c9a156071102cc6b4f36115b5498e9d"
"gitHead": "002dc553b0ffffd72193d0121ac425a4083bc9ee"
}

@@ -0,0 +0,0 @@ # `intl-orm`

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc