node_modules ignore

This commit is contained in:
2025-05-08 23:43:47 +02:00
parent e19d52f172
commit 4574544c9f
65041 changed files with 10593536 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import type { Modules, UID, Data, Schema, Core } from '@strapi/types';
type LoadedComponents<TUID extends UID.Schema> = Data.Entity<TUID, Schema.AttributeNamesByType<TUID, 'component' | 'dynamiczone'>>;
type ComponentBody = {
[key: string]: Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, false> | Schema.Attribute.Component<UID.Component, true> | Schema.Attribute.DynamicZone>;
};
declare function omitComponentData(contentType: Schema.ContentType, data: Modules.EntityService.Params.Data.Input<Schema.ContentType['uid']>): Partial<Modules.EntityService.Params.Data.Input<Schema.ContentType['uid']>>;
declare function omitComponentData(contentType: Schema.Component, data: Modules.EntityService.Params.Data.Input<Schema.Component['uid']>): Partial<Modules.EntityService.Params.Data.Input<Schema.Component['uid']>>;
declare const createComponents: <TUID extends UID.Schema, TData extends Modules.EntityService.Params.Data.Input<TUID>>(uid: TUID, data: TData) => Promise<ComponentBody>;
declare const getComponents: <TUID extends UID.Schema>(uid: TUID, entity: {
id: Modules.EntityService.Params.Attribute.ID;
}) => Promise<LoadedComponents<TUID>>;
declare const updateComponents: <TUID extends UID.Schema, TData extends Partial<Modules.EntityService.Params.Data.Input<TUID>>>(uid: TUID, entityToUpdate: {
id: Modules.EntityService.Params.Attribute.ID;
}, data: TData) => Promise<ComponentBody>;
declare const deleteComponents: <TUID extends UID.Schema, TEntity extends Data.Entity<TUID, Extract<keyof Schema.Attributes<TUID>, string>>>(uid: TUID, entityToDelete: TEntity, { loadComponents }?: {
loadComponents?: boolean | undefined;
}) => Promise<void>;
declare const deleteComponent: <TUID extends `${string}.${string}`>(uid: TUID, componentToDelete: Data.Component<TUID>) => Promise<void>;
/**
* Resolve the component UID of an entity's attribute based
* on a given path (components & dynamic zones only)
*/
declare const resolveComponentUID: ({ paths, strapi, data, contentType, }: {
paths: string[];
strapi: Core.Strapi;
data: any;
contentType: Schema.ContentType;
}) => UID.Schema | undefined;
export { omitComponentData, getComponents, createComponents, updateComponents, deleteComponents, deleteComponent, resolveComponentUID, };
//# sourceMappingURL=components.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../src/utils/components.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAS,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE7E,KAAK,gBAAgB,CAAC,IAAI,SAAS,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAC1D,IAAI,EACJ,MAAM,CAAC,oBAAoB,CAAC,IAAI,EAAE,WAAW,GAAG,aAAa,CAAC,CAC/D,CAAC;AAMF,KAAK,aAAa,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CACjC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,GAChD,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,GAC/C,MAAM,CAAC,SAAS,CAAC,WAAW,CAC/B,CAAC;CACH,CAAC;AAIF,iBAAS,iBAAiB,CACxB,WAAW,EAAE,MAAM,CAAC,WAAW,EAC/B,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,GACvE,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC/E,iBAAS,iBAAiB,CACxB,WAAW,EAAE,MAAM,CAAC,SAAS,EAC7B,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,GACrE,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAgB7E,QAAA,MAAM,gBAAgB,8FAIf,IAAI,QACH,KAAK,2BAgGZ,CAAC;AAEF,QAAA,MAAM,aAAa,iCACZ,IAAI,UACD;IAAE,EAAE,EAAE,QAAQ,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAA;CAAE,KACxD,QAAQ,iBAAiB,IAAI,CAAC,CAQhC,CAAC;AAMF,QAAA,MAAM,gBAAgB,uGAIf,IAAI,kBACO;IAAE,EAAE,EAAE,QAAQ,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAA;CAAE,QAC3D,KAAK,2BA0FZ,CAAC;AAkGF,QAAA,MAAM,gBAAgB,oHACf,IAAI,kBACO,OAAO;;mBA6CxB,CAAC;AA8DF,QAAA,MAAM,eAAe,4CACd,IAAI,qBACU,KAAK,SAAS,CAAC,IAAI,CAAC,kBAIxC,CAAC;AAEF;;;GAGG;AACH,QAAA,MAAM,mBAAmB,0CAKtB;IACD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,KAAK,MAAM,CAAC;IACpB,IAAI,EAAE,GAAG,CAAC;IACV,WAAW,EAAE,OAAO,WAAW,CAAC;CACjC,KAAG,IAAI,MAAM,GAAG,SAiChB,CAAC;AAEF,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,GACpB,CAAC"}

View File

@@ -0,0 +1,178 @@
'use strict';
var _ = require('lodash');
var fp = require('lodash/fp');
var utils = require('@strapi/utils');
const isDialectMySQL = ()=>strapi.db?.dialect.client === 'mysql';
function omitComponentData(contentType, data) {
const { attributes } = contentType;
const componentAttributes = Object.keys(attributes).filter((attributeName)=>utils.contentTypes.isComponentAttribute(attributes[attributeName]));
return fp.omit(componentAttributes, data);
}
// NOTE: we could generalize the logic to allow CRUD of relation directly in the DB layer
const createComponents = async (uid, data)=>{
const { attributes = {} } = strapi.getModel(uid);
const componentBody = {};
const attributeNames = Object.keys(attributes);
for (const attributeName of attributeNames){
const attribute = attributes[attributeName];
if (!fp.has(attributeName, data) || !utils.contentTypes.isComponentAttribute(attribute)) {
continue;
}
if (attribute.type === 'component') {
const { component: componentUID, repeatable = false } = attribute;
const componentValue = data[attributeName];
if (componentValue === null) {
continue;
}
if (repeatable === true) {
if (!Array.isArray(componentValue)) {
throw new Error('Expected an array to create repeatable component');
}
// MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
const components = await utils.async.map(componentValue, (value)=>createComponent(componentUID, value), {
concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity
});
componentBody[attributeName] = components.map(({ id })=>{
return {
id,
__pivot: {
field: attributeName,
component_type: componentUID
}
};
});
} else {
const component = await createComponent(componentUID, componentValue);
componentBody[attributeName] = {
id: component.id,
__pivot: {
field: attributeName,
component_type: componentUID
}
};
}
continue;
}
if (attribute.type === 'dynamiczone') {
const dynamiczoneValues = data[attributeName];
if (!Array.isArray(dynamiczoneValues)) {
throw new Error('Expected an array to create repeatable component');
}
const createDynamicZoneComponents = async (value)=>{
const { id } = await createComponent(value.__component, value);
return {
id,
__component: value.__component,
__pivot: {
field: attributeName
}
};
};
// MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
componentBody[attributeName] = await utils.async.map(dynamiczoneValues, createDynamicZoneComponents, {
concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity
});
continue;
}
}
return componentBody;
};
const getComponents = async (uid, entity)=>{
const componentAttributes = utils.contentTypes.getComponentAttributes(strapi.getModel(uid));
if (_.isEmpty(componentAttributes)) {
return {};
}
return strapi.db.query(uid).load(entity, componentAttributes);
};
const deleteComponents = async (uid, entityToDelete, { loadComponents = true } = {})=>{
const { attributes = {} } = strapi.getModel(uid);
const attributeNames = Object.keys(attributes);
for (const attributeName of attributeNames){
const attribute = attributes[attributeName];
if (attribute.type === 'component' || attribute.type === 'dynamiczone') {
let value;
if (loadComponents) {
value = await strapi.db.query(uid).load(entityToDelete, attributeName);
} else {
value = entityToDelete[attributeName];
}
if (!value) {
continue;
}
if (attribute.type === 'component') {
const { component: componentUID } = attribute;
// MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
await utils.async.map(_.castArray(value), (subValue)=>deleteComponent(componentUID, subValue), {
concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity
});
} else {
// delete dynamic zone components
// MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
await utils.async.map(_.castArray(value), (subValue)=>deleteComponent(subValue.__component, subValue), {
concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity
});
}
continue;
}
}
};
/** *************************
Component queries
************************** */ // components can have nested compos so this must be recursive
const createComponent = async (uid, data)=>{
const model = strapi.getModel(uid);
const componentData = await createComponents(uid, data);
const transform = fp.pipe(// Make sure we don't save the component with a pre-defined ID
fp.omit('id'), // Remove the component data from the original data object ...
(payload)=>omitComponentData(model, payload), // ... and assign the newly created component instead
fp.assign(componentData));
return strapi.db.query(uid).create({
data: transform(data)
});
};
const deleteComponent = async (uid, componentToDelete)=>{
await deleteComponents(uid, componentToDelete);
await strapi.db.query(uid).delete({
where: {
id: componentToDelete.id
}
});
};
/**
* Resolve the component UID of an entity's attribute based
* on a given path (components & dynamic zones only)
*/ const resolveComponentUID = ({ paths, strapi: strapi1, data, contentType })=>{
let value = data;
let cType = contentType;
for (const path of paths){
value = fp.get(path, value);
// Needed when the value of cType should be computed
// based on the next value (eg: dynamic zones)
if (typeof cType === 'function') {
cType = cType(value);
}
if (path in cType.attributes) {
const attribute = cType.attributes[path];
if (attribute.type === 'component') {
cType = strapi1.getModel(attribute.component);
}
if (attribute.type === 'dynamiczone') {
cType = ({ __component })=>strapi1.getModel(__component);
}
}
}
if ('uid' in cType) {
return cType.uid;
}
return undefined;
};
exports.createComponents = createComponents;
exports.deleteComponent = deleteComponent;
exports.deleteComponents = deleteComponents;
exports.getComponents = getComponents;
exports.omitComponentData = omitComponentData;
exports.resolveComponentUID = resolveComponentUID;
//# sourceMappingURL=components.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,171 @@
import _ from 'lodash';
import { get, has, pipe, omit, assign } from 'lodash/fp';
import { contentTypes, async } from '@strapi/utils';
const isDialectMySQL = ()=>strapi.db?.dialect.client === 'mysql';
function omitComponentData(contentType, data) {
const { attributes } = contentType;
const componentAttributes = Object.keys(attributes).filter((attributeName)=>contentTypes.isComponentAttribute(attributes[attributeName]));
return omit(componentAttributes, data);
}
// NOTE: we could generalize the logic to allow CRUD of relation directly in the DB layer
const createComponents = async (uid, data)=>{
const { attributes = {} } = strapi.getModel(uid);
const componentBody = {};
const attributeNames = Object.keys(attributes);
for (const attributeName of attributeNames){
const attribute = attributes[attributeName];
if (!has(attributeName, data) || !contentTypes.isComponentAttribute(attribute)) {
continue;
}
if (attribute.type === 'component') {
const { component: componentUID, repeatable = false } = attribute;
const componentValue = data[attributeName];
if (componentValue === null) {
continue;
}
if (repeatable === true) {
if (!Array.isArray(componentValue)) {
throw new Error('Expected an array to create repeatable component');
}
// MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
const components = await async.map(componentValue, (value)=>createComponent(componentUID, value), {
concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity
});
componentBody[attributeName] = components.map(({ id })=>{
return {
id,
__pivot: {
field: attributeName,
component_type: componentUID
}
};
});
} else {
const component = await createComponent(componentUID, componentValue);
componentBody[attributeName] = {
id: component.id,
__pivot: {
field: attributeName,
component_type: componentUID
}
};
}
continue;
}
if (attribute.type === 'dynamiczone') {
const dynamiczoneValues = data[attributeName];
if (!Array.isArray(dynamiczoneValues)) {
throw new Error('Expected an array to create repeatable component');
}
const createDynamicZoneComponents = async (value)=>{
const { id } = await createComponent(value.__component, value);
return {
id,
__component: value.__component,
__pivot: {
field: attributeName
}
};
};
// MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
componentBody[attributeName] = await async.map(dynamiczoneValues, createDynamicZoneComponents, {
concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity
});
continue;
}
}
return componentBody;
};
const getComponents = async (uid, entity)=>{
const componentAttributes = contentTypes.getComponentAttributes(strapi.getModel(uid));
if (_.isEmpty(componentAttributes)) {
return {};
}
return strapi.db.query(uid).load(entity, componentAttributes);
};
const deleteComponents = async (uid, entityToDelete, { loadComponents = true } = {})=>{
const { attributes = {} } = strapi.getModel(uid);
const attributeNames = Object.keys(attributes);
for (const attributeName of attributeNames){
const attribute = attributes[attributeName];
if (attribute.type === 'component' || attribute.type === 'dynamiczone') {
let value;
if (loadComponents) {
value = await strapi.db.query(uid).load(entityToDelete, attributeName);
} else {
value = entityToDelete[attributeName];
}
if (!value) {
continue;
}
if (attribute.type === 'component') {
const { component: componentUID } = attribute;
// MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
await async.map(_.castArray(value), (subValue)=>deleteComponent(componentUID, subValue), {
concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity
});
} else {
// delete dynamic zone components
// MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
await async.map(_.castArray(value), (subValue)=>deleteComponent(subValue.__component, subValue), {
concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity
});
}
continue;
}
}
};
/** *************************
Component queries
************************** */ // components can have nested compos so this must be recursive
const createComponent = async (uid, data)=>{
const model = strapi.getModel(uid);
const componentData = await createComponents(uid, data);
const transform = pipe(// Make sure we don't save the component with a pre-defined ID
omit('id'), // Remove the component data from the original data object ...
(payload)=>omitComponentData(model, payload), // ... and assign the newly created component instead
assign(componentData));
return strapi.db.query(uid).create({
data: transform(data)
});
};
const deleteComponent = async (uid, componentToDelete)=>{
await deleteComponents(uid, componentToDelete);
await strapi.db.query(uid).delete({
where: {
id: componentToDelete.id
}
});
};
/**
* Resolve the component UID of an entity's attribute based
* on a given path (components & dynamic zones only)
*/ const resolveComponentUID = ({ paths, strapi: strapi1, data, contentType })=>{
let value = data;
let cType = contentType;
for (const path of paths){
value = get(path, value);
// Needed when the value of cType should be computed
// based on the next value (eg: dynamic zones)
if (typeof cType === 'function') {
cType = cType(value);
}
if (path in cType.attributes) {
const attribute = cType.attributes[path];
if (attribute.type === 'component') {
cType = strapi1.getModel(attribute.component);
}
if (attribute.type === 'dynamiczone') {
cType = ({ __component })=>strapi1.getModel(__component);
}
}
}
if ('uid' in cType) {
return cType.uid;
}
return undefined;
};
export { createComponents, deleteComponent, deleteComponents, getComponents, omitComponentData, resolveComponentUID };
//# sourceMappingURL=components.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,42 @@
export interface IDiagnosticReporterOptions {
stackSize?: number;
}
export type GenericDiagnostic<K extends DiagnosticKind, T = unknown> = {
kind: K;
details: {
message: string;
createdAt: Date;
} & T;
};
export type DiagnosticKind = 'error' | 'warning' | 'info';
export type DiagnosticListener<T extends DiagnosticKind = DiagnosticKind> = (diagnostic: {
kind: T;
} & Diagnostic extends infer U ? U : never) => void | Promise<void>;
export type DiagnosticEvent = 'diagnostic' | `diagnostic.${DiagnosticKind}`;
export type GetEventListener<E extends DiagnosticEvent> = E extends 'diagnostic' ? DiagnosticListener : E extends `diagnostic.${infer K}` ? K extends DiagnosticKind ? DiagnosticListener<K> : never : never;
export type Diagnostic = ErrorDiagnostic | WarningDiagnostic | InfoDiagnostic;
export type ErrorDiagnosticSeverity = 'fatal' | 'error' | 'silly';
export type ErrorDiagnostic = GenericDiagnostic<'error', {
name: string;
severity: ErrorDiagnosticSeverity;
error: Error;
}>;
export type WarningDiagnostic = GenericDiagnostic<'warning', {
origin?: string;
}>;
export type InfoDiagnostic<T = unknown> = GenericDiagnostic<'info', {
origin?: string;
params?: T;
}>;
export interface IDiagnosticReporter {
stack: {
readonly size: number;
readonly items: Diagnostic[];
};
report(diagnostic: Diagnostic): IDiagnosticReporter;
onDiagnostic(listener: DiagnosticListener): IDiagnosticReporter;
on<T extends DiagnosticKind>(kind: T, listener: DiagnosticListener<T>): IDiagnosticReporter;
}
declare const createDiagnosticReporter: (options?: IDiagnosticReporterOptions) => IDiagnosticReporter;
export { createDiagnosticReporter };
//# sourceMappingURL=diagnostic.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"diagnostic.d.ts","sourceRoot":"","sources":["../../src/utils/diagnostic.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,0BAA0B;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,cAAc,EAAE,CAAC,GAAG,OAAO,IAAI;IACrE,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE;QACP,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,IAAI,CAAC;KACjB,GAAG,CAAC,CAAC;CACP,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAE1D,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,IAAI,CAC1E,UAAU,EAAE;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,GAAG,UAAU,SAAS,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,KAC7D,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,cAAc,cAAc,EAAE,CAAC;AAE5E,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,eAAe,IAAI,CAAC,SAAS,YAAY,GAC5E,kBAAkB,GAClB,CAAC,SAAS,cAAc,MAAM,CAAC,EAAE,GAC/B,CAAC,SAAS,cAAc,GACtB,kBAAkB,CAAC,CAAC,CAAC,GACrB,KAAK,GACP,KAAK,CAAC;AAEZ,MAAM,MAAM,UAAU,GAAG,eAAe,GAAG,iBAAiB,GAAG,cAAc,CAAC;AAE9E,MAAM,MAAM,uBAAuB,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAElE,MAAM,MAAM,eAAe,GAAG,iBAAiB,CAC7C,OAAO,EACP;IACE,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,uBAAuB,CAAC;IAClC,KAAK,EAAE,KAAK,CAAC;CACd,CACF,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,CAC/C,SAAS,EACT;IACE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CACF,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,OAAO,IAAI,iBAAiB,CACzD,MAAM,EACN;IACE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,CAAC,CAAC;CACZ,CACF,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE;QACL,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,CAAC;KAC9B,CAAC;IAEF,MAAM,CAAC,UAAU,EAAE,UAAU,GAAG,mBAAmB,CAAC;IACpD,YAAY,CAAC,QAAQ,EAAE,kBAAkB,GAAG,mBAAmB,CAAC;IAChE,EAAE,CAAC,CAAC,SAAS,cAAc,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC;CAC7F;AAED,QAAA,MAAM,wBAAwB,aACnB,0BAA0B,KAClC,mBAyDF,CAAC;AAEF,OAAO,EAAE,wBAAwB,EAAE,CAAC"}

View File

@@ -0,0 +1,51 @@
'use strict';
var events = require('events');
const createDiagnosticReporter = (options = {})=>{
const { stackSize = -1 } = options;
const emitter = new events.EventEmitter();
const stack = [];
const addListener = (event, listener)=>{
emitter.on(event, listener);
};
const isDiagnosticValid = (diagnostic)=>{
if (!diagnostic.kind || !diagnostic.details || !diagnostic.details.message) {
return false;
}
return true;
};
return {
stack: {
get size () {
return stack.length;
},
get items () {
return stack;
}
},
report (diagnostic) {
if (!isDiagnosticValid(diagnostic)) {
return this;
}
emitter.emit('diagnostic', diagnostic);
emitter.emit(`diagnostic.${diagnostic.kind}`, diagnostic);
if (stackSize !== -1 && stack.length >= stackSize) {
stack.shift();
}
stack.push(diagnostic);
return this;
},
onDiagnostic (listener) {
addListener('diagnostic', listener);
return this;
},
on (kind, listener) {
addListener(`diagnostic.${kind}`, listener);
return this;
}
};
};
exports.createDiagnosticReporter = createDiagnosticReporter;
//# sourceMappingURL=diagnostic.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"diagnostic.js","sources":["../../src/utils/diagnostic.ts"],"sourcesContent":["import { EventEmitter } from 'events';\n\nexport interface IDiagnosticReporterOptions {\n stackSize?: number;\n}\n\nexport type GenericDiagnostic<K extends DiagnosticKind, T = unknown> = {\n kind: K;\n details: {\n message: string;\n createdAt: Date;\n } & T;\n};\n\nexport type DiagnosticKind = 'error' | 'warning' | 'info';\n\nexport type DiagnosticListener<T extends DiagnosticKind = DiagnosticKind> = (\n diagnostic: { kind: T } & Diagnostic extends infer U ? U : never\n) => void | Promise<void>;\n\nexport type DiagnosticEvent = 'diagnostic' | `diagnostic.${DiagnosticKind}`;\n\nexport type GetEventListener<E extends DiagnosticEvent> = E extends 'diagnostic'\n ? DiagnosticListener\n : E extends `diagnostic.${infer K}`\n ? K extends DiagnosticKind\n ? DiagnosticListener<K>\n : never\n : never;\n\nexport type Diagnostic = ErrorDiagnostic | WarningDiagnostic | InfoDiagnostic;\n\nexport type ErrorDiagnosticSeverity = 'fatal' | 'error' | 'silly';\n\nexport type ErrorDiagnostic = GenericDiagnostic<\n 'error',\n {\n name: string;\n severity: ErrorDiagnosticSeverity;\n error: Error;\n }\n>;\n\nexport type WarningDiagnostic = GenericDiagnostic<\n 'warning',\n {\n origin?: string;\n }\n>;\n\nexport type InfoDiagnostic<T = unknown> = GenericDiagnostic<\n 'info',\n {\n origin?: string;\n params?: T;\n }\n>;\n\nexport interface IDiagnosticReporter {\n stack: {\n readonly size: number;\n readonly items: Diagnostic[];\n };\n\n report(diagnostic: Diagnostic): IDiagnosticReporter;\n onDiagnostic(listener: DiagnosticListener): IDiagnosticReporter;\n on<T extends DiagnosticKind>(kind: T, listener: DiagnosticListener<T>): IDiagnosticReporter;\n}\n\nconst createDiagnosticReporter = (\n options: IDiagnosticReporterOptions = {}\n): IDiagnosticReporter => {\n const { stackSize = -1 } = options;\n\n const emitter = new EventEmitter();\n const stack: Diagnostic[] = [];\n\n const addListener = <T extends DiagnosticEvent>(event: T, listener: GetEventListener<T>) => {\n emitter.on(event, listener);\n };\n\n const isDiagnosticValid = (diagnostic: Diagnostic) => {\n if (!diagnostic.kind || !diagnostic.details || !diagnostic.details.message) {\n return false;\n }\n return true;\n };\n\n return {\n stack: {\n get size() {\n return stack.length;\n },\n\n get items() {\n return stack;\n },\n },\n\n report(diagnostic: Diagnostic) {\n if (!isDiagnosticValid(diagnostic)) {\n return this;\n }\n\n emitter.emit('diagnostic', diagnostic);\n emitter.emit(`diagnostic.${diagnostic.kind}`, diagnostic);\n\n if (stackSize !== -1 && stack.length >= stackSize) {\n stack.shift();\n }\n\n stack.push(diagnostic);\n\n return this;\n },\n\n onDiagnostic(listener: DiagnosticListener) {\n addListener('diagnostic', listener);\n\n return this;\n },\n\n on<T extends DiagnosticKind>(kind: T, listener: DiagnosticListener<T>) {\n addListener(`diagnostic.${kind}`, listener as never);\n\n return this;\n },\n };\n};\n\nexport { createDiagnosticReporter };\n"],"names":["createDiagnosticReporter","options","stackSize","emitter","EventEmitter","stack","addListener","event","listener","on","isDiagnosticValid","diagnostic","kind","details","message","size","length","items","report","emit","shift","push","onDiagnostic"],"mappings":";;;;AAqEA,MAAMA,wBAA2B,GAAA,CAC/BC,OAAsC,GAAA,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AA;AAEAW,QAAAA,YAAAA,CAAAA,CAAad,QAA4B,EAAA;AACvCF,YAAAA,WAAAA,CAAY,YAAcE,EAAAA,QAAAA,CAAAA;AAE1B,YAAA,OAAO,IAAI;AACb,SAAA;QAEAC,EAA6BG,CAAAA,CAAAA,IAAO,EAAEJ,QAA+B,EAAA;AACnEF,YAAAA,WAAAA,CAAY,CAAC,WAAW,EAAEM,IAAAA,CAAK,CAAC,EAAEJ,QAAAA,CAAAA;AAElC,YAAA,OAAO,IAAI;AACb;AACF,KAAA;AACF;;;;"}

View File

@@ -0,0 +1,49 @@
import { EventEmitter } from 'events';
const createDiagnosticReporter = (options = {})=>{
const { stackSize = -1 } = options;
const emitter = new EventEmitter();
const stack = [];
const addListener = (event, listener)=>{
emitter.on(event, listener);
};
const isDiagnosticValid = (diagnostic)=>{
if (!diagnostic.kind || !diagnostic.details || !diagnostic.details.message) {
return false;
}
return true;
};
return {
stack: {
get size () {
return stack.length;
},
get items () {
return stack;
}
},
report (diagnostic) {
if (!isDiagnosticValid(diagnostic)) {
return this;
}
emitter.emit('diagnostic', diagnostic);
emitter.emit(`diagnostic.${diagnostic.kind}`, diagnostic);
if (stackSize !== -1 && stack.length >= stackSize) {
stack.shift();
}
stack.push(diagnostic);
return this;
},
onDiagnostic (listener) {
addListener('diagnostic', listener);
return this;
},
on (kind, listener) {
addListener(`diagnostic.${kind}`, listener);
return this;
}
};
};
export { createDiagnosticReporter };
//# sourceMappingURL=diagnostic.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"diagnostic.mjs","sources":["../../src/utils/diagnostic.ts"],"sourcesContent":["import { EventEmitter } from 'events';\n\nexport interface IDiagnosticReporterOptions {\n stackSize?: number;\n}\n\nexport type GenericDiagnostic<K extends DiagnosticKind, T = unknown> = {\n kind: K;\n details: {\n message: string;\n createdAt: Date;\n } & T;\n};\n\nexport type DiagnosticKind = 'error' | 'warning' | 'info';\n\nexport type DiagnosticListener<T extends DiagnosticKind = DiagnosticKind> = (\n diagnostic: { kind: T } & Diagnostic extends infer U ? U : never\n) => void | Promise<void>;\n\nexport type DiagnosticEvent = 'diagnostic' | `diagnostic.${DiagnosticKind}`;\n\nexport type GetEventListener<E extends DiagnosticEvent> = E extends 'diagnostic'\n ? DiagnosticListener\n : E extends `diagnostic.${infer K}`\n ? K extends DiagnosticKind\n ? DiagnosticListener<K>\n : never\n : never;\n\nexport type Diagnostic = ErrorDiagnostic | WarningDiagnostic | InfoDiagnostic;\n\nexport type ErrorDiagnosticSeverity = 'fatal' | 'error' | 'silly';\n\nexport type ErrorDiagnostic = GenericDiagnostic<\n 'error',\n {\n name: string;\n severity: ErrorDiagnosticSeverity;\n error: Error;\n }\n>;\n\nexport type WarningDiagnostic = GenericDiagnostic<\n 'warning',\n {\n origin?: string;\n }\n>;\n\nexport type InfoDiagnostic<T = unknown> = GenericDiagnostic<\n 'info',\n {\n origin?: string;\n params?: T;\n }\n>;\n\nexport interface IDiagnosticReporter {\n stack: {\n readonly size: number;\n readonly items: Diagnostic[];\n };\n\n report(diagnostic: Diagnostic): IDiagnosticReporter;\n onDiagnostic(listener: DiagnosticListener): IDiagnosticReporter;\n on<T extends DiagnosticKind>(kind: T, listener: DiagnosticListener<T>): IDiagnosticReporter;\n}\n\nconst createDiagnosticReporter = (\n options: IDiagnosticReporterOptions = {}\n): IDiagnosticReporter => {\n const { stackSize = -1 } = options;\n\n const emitter = new EventEmitter();\n const stack: Diagnostic[] = [];\n\n const addListener = <T extends DiagnosticEvent>(event: T, listener: GetEventListener<T>) => {\n emitter.on(event, listener);\n };\n\n const isDiagnosticValid = (diagnostic: Diagnostic) => {\n if (!diagnostic.kind || !diagnostic.details || !diagnostic.details.message) {\n return false;\n }\n return true;\n };\n\n return {\n stack: {\n get size() {\n return stack.length;\n },\n\n get items() {\n return stack;\n },\n },\n\n report(diagnostic: Diagnostic) {\n if (!isDiagnosticValid(diagnostic)) {\n return this;\n }\n\n emitter.emit('diagnostic', diagnostic);\n emitter.emit(`diagnostic.${diagnostic.kind}`, diagnostic);\n\n if (stackSize !== -1 && stack.length >= stackSize) {\n stack.shift();\n }\n\n stack.push(diagnostic);\n\n return this;\n },\n\n onDiagnostic(listener: DiagnosticListener) {\n addListener('diagnostic', listener);\n\n return this;\n },\n\n on<T extends DiagnosticKind>(kind: T, listener: DiagnosticListener<T>) {\n addListener(`diagnostic.${kind}`, listener as never);\n\n return this;\n },\n };\n};\n\nexport { createDiagnosticReporter };\n"],"names":["createDiagnosticReporter","options","stackSize","emitter","EventEmitter","stack","addListener","event","listener","on","isDiagnosticValid","diagnostic","kind","details","message","size","length","items","report","emit","shift","push","onDiagnostic"],"mappings":";;AAqEA,MAAMA,wBAA2B,GAAA,CAC/BC,OAAsC,GAAA,EAAE,GAAA;AAExC,IAAA,MAAM,EAAEC,SAAAA,GAAY,CAAC,CAAC,EAAE,GAAGD,OAAAA;AAE3B,IAAA,MAAME,UAAU,IAAIC,YAAAA,EAAAA;AACpB,IAAA,MAAMC,QAAsB,EAAE;IAE9B,MAAMC,WAAAA,GAAc,CAA4BC,KAAUC,EAAAA,QAAAA,GAAAA;QACxDL,OAAQM,CAAAA,EAAE,CAACF,KAAOC,EAAAA,QAAAA,CAAAA;AACpB,KAAA;AAEA,IAAA,MAAME,oBAAoB,CAACC,UAAAA,GAAAA;AACzB,QAAA,IAAI,CAACA,UAAAA,CAAWC,IAAI,IAAI,CAACD,UAAAA,CAAWE,OAAO,IAAI,CAACF,UAAAA,CAAWE,OAAO,CAACC,OAAO,EAAE;YAC1E,OAAO,KAAA;AACT;QACA,OAAO,IAAA;AACT,KAAA;IAEA,OAAO;QACLT,KAAO,EAAA;AACL,YAAA,IAAIU,IAAO,CAAA,GAAA;AACT,gBAAA,OAAOV,MAAMW,MAAM;AACrB,aAAA;AAEA,YAAA,IAAIC,KAAQ,CAAA,GAAA;gBACV,OAAOZ,KAAAA;AACT;AACF,SAAA;AAEAa,QAAAA,MAAAA,CAAAA,CAAOP,UAAsB,EAAA;YAC3B,IAAI,CAACD,kBAAkBC,UAAa,CAAA,EAAA;AAClC,gBAAA,OAAO,IAAI;AACb;YAEAR,OAAQgB,CAAAA,IAAI,CAAC,YAAcR,EAAAA,UAAAA,CAAAA;YAC3BR,OAAQgB,CAAAA,IAAI,CAAC,CAAC,WAAW,EAAER,UAAWC,CAAAA,IAAI,CAAC,CAAC,EAAED,UAAAA,CAAAA;AAE9C,YAAA,IAAIT,cAAc,CAAC,CAAA,IAAKG,KAAMW,CAAAA,MAAM,IAAId,SAAW,EAAA;AACjDG,gBAAAA,KAAAA,CAAMe,KAAK,EAAA;AACb;AAEAf,YAAAA,KAAAA,CAAMgB,IAAI,CAACV,UAAAA,CAAAA;AAEX,YAAA,OAAO,IAAI;AACb,SAAA;AAEAW,QAAAA,YAAAA,CAAAA,CAAad,QAA4B,EAAA;AACvCF,YAAAA,WAAAA,CAAY,YAAcE,EAAAA,QAAAA,CAAAA;AAE1B,YAAA,OAAO,IAAI;AACb,SAAA;QAEAC,EAA6BG,CAAAA,CAAAA,IAAO,EAAEJ,QAA+B,EAAA;AACnEF,YAAAA,WAAAA,CAAY,CAAC,WAAW,EAAEM,IAAAA,CAAK,CAAC,EAAEJ,QAAAA,CAAAA;AAElC,YAAA,OAAO,IAAI;AACb;AACF,KAAA;AACF;;;;"}

View File

@@ -0,0 +1,13 @@
/// <reference types="node" />
import { Cipher } from 'crypto';
import { Algorithm } from '../../../types';
/**
* It creates a cipher instance used for decryption
*
* @param key - The decryption key
* @param algorithm - The algorithm to use to create the Cipher
*
* @returns A {@link Cipher} instance created with the given key & algorithm
*/
export declare const createDecryptionCipher: (key: string, algorithm?: Algorithm) => Cipher;
//# sourceMappingURL=decrypt.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"decrypt.d.ts","sourceRoot":"","sources":["../../../src/utils/encryption/decrypt.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAuD,MAAM,QAAQ,CAAC;AACrF,OAAO,EAAkC,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAkC3E;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,QAC5B,MAAM,cACA,SAAS,KACnB,MAEF,CAAC"}

View File

@@ -0,0 +1,47 @@
'use strict';
var crypto = require('crypto');
// different key values depending on algorithm chosen
const getDecryptionStrategy = (algorithm)=>{
const strategies = {
'aes-128-ecb' (key) {
const hashedKey = crypto.scryptSync(key, '', 16);
const initVector = null;
const securityKey = hashedKey;
return crypto.createDecipheriv(algorithm, securityKey, initVector);
},
aes128 (key) {
const hashedKey = crypto.scryptSync(key, '', 32);
const initVector = hashedKey.slice(16);
const securityKey = hashedKey.slice(0, 16);
return crypto.createDecipheriv(algorithm, securityKey, initVector);
},
aes192 (key) {
const hashedKey = crypto.scryptSync(key, '', 40);
const initVector = hashedKey.slice(24);
const securityKey = hashedKey.slice(0, 24);
return crypto.createDecipheriv(algorithm, securityKey, initVector);
},
aes256 (key) {
const hashedKey = crypto.scryptSync(key, '', 48);
const initVector = hashedKey.slice(32);
const securityKey = hashedKey.slice(0, 32);
return crypto.createDecipheriv(algorithm, securityKey, initVector);
}
};
return strategies[algorithm];
};
/**
* It creates a cipher instance used for decryption
*
* @param key - The decryption key
* @param algorithm - The algorithm to use to create the Cipher
*
* @returns A {@link Cipher} instance created with the given key & algorithm
*/ const createDecryptionCipher = (key, algorithm = 'aes-128-ecb')=>{
return getDecryptionStrategy(algorithm)(key);
};
exports.createDecryptionCipher = createDecryptionCipher;
//# sourceMappingURL=decrypt.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"decrypt.js","sources":["../../../src/utils/encryption/decrypt.ts"],"sourcesContent":["import { Cipher, scryptSync, CipherKey, BinaryLike, createDecipheriv } from 'crypto';\nimport { EncryptionStrategy, Strategies, Algorithm } from '../../../types';\n\n// different key values depending on algorithm chosen\nconst getDecryptionStrategy = (algorithm: Algorithm): EncryptionStrategy => {\n const strategies: Strategies = {\n 'aes-128-ecb'(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 16);\n const initVector: BinaryLike | null = null;\n const securityKey: CipherKey = hashedKey;\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes128(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 32);\n const initVector: BinaryLike | null = hashedKey.slice(16);\n const securityKey: CipherKey = hashedKey.slice(0, 16);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes192(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 40);\n const initVector: BinaryLike | null = hashedKey.slice(24);\n const securityKey: CipherKey = hashedKey.slice(0, 24);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes256(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 48);\n const initVector: BinaryLike | null = hashedKey.slice(32);\n const securityKey: CipherKey = hashedKey.slice(0, 32);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n };\n\n return strategies[algorithm];\n};\n\n/**\n * It creates a cipher instance used for decryption\n *\n * @param key - The decryption key\n * @param algorithm - The algorithm to use to create the Cipher\n *\n * @returns A {@link Cipher} instance created with the given key & algorithm\n */\nexport const createDecryptionCipher = (\n key: string,\n algorithm: Algorithm = 'aes-128-ecb'\n): Cipher => {\n return getDecryptionStrategy(algorithm)(key);\n};\n"],"names":["getDecryptionStrategy","algorithm","strategies","key","hashedKey","scryptSync","initVector","securityKey","createDecipheriv","aes128","slice","aes192","aes256","createDecryptionCipher"],"mappings":";;;;AAGA;AACA,MAAMA,wBAAwB,CAACC,SAAAA,GAAAA;AAC7B,IAAA,MAAMC,UAAyB,GAAA;AAC7B,QAAA,aAAA,CAAA,CAAcC,GAAW,EAAA;YACvB,MAAMC,SAAAA,GAAYC,iBAAWF,CAAAA,GAAAA,EAAK,EAAI,EAAA,EAAA,CAAA;AACtC,YAAA,MAAMG,UAAgC,GAAA,IAAA;AACtC,YAAA,MAAMC,WAAyBH,GAAAA,SAAAA;YAC/B,OAAOI,uBAAAA,CAAiBP,WAAWM,WAAaD,EAAAA,UAAAA,CAAAA;AAClD,SAAA;AACAG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D,sBAAsBC,SAAWE,CAAAA,CAAAA,GAAAA,CAAAA;AAC1C;;;;"}

View File

@@ -0,0 +1,45 @@
import { scryptSync, createDecipheriv } from 'crypto';
// different key values depending on algorithm chosen
const getDecryptionStrategy = (algorithm)=>{
const strategies = {
'aes-128-ecb' (key) {
const hashedKey = scryptSync(key, '', 16);
const initVector = null;
const securityKey = hashedKey;
return createDecipheriv(algorithm, securityKey, initVector);
},
aes128 (key) {
const hashedKey = scryptSync(key, '', 32);
const initVector = hashedKey.slice(16);
const securityKey = hashedKey.slice(0, 16);
return createDecipheriv(algorithm, securityKey, initVector);
},
aes192 (key) {
const hashedKey = scryptSync(key, '', 40);
const initVector = hashedKey.slice(24);
const securityKey = hashedKey.slice(0, 24);
return createDecipheriv(algorithm, securityKey, initVector);
},
aes256 (key) {
const hashedKey = scryptSync(key, '', 48);
const initVector = hashedKey.slice(32);
const securityKey = hashedKey.slice(0, 32);
return createDecipheriv(algorithm, securityKey, initVector);
}
};
return strategies[algorithm];
};
/**
* It creates a cipher instance used for decryption
*
* @param key - The decryption key
* @param algorithm - The algorithm to use to create the Cipher
*
* @returns A {@link Cipher} instance created with the given key & algorithm
*/ const createDecryptionCipher = (key, algorithm = 'aes-128-ecb')=>{
return getDecryptionStrategy(algorithm)(key);
};
export { createDecryptionCipher };
//# sourceMappingURL=decrypt.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"decrypt.mjs","sources":["../../../src/utils/encryption/decrypt.ts"],"sourcesContent":["import { Cipher, scryptSync, CipherKey, BinaryLike, createDecipheriv } from 'crypto';\nimport { EncryptionStrategy, Strategies, Algorithm } from '../../../types';\n\n// different key values depending on algorithm chosen\nconst getDecryptionStrategy = (algorithm: Algorithm): EncryptionStrategy => {\n const strategies: Strategies = {\n 'aes-128-ecb'(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 16);\n const initVector: BinaryLike | null = null;\n const securityKey: CipherKey = hashedKey;\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes128(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 32);\n const initVector: BinaryLike | null = hashedKey.slice(16);\n const securityKey: CipherKey = hashedKey.slice(0, 16);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes192(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 40);\n const initVector: BinaryLike | null = hashedKey.slice(24);\n const securityKey: CipherKey = hashedKey.slice(0, 24);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes256(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 48);\n const initVector: BinaryLike | null = hashedKey.slice(32);\n const securityKey: CipherKey = hashedKey.slice(0, 32);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n };\n\n return strategies[algorithm];\n};\n\n/**\n * It creates a cipher instance used for decryption\n *\n * @param key - The decryption key\n * @param algorithm - The algorithm to use to create the Cipher\n *\n * @returns A {@link Cipher} instance created with the given key & algorithm\n */\nexport const createDecryptionCipher = (\n key: string,\n algorithm: Algorithm = 'aes-128-ecb'\n): Cipher => {\n return getDecryptionStrategy(algorithm)(key);\n};\n"],"names":["getDecryptionStrategy","algorithm","strategies","key","hashedKey","scryptSync","initVector","securityKey","createDecipheriv","aes128","slice","aes192","aes256","createDecryptionCipher"],"mappings":";;AAGA;AACA,MAAMA,wBAAwB,CAACC,SAAAA,GAAAA;AAC7B,IAAA,MAAMC,UAAyB,GAAA;AAC7B,QAAA,aAAA,CAAA,CAAcC,GAAW,EAAA;YACvB,MAAMC,SAAAA,GAAYC,UAAWF,CAAAA,GAAAA,EAAK,EAAI,EAAA,EAAA,CAAA;AACtC,YAAA,MAAMG,UAAgC,GAAA,IAAA;AACtC,YAAA,MAAMC,WAAyBH,GAAAA,SAAAA;YAC/B,OAAOI,gBAAAA,CAAiBP,WAAWM,WAAaD,EAAAA,UAAAA,CAAAA;AAClD,SAAA;AACAG,QAAAA,MAAAA,CAAAA,CAAON,GAAW,EAAA;YAChB,MAAMC,SAAAA,GAAYC,UAAWF,CAAAA,GAAA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types="node" />
import { Cipher } from 'crypto';
import { Algorithm } from '../../../types';
/**
* It creates a cipher instance used for encryption
*
* @param key - The encryption key
* @param algorithm - The algorithm to use to create the Cipher
*
* @returns A {@link Cipher} instance created with the given key & algorithm
*/
export declare const createEncryptionCipher: (key: string, algorithm?: Algorithm) => Cipher;
//# sourceMappingURL=encrypt.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../../src/utils/encryption/encrypt.ts"],"names":[],"mappings":";AAAA,OAAO,EAAkB,MAAM,EAAqC,MAAM,QAAQ,CAAC;AACnF,OAAO,EAAkC,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAkC3E;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,QAC5B,MAAM,cACA,SAAS,KACnB,MAEF,CAAC"}

View File

@@ -0,0 +1,47 @@
'use strict';
var crypto = require('crypto');
// different key values depending on algorithm chosen
const getEncryptionStrategy = (algorithm)=>{
const strategies = {
'aes-128-ecb' (key) {
const hashedKey = crypto.scryptSync(key, '', 16);
const initVector = null;
const securityKey = hashedKey;
return crypto.createCipheriv(algorithm, securityKey, initVector);
},
aes128 (key) {
const hashedKey = crypto.scryptSync(key, '', 32);
const initVector = hashedKey.slice(16);
const securityKey = hashedKey.slice(0, 16);
return crypto.createCipheriv(algorithm, securityKey, initVector);
},
aes192 (key) {
const hashedKey = crypto.scryptSync(key, '', 40);
const initVector = hashedKey.slice(24);
const securityKey = hashedKey.slice(0, 24);
return crypto.createCipheriv(algorithm, securityKey, initVector);
},
aes256 (key) {
const hashedKey = crypto.scryptSync(key, '', 48);
const initVector = hashedKey.slice(32);
const securityKey = hashedKey.slice(0, 32);
return crypto.createCipheriv(algorithm, securityKey, initVector);
}
};
return strategies[algorithm];
};
/**
* It creates a cipher instance used for encryption
*
* @param key - The encryption key
* @param algorithm - The algorithm to use to create the Cipher
*
* @returns A {@link Cipher} instance created with the given key & algorithm
*/ const createEncryptionCipher = (key, algorithm = 'aes-128-ecb')=>{
return getEncryptionStrategy(algorithm)(key);
};
exports.createEncryptionCipher = createEncryptionCipher;
//# sourceMappingURL=encrypt.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"encrypt.js","sources":["../../../src/utils/encryption/encrypt.ts"],"sourcesContent":["import { createCipheriv, Cipher, scryptSync, CipherKey, BinaryLike } from 'crypto';\nimport { EncryptionStrategy, Strategies, Algorithm } from '../../../types';\n\n// different key values depending on algorithm chosen\nconst getEncryptionStrategy = (algorithm: Algorithm): EncryptionStrategy => {\n const strategies: Strategies = {\n 'aes-128-ecb'(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 16);\n const initVector: BinaryLike | null = null;\n const securityKey: CipherKey = hashedKey;\n return createCipheriv(algorithm, securityKey, initVector);\n },\n aes128(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 32);\n const initVector: BinaryLike | null = hashedKey.slice(16);\n const securityKey: CipherKey = hashedKey.slice(0, 16);\n return createCipheriv(algorithm, securityKey, initVector);\n },\n aes192(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 40);\n const initVector: BinaryLike | null = hashedKey.slice(24);\n const securityKey: CipherKey = hashedKey.slice(0, 24);\n return createCipheriv(algorithm, securityKey, initVector);\n },\n aes256(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 48);\n const initVector: BinaryLike | null = hashedKey.slice(32);\n const securityKey: CipherKey = hashedKey.slice(0, 32);\n return createCipheriv(algorithm, securityKey, initVector);\n },\n };\n\n return strategies[algorithm];\n};\n\n/**\n * It creates a cipher instance used for encryption\n *\n * @param key - The encryption key\n * @param algorithm - The algorithm to use to create the Cipher\n *\n * @returns A {@link Cipher} instance created with the given key & algorithm\n */\nexport const createEncryptionCipher = (\n key: string,\n algorithm: Algorithm = 'aes-128-ecb'\n): Cipher => {\n return getEncryptionStrategy(algorithm)(key);\n};\n"],"names":["getEncryptionStrategy","algorithm","strategies","key","hashedKey","scryptSync","initVector","securityKey","createCipheriv","aes128","slice","aes192","aes256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ACtC,MAAMG,UAAAA,GAAgCF,SAAUM,CAAAA,KAAK,CAAC,EAAA,CAAA;AACtD,YAAA,MAAMH,WAAyBH,GAAAA,SAAAA,CAAUM,KAAK,CAAC,CAAG,EAAA,EAAA,CAAA;YAClD,OAAOF,qBAAAA,CAAeP,WAAWM,WAAaD,EAAAA,UAAAA,CAAAA;AAChD;AACF,KAAA;IAEA,OAAOJ,UAAU,CAACD,SAAU,CAAA;AAC9B,CAAA;AAEA;;;;;;;AAOC,IACYY,MAAAA,sBAAAA,GAAyB,CACpCV,GAAAA,EACAF,YAAuB,aAAa,GAAA;AAEpC,IAAA,OAAOD,sBAAsBC,SAAWE,CAAAA,CAAAA,GAAAA,CAAAA;AAC1C;;;;"}

View File

@@ -0,0 +1,45 @@
import { scryptSync, createCipheriv } from 'crypto';
// different key values depending on algorithm chosen
const getEncryptionStrategy = (algorithm)=>{
const strategies = {
'aes-128-ecb' (key) {
const hashedKey = scryptSync(key, '', 16);
const initVector = null;
const securityKey = hashedKey;
return createCipheriv(algorithm, securityKey, initVector);
},
aes128 (key) {
const hashedKey = scryptSync(key, '', 32);
const initVector = hashedKey.slice(16);
const securityKey = hashedKey.slice(0, 16);
return createCipheriv(algorithm, securityKey, initVector);
},
aes192 (key) {
const hashedKey = scryptSync(key, '', 40);
const initVector = hashedKey.slice(24);
const securityKey = hashedKey.slice(0, 24);
return createCipheriv(algorithm, securityKey, initVector);
},
aes256 (key) {
const hashedKey = scryptSync(key, '', 48);
const initVector = hashedKey.slice(32);
const securityKey = hashedKey.slice(0, 32);
return createCipheriv(algorithm, securityKey, initVector);
}
};
return strategies[algorithm];
};
/**
* It creates a cipher instance used for encryption
*
* @param key - The encryption key
* @param algorithm - The algorithm to use to create the Cipher
*
* @returns A {@link Cipher} instance created with the given key & algorithm
*/ const createEncryptionCipher = (key, algorithm = 'aes-128-ecb')=>{
return getEncryptionStrategy(algorithm)(key);
};
export { createEncryptionCipher };
//# sourceMappingURL=encrypt.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"encrypt.mjs","sources":["../../../src/utils/encryption/encrypt.ts"],"sourcesContent":["import { createCipheriv, Cipher, scryptSync, CipherKey, BinaryLike } from 'crypto';\nimport { EncryptionStrategy, Strategies, Algorithm } from '../../../types';\n\n// different key values depending on algorithm chosen\nconst getEncryptionStrategy = (algorithm: Algorithm): EncryptionStrategy => {\n const strategies: Strategies = {\n 'aes-128-ecb'(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 16);\n const initVector: BinaryLike | null = null;\n const securityKey: CipherKey = hashedKey;\n return createCipheriv(algorithm, securityKey, initVector);\n },\n aes128(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 32);\n const initVector: BinaryLike | null = hashedKey.slice(16);\n const securityKey: CipherKey = hashedKey.slice(0, 16);\n return createCipheriv(algorithm, securityKey, initVector);\n },\n aes192(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 40);\n const initVector: BinaryLike | null = hashedKey.slice(24);\n const securityKey: CipherKey = hashedKey.slice(0, 24);\n return createCipheriv(algorithm, securityKey, initVector);\n },\n aes256(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 48);\n const initVector: BinaryLike | null = hashedKey.slice(32);\n const securityKey: CipherKey = hashedKey.slice(0, 32);\n return createCipheriv(algorithm, securityKey, initVector);\n },\n };\n\n return strategies[algorithm];\n};\n\n/**\n * It creates a cipher instance used for encryption\n *\n * @param key - The encryption key\n * @param algorithm - The algorithm to use to create the Cipher\n *\n * @returns A {@link Cipher} instance created with the given key & algorithm\n */\nexport const createEncryptionCipher = (\n key: string,\n algorithm: Algorithm = 'aes-128-ecb'\n): Cipher => {\n return getEncryptionStrategy(algorithm)(key);\n};\n"],"names":["getEncryptionStrategy","algorithm","strategies","key","hashedKey","scryptSync","initVector","securityKey","createCipheriv","aes128","slice","aes192","aes256","createEncryptionCipher"],"mappings":";;AAGA;AACA,MAAMA,wBAAwB,CAACC,SAAAA,GAAAA;AAC7B,IAAA,MAAMC,UAAyB,GAAA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M,KAAK,CAAC,CAAG,EAAA,EAAA,CAAA;YAClD,OAAOF,cAAAA,CAAeP,WAAWM,WAAaD,EAAAA,UAAAA,CAAAA;AAChD;AACF,KAAA;IAEA,OAAOJ,UAAU,CAACD,SAAU,CAAA;AAC9B,CAAA;AAEA;;;;;;;AAOC,IACYY,MAAAA,sBAAAA,GAAyB,CACpCV,GAAAA,EACAF,YAAuB,aAAa,GAAA;AAEpC,IAAA,OAAOD,sBAAsBC,SAAWE,CAAAA,CAAAA,GAAAA,CAAAA;AAC1C;;;;"}

View File

@@ -0,0 +1,3 @@
export * from './encrypt';
export * from './decrypt';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/encryption/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}

View File

@@ -0,0 +1,10 @@
'use strict';
var encrypt = require('./encrypt.js');
var decrypt = require('./decrypt.js');
exports.createEncryptionCipher = encrypt.createEncryptionCipher;
exports.createDecryptionCipher = decrypt.createDecryptionCipher;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}

View File

@@ -0,0 +1,3 @@
export { createEncryptionCipher } from './encrypt.mjs';
export { createDecryptionCipher } from './decrypt.mjs';
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}

View File

@@ -0,0 +1,8 @@
export * as encryption from './encryption';
export * as stream from './stream';
export * as json from './json';
export * as schema from './schema';
export * as transaction from './transaction';
export * as middleware from './middleware';
export * as diagnostics from './diagnostic';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC"}

View File

@@ -0,0 +1,20 @@
'use strict';
var index = require('./encryption/index.js');
var stream = require('./stream.js');
var json = require('./json.js');
var schema = require('./schema.js');
var transaction = require('./transaction.js');
var middleware = require('./middleware.js');
var diagnostic = require('./diagnostic.js');
exports.encryption = index;
exports.stream = stream;
exports.json = json;
exports.schema = schema;
exports.transaction = transaction;
exports.middleware = middleware;
exports.diagnostics = diagnostic;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}

View File

@@ -0,0 +1,15 @@
import * as index from './encryption/index.mjs';
export { index as encryption };
import * as stream from './stream.mjs';
export { stream };
import * as json from './json.mjs';
export { json };
import * as schema from './schema.mjs';
export { schema };
import * as transaction from './transaction.mjs';
export { transaction };
import * as middleware from './middleware.mjs';
export { middleware };
import * as diagnostic from './diagnostic.mjs';
export { diagnostic as diagnostics };
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}

View File

@@ -0,0 +1,31 @@
/**
* Compute differences between two JSON objects and returns them
*
* @param a - First object
* @param b - Second object
* @param ctx - Context used to keep track of the current path during recursion
*/
export declare const diff: (a: unknown, b: unknown, ctx?: Context) => Diff[];
export interface AddedDiff<T = unknown> {
kind: 'added';
path: string[];
type: string;
value: T;
}
export interface ModifiedDiff<T = unknown, P = unknown> {
kind: 'modified';
path: string[];
types: [string, string];
values: [T, P];
}
export interface DeletedDiff<T = unknown> {
kind: 'deleted';
path: string[];
type: string;
value: T;
}
export type Diff<T = unknown> = AddedDiff<T> | ModifiedDiff<T> | DeletedDiff<T>;
export interface Context {
path: string[];
}
//# sourceMappingURL=json.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/utils/json.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,MAAO,OAAO,KAAK,OAAO,QAAO,OAAO,KAAqB,IAAI,EAwEjF,CAAC;AAEF,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACpC,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,CAAC,CAAC;CACV;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO;IACpD,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAChB;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO;IACtC,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,CAAC,CAAC;CACV;AAED,MAAM,MAAM,IAAI,CAAC,CAAC,GAAG,OAAO,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAEhF,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB"}

View File

@@ -0,0 +1,96 @@
'use strict';
var fp = require('lodash/fp');
const createContext = ()=>({
path: []
});
/**
* Compute differences between two JSON objects and returns them
*
* @param a - First object
* @param b - Second object
* @param ctx - Context used to keep track of the current path during recursion
*/ const diff = (a, b, ctx = createContext())=>{
const diffs = [];
const { path } = ctx;
const aType = typeof a;
const bType = typeof b;
// Define helpers
const added = ()=>{
diffs.push({
kind: 'added',
path,
type: bType,
value: b
});
return diffs;
};
const deleted = ()=>{
diffs.push({
kind: 'deleted',
path,
type: aType,
value: a
});
return diffs;
};
const modified = ()=>{
diffs.push({
kind: 'modified',
path,
types: [
aType,
bType
],
values: [
a,
b
]
});
return diffs;
};
if (fp.isArray(a) && fp.isArray(b)) {
let k = 0;
for (const [aItem, bItem] of fp.zip(a, b)){
const kCtx = {
path: [
...path,
k.toString()
]
};
const kDiffs = diff(aItem, bItem, kCtx);
diffs.push(...kDiffs);
k += 1;
}
return diffs;
}
if (fp.isObject(a) && fp.isObject(b)) {
const keys = fp.uniq(Object.keys(a).concat(Object.keys(b)));
for (const key of keys){
const aValue = a[key];
const bValue = b[key];
const nestedDiffs = diff(aValue, bValue, {
path: [
...path,
key
]
});
diffs.push(...nestedDiffs);
}
return diffs;
}
if (!fp.isEqual(a, b)) {
if (aType === 'undefined') {
return added();
}
if (bType === 'undefined') {
return deleted();
}
return modified();
}
return diffs;
};
exports.diff = diff;
//# sourceMappingURL=json.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,94 @@
import { isArray, zip, isObject, uniq, isEqual } from 'lodash/fp';
const createContext = ()=>({
path: []
});
/**
* Compute differences between two JSON objects and returns them
*
* @param a - First object
* @param b - Second object
* @param ctx - Context used to keep track of the current path during recursion
*/ const diff = (a, b, ctx = createContext())=>{
const diffs = [];
const { path } = ctx;
const aType = typeof a;
const bType = typeof b;
// Define helpers
const added = ()=>{
diffs.push({
kind: 'added',
path,
type: bType,
value: b
});
return diffs;
};
const deleted = ()=>{
diffs.push({
kind: 'deleted',
path,
type: aType,
value: a
});
return diffs;
};
const modified = ()=>{
diffs.push({
kind: 'modified',
path,
types: [
aType,
bType
],
values: [
a,
b
]
});
return diffs;
};
if (isArray(a) && isArray(b)) {
let k = 0;
for (const [aItem, bItem] of zip(a, b)){
const kCtx = {
path: [
...path,
k.toString()
]
};
const kDiffs = diff(aItem, bItem, kCtx);
diffs.push(...kDiffs);
k += 1;
}
return diffs;
}
if (isObject(a) && isObject(b)) {
const keys = uniq(Object.keys(a).concat(Object.keys(b)));
for (const key of keys){
const aValue = a[key];
const bValue = b[key];
const nestedDiffs = diff(aValue, bValue, {
path: [
...path,
key
]
});
diffs.push(...nestedDiffs);
}
return diffs;
}
if (!isEqual(a, b)) {
if (aType === 'undefined') {
return added();
}
if (bType === 'undefined') {
return deleted();
}
return modified();
}
return diffs;
};
export { diff };
//# sourceMappingURL=json.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
import { Middleware } from '../../types';
export declare const runMiddleware: <T>(context: T, middlewares: Middleware<T>[]) => Promise<void>;
//# sourceMappingURL=middleware.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/utils/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,eAAO,MAAM,aAAa,eAAsB,CAAC,eAAe,WAAW,CAAC,CAAC,EAAE,KAAG,QAAQ,IAAI,CAQ7F,CAAC"}

View File

@@ -0,0 +1,14 @@
'use strict';
const runMiddleware = async (context, middlewares)=>{
if (!middlewares.length) {
return;
}
const cb = middlewares[0];
await cb(context, async (newContext)=>{
await runMiddleware(newContext, middlewares.slice(1));
});
};
exports.runMiddleware = runMiddleware;
//# sourceMappingURL=middleware.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"middleware.js","sources":["../../src/utils/middleware.ts"],"sourcesContent":["import { Middleware } from '../../types';\n\nexport const runMiddleware = async <T>(context: T, middlewares: Middleware<T>[]): Promise<void> => {\n if (!middlewares.length) {\n return;\n }\n const cb = middlewares[0];\n await cb(context, async (newContext: T) => {\n await runMiddleware(newContext, middlewares.slice(1));\n });\n};\n"],"names":["runMiddleware","context","middlewares","length","cb","newContext","slice"],"mappings":";;AAEO,MAAMA,aAAgB,GAAA,OAAUC,OAAYC,EAAAA,WAAAA,GAAAA;IACjD,IAAI,CAACA,WAAYC,CAAAA,MAAM,EAAE;AACvB,QAAA;AACF;IACA,MAAMC,EAAAA,GAAKF,WAAW,CAAC,CAAE,CAAA;IACzB,MAAME,EAAAA,CAAGH,SAAS,OAAOI,UAAAA,GAAAA;AACvB,QAAA,MAAML,aAAcK,CAAAA,UAAAA,EAAYH,WAAYI,CAAAA,KAAK,CAAC,CAAA,CAAA,CAAA;AACpD,KAAA,CAAA;AACF;;;;"}

View File

@@ -0,0 +1,12 @@
const runMiddleware = async (context, middlewares)=>{
if (!middlewares.length) {
return;
}
const cb = middlewares[0];
await cb(context, async (newContext)=>{
await runMiddleware(newContext, middlewares.slice(1));
});
};
export { runMiddleware };
//# sourceMappingURL=middleware.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"middleware.mjs","sources":["../../src/utils/middleware.ts"],"sourcesContent":["import { Middleware } from '../../types';\n\nexport const runMiddleware = async <T>(context: T, middlewares: Middleware<T>[]): Promise<void> => {\n if (!middlewares.length) {\n return;\n }\n const cb = middlewares[0];\n await cb(context, async (newContext: T) => {\n await runMiddleware(newContext, middlewares.slice(1));\n });\n};\n"],"names":["runMiddleware","context","middlewares","length","cb","newContext","slice"],"mappings":"AAEO,MAAMA,aAAgB,GAAA,OAAUC,OAAYC,EAAAA,WAAAA,GAAAA;IACjD,IAAI,CAACA,WAAYC,CAAAA,MAAM,EAAE;AACvB,QAAA;AACF;IACA,MAAMC,EAAAA,GAAKF,WAAW,CAAC,CAAE,CAAA;IACzB,MAAME,EAAAA,CAAGH,SAAS,OAAOI,UAAAA,GAAAA;AACvB,QAAA,MAAML,aAAcK,CAAAA,UAAAA,EAAYH,WAAYI,CAAAA,KAAK,CAAC,CAAA,CAAA,CAAA;AACpD,KAAA,CAAA;AACF;;;;"}

View File

@@ -0,0 +1,4 @@
import type { Core } from '@strapi/types';
export type ValidStrapiAssertion = (strapi: unknown, msg?: string) => asserts strapi is Core.Strapi;
export declare const assertValidStrapi: ValidStrapiAssertion;
//# sourceMappingURL=providers.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/utils/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAI1C,MAAM,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;AAEpG,eAAO,MAAM,iBAAiB,EAAE,oBAI/B,CAAC"}

View File

@@ -0,0 +1,12 @@
'use strict';
var providers = require('../errors/providers.js');
const assertValidStrapi = (strapi, msg = '')=>{
if (!strapi) {
throw new providers.ProviderInitializationError(`${msg}. Strapi instance not found.`);
}
};
exports.assertValidStrapi = assertValidStrapi;
//# sourceMappingURL=providers.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"providers.js","sources":["../../src/utils/providers.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nimport { ProviderInitializationError } from '../errors/providers';\n\nexport type ValidStrapiAssertion = (strapi: unknown, msg?: string) => asserts strapi is Core.Strapi;\n\nexport const assertValidStrapi: ValidStrapiAssertion = (strapi?: unknown, msg = '') => {\n if (!strapi) {\n throw new ProviderInitializationError(`${msg}. Strapi instance not found.`);\n }\n};\n"],"names":["assertValidStrapi","strapi","msg","ProviderInitializationError"],"mappings":";;;;AAMaA,MAAAA,iBAAAA,GAA0C,CAACC,MAAAA,EAAkBC,MAAM,EAAE,GAAA;AAChF,IAAA,IAAI,CAACD,MAAQ,EAAA;AACX,QAAA,MAAM,IAAIE,qCAA4B,CAAA,CAAC,EAAED,GAAAA,CAAI,4BAA4B,CAAC,CAAA;AAC5E;AACF;;;;"}

View File

@@ -0,0 +1,10 @@
import { ProviderInitializationError } from '../errors/providers.mjs';
const assertValidStrapi = (strapi, msg = '')=>{
if (!strapi) {
throw new ProviderInitializationError(`${msg}. Strapi instance not found.`);
}
};
export { assertValidStrapi };
//# sourceMappingURL=providers.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"providers.mjs","sources":["../../src/utils/providers.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nimport { ProviderInitializationError } from '../errors/providers';\n\nexport type ValidStrapiAssertion = (strapi: unknown, msg?: string) => asserts strapi is Core.Strapi;\n\nexport const assertValidStrapi: ValidStrapiAssertion = (strapi?: unknown, msg = '') => {\n if (!strapi) {\n throw new ProviderInitializationError(`${msg}. Strapi instance not found.`);\n }\n};\n"],"names":["assertValidStrapi","strapi","msg","ProviderInitializationError"],"mappings":";;AAMaA,MAAAA,iBAAAA,GAA0C,CAACC,MAAAA,EAAkBC,MAAM,EAAE,GAAA;AAChF,IAAA,IAAI,CAACD,MAAQ,EAAA;AACX,QAAA,MAAM,IAAIE,2BAA4B,CAAA,CAAC,EAAED,GAAAA,CAAI,4BAA4B,CAAC,CAAA;AAC5E;AACF;;;;"}

View File

@@ -0,0 +1,8 @@
import type { Struct, Utils } from '@strapi/types';
/**
* Sanitize a schemas dictionary by omitting unwanted properties
* The list of allowed properties can be found here: {@link VALID_SCHEMA_PROPERTIES}
*/
export declare const mapSchemasValues: (schemas: Utils.String.Dict<Struct.Schema>) => Utils.String.Dict<Struct.Schema>;
export declare const schemasToValidJSON: (schemas: Utils.String.Dict<Struct.Schema>) => any;
//# sourceMappingURL=schema.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/utils/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAoBnD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,YAAa,YAAY,CAAC,IAAI,CAAC,OAAO,MAAM,CAAC,qCAEzE,CAAC;AAEF,eAAO,MAAM,kBAAkB,YAAa,YAAY,CAAC,IAAI,CAAC,OAAO,MAAM,CAAC,QAE3E,CAAC"}

View File

@@ -0,0 +1,32 @@
'use strict';
var fp = require('lodash/fp');
/**
* List of schema properties that should be kept when sanitizing schemas
*/ const VALID_SCHEMA_PROPERTIES = [
'collectionName',
'info',
'options',
'pluginOptions',
'attributes',
'kind',
'modelType',
'modelName',
'uid',
'plugin',
'globalId'
];
/**
* Sanitize a schemas dictionary by omitting unwanted properties
* The list of allowed properties can be found here: {@link VALID_SCHEMA_PROPERTIES}
*/ const mapSchemasValues = (schemas)=>{
return fp.mapValues(fp.pick(VALID_SCHEMA_PROPERTIES), schemas);
};
const schemasToValidJSON = (schemas)=>{
return JSON.parse(JSON.stringify(schemas));
};
exports.mapSchemasValues = mapSchemasValues;
exports.schemasToValidJSON = schemasToValidJSON;
//# sourceMappingURL=schema.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"schema.js","sources":["../../src/utils/schema.ts"],"sourcesContent":["import type { Struct, Utils } from '@strapi/types';\nimport { mapValues, pick } from 'lodash/fp';\n\n/**\n * List of schema properties that should be kept when sanitizing schemas\n */\nconst VALID_SCHEMA_PROPERTIES = [\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n 'modelType',\n 'modelName',\n 'uid',\n 'plugin',\n 'globalId',\n];\n\n/**\n * Sanitize a schemas dictionary by omitting unwanted properties\n * The list of allowed properties can be found here: {@link VALID_SCHEMA_PROPERTIES}\n */\nexport const mapSchemasValues = (schemas: Utils.String.Dict<Struct.Schema>) => {\n return mapValues(pick(VALID_SCHEMA_PROPERTIES), schemas) as Utils.String.Dict<Struct.Schema>;\n};\n\nexport const schemasToValidJSON = (schemas: Utils.String.Dict<Struct.Schema>) => {\n return JSON.parse(JSON.stringify(schemas));\n};\n"],"names":["VALID_SCHEMA_PROPERTIES","mapSchemasValues","schemas","mapValues","pick","schemasToValidJSON","JSON","parse","stringify"],"mappings":";;;;AAGA;;AAEC,IACD,MAAMA,uBAA0B,GAAA;AAC9B,IAAA,gBAAA;AACA,IAAA,MAAA;AACA,IAAA,SAAA;AACA,IAAA,eAAA;AACA,IAAA,YAAA;AACA,IAAA,MAAA;AACA,IAAA,WAAA;AACA,IAAA,WAAA;AACA,IAAA,KAAA;AACA,IAAA,QAAA;AACA,IAAA;AACD,CAAA;AAED;;;IAIaC,MAAAA,gBAAAA,GAAmB,CAACC,OAAAA,GAAAA;IAC/B,OAAOC,YAAAA,CAAUC,QAAKJ,uBAA0BE,CAAAA,EAAAA,OAAAA,CAAAA;AAClD;AAEO,MAAMG,qBAAqB,CAACH,OAAAA,GAAAA;AACjC,IAAA,OAAOI,IAAKC,CAAAA,KAAK,CAACD,IAAAA,CAAKE,SAAS,CAACN,OAAAA,CAAAA,CAAAA;AACnC;;;;;"}

View File

@@ -0,0 +1,29 @@
import { mapValues, pick } from 'lodash/fp';
/**
* List of schema properties that should be kept when sanitizing schemas
*/ const VALID_SCHEMA_PROPERTIES = [
'collectionName',
'info',
'options',
'pluginOptions',
'attributes',
'kind',
'modelType',
'modelName',
'uid',
'plugin',
'globalId'
];
/**
* Sanitize a schemas dictionary by omitting unwanted properties
* The list of allowed properties can be found here: {@link VALID_SCHEMA_PROPERTIES}
*/ const mapSchemasValues = (schemas)=>{
return mapValues(pick(VALID_SCHEMA_PROPERTIES), schemas);
};
const schemasToValidJSON = (schemas)=>{
return JSON.parse(JSON.stringify(schemas));
};
export { mapSchemasValues, schemasToValidJSON };
//# sourceMappingURL=schema.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"schema.mjs","sources":["../../src/utils/schema.ts"],"sourcesContent":["import type { Struct, Utils } from '@strapi/types';\nimport { mapValues, pick } from 'lodash/fp';\n\n/**\n * List of schema properties that should be kept when sanitizing schemas\n */\nconst VALID_SCHEMA_PROPERTIES = [\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n 'modelType',\n 'modelName',\n 'uid',\n 'plugin',\n 'globalId',\n];\n\n/**\n * Sanitize a schemas dictionary by omitting unwanted properties\n * The list of allowed properties can be found here: {@link VALID_SCHEMA_PROPERTIES}\n */\nexport const mapSchemasValues = (schemas: Utils.String.Dict<Struct.Schema>) => {\n return mapValues(pick(VALID_SCHEMA_PROPERTIES), schemas) as Utils.String.Dict<Struct.Schema>;\n};\n\nexport const schemasToValidJSON = (schemas: Utils.String.Dict<Struct.Schema>) => {\n return JSON.parse(JSON.stringify(schemas));\n};\n"],"names":["VALID_SCHEMA_PROPERTIES","mapSchemasValues","schemas","mapValues","pick","schemasToValidJSON","JSON","parse","stringify"],"mappings":";;AAGA;;AAEC,IACD,MAAMA,uBAA0B,GAAA;AAC9B,IAAA,gBAAA;AACA,IAAA,MAAA;AACA,IAAA,SAAA;AACA,IAAA,eAAA;AACA,IAAA,YAAA;AACA,IAAA,MAAA;AACA,IAAA,WAAA;AACA,IAAA,WAAA;AACA,IAAA,KAAA;AACA,IAAA,QAAA;AACA,IAAA;AACD,CAAA;AAED;;;IAIaC,MAAAA,gBAAAA,GAAmB,CAACC,OAAAA,GAAAA;IAC/B,OAAOC,SAAAA,CAAUC,KAAKJ,uBAA0BE,CAAAA,EAAAA,OAAAA,CAAAA;AAClD;AAEO,MAAMG,qBAAqB,CAACH,OAAAA,GAAAA;AACjC,IAAA,OAAOI,IAAKC,CAAAA,KAAK,CAACD,IAAAA,CAAKE,SAAS,CAACN,OAAAA,CAAAA,CAAAA;AACnC;;;;"}

View File

@@ -0,0 +1,28 @@
/// <reference types="node" />
import { Transform, Readable } from 'stream';
type TransformOptions = ConstructorParameters<typeof Transform>[0];
/**
* Create a filter stream that discard chunks which doesn't satisfies the given predicate
*
* @param predicate - A filter predicate, takes a stream data chunk as parameter and returns a boolean value
* @param options - Transform stream options
*/
export declare const filter: <T>(predicate: (value: T) => boolean | Promise<boolean>, options?: TransformOptions) => Transform;
/**
* Create a map stream that transform chunks using the given predicate
*
* @param predicate - A map predicate, takes a stream data chunk as parameter and returns a mapped value
* @param options - Transform stream options
*/
export declare const map: <T, U = T>(predicate: (value: T) => U | Promise<U>, options?: TransformOptions) => Transform;
/**
* Collect every chunks from a Readable stream.
*
* @param stream - The redable stream to collect data from
* @param options.destroy - If set to true, it automatically calls `destroy()` on the given stream upon receiving the 'end' event
*/
export declare const collect: <T = unknown>(stream: Readable, options?: {
destroy: boolean;
}) => Promise<T[]>;
export {};
//# sourceMappingURL=stream.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE7C,KAAK,gBAAgB,GAAG,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnE;;;;;GAKG;AACH,eAAO,MAAM,MAAM,iBACN,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAAG,QAAQ,OAAO,CAAC,YAC1C,gBAAgB,KACxB,SAUF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,GAAG,wBACH,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAC,YAC9B,gBAAgB,KACxB,SAUF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,OAAO,wBACV,QAAQ,YACP;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,KAC5B,QAAQ,CAAC,EAAE,CAgBb,CAAC"}

View File

@@ -0,0 +1,59 @@
'use strict';
var stream = require('stream');
/**
* Create a filter stream that discard chunks which doesn't satisfies the given predicate
*
* @param predicate - A filter predicate, takes a stream data chunk as parameter and returns a boolean value
* @param options - Transform stream options
*/ const filter = (predicate, options = {
objectMode: true
})=>{
return new stream.Transform({
...options,
async transform (chunk, _encoding, callback) {
const keep = await predicate(chunk);
callback(null, keep ? chunk : undefined);
}
});
};
/**
* Create a map stream that transform chunks using the given predicate
*
* @param predicate - A map predicate, takes a stream data chunk as parameter and returns a mapped value
* @param options - Transform stream options
*/ const map = (predicate, options = {
objectMode: true
})=>{
return new stream.Transform({
...options,
async transform (chunk, _encoding, callback) {
const mappedValue = await predicate(chunk);
callback(null, mappedValue);
}
});
};
/**
* Collect every chunks from a Readable stream.
*
* @param stream - The redable stream to collect data from
* @param options.destroy - If set to true, it automatically calls `destroy()` on the given stream upon receiving the 'end' event
*/ const collect = (stream, options = {
destroy: true
})=>{
const chunks = [];
return new Promise((resolve, reject)=>{
stream.on('close', ()=>resolve(chunks)).on('error', reject).on('data', (chunk)=>chunks.push(chunk)).on('end', ()=>{
if (options.destroy) {
stream.destroy();
}
resolve(chunks);
});
});
};
exports.collect = collect;
exports.filter = filter;
exports.map = map;
//# sourceMappingURL=stream.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"stream.js","sources":["../../src/utils/stream.ts"],"sourcesContent":["import { Transform, Readable } from 'stream';\n\ntype TransformOptions = ConstructorParameters<typeof Transform>[0];\n\n/**\n * Create a filter stream that discard chunks which doesn't satisfies the given predicate\n *\n * @param predicate - A filter predicate, takes a stream data chunk as parameter and returns a boolean value\n * @param options - Transform stream options\n */\nexport const filter = <T>(\n predicate: (value: T) => boolean | Promise<boolean>,\n options: TransformOptions = { objectMode: true }\n): Transform => {\n return new Transform({\n ...options,\n\n async transform(chunk, _encoding, callback) {\n const keep = await predicate(chunk);\n\n callback(null, keep ? chunk : undefined);\n },\n });\n};\n\n/**\n * Create a map stream that transform chunks using the given predicate\n *\n * @param predicate - A map predicate, takes a stream data chunk as parameter and returns a mapped value\n * @param options - Transform stream options\n */\nexport const map = <T, U = T>(\n predicate: (value: T) => U | Promise<U>,\n options: TransformOptions = { objectMode: true }\n): Transform => {\n return new Transform({\n ...options,\n\n async transform(chunk, _encoding, callback) {\n const mappedValue = await predicate(chunk);\n\n callback(null, mappedValue);\n },\n });\n};\n\n/**\n * Collect every chunks from a Readable stream.\n *\n * @param stream - The redable stream to collect data from\n * @param options.destroy - If set to true, it automatically calls `destroy()` on the given stream upon receiving the 'end' event\n */\nexport const collect = <T = unknown>(\n stream: Readable,\n options: { destroy: boolean } = { destroy: true }\n): Promise<T[]> => {\n const chunks: T[] = [];\n\n return new Promise((resolve, reject) => {\n stream\n .on('close', () => resolve(chunks))\n .on('error', reject)\n .on('data', (chunk) => chunks.push(chunk))\n .on('end', () => {\n if (options.destroy) {\n stream.destroy();\n }\n\n resolve(chunks);\n });\n });\n};\n"],"names":["filter","predicate","options","objectMode","Transform","transform","chunk","_encoding","callback","keep","undefined","map","mappedValue","collect","stream","destroy","chunks","Promise","resolve","reject","on","push"],"mappings":";;;;AAIA;;;;;AAKC,IACM,MAAMA,MAAS,GAAA,CACpBC,WACAC,OAA4B,GAAA;IAAEC,UAAY,EAAA;AAAK,CAAC,GAAA;AAEhD,IAAA,OAAO,IAAIC,gBAAU,CAAA;AACnB,QAAA,GAAGF,OAAO;AAEV,QAAA,MAAMG,SAAUC,CAAAA,CAAAA,KAAK,EAAEC,SAAS,EAAEC,QAAQ,EAAA;YACxC,MAAMC,IAAAA,GAAO,MAAMR,SAAUK,CAAAA,KAAAA,CAAAA;YAE7BE,QAAS,CAAA,IAAA,EAAMC,OAAOH,KAAQI,GAAAA,SAAAA,CAAAA;AAChC;AACF,KAAA,CAAA;AACF;AAEA;;;;;AAKC,IACM,MAAMC,GAAM,GAAA,CACjBV,WACAC,OAA4B,GAAA;IAAEC,UAAY,EAAA;AAAK,CAAC,GAAA;AAEhD,IAAA,OAAO,IAAIC,gBAAU,CAAA;AACnB,QAAA,GAAGF,OAAO;AAEV,QAAA,MAAMG,SAAUC,CAAAA,CAAAA,KAAK,EAAEC,SAAS,EAAEC,QAAQ,EAAA;YACxC,MAAMI,WAAAA,GAAc,MAAMX,SAAUK,CAAAA,KAAAA,CAAAA;AAEpCE,YAAAA,QAAAA,CAAS,IAAMI,EAAAA,WAAAA,CAAAA;AACjB;AACF,KAAA,CAAA;AACF;AAEA;;;;;AAKC,IACM,MAAMC,OAAU,GAAA,CACrBC,QACAZ,OAAgC,GAAA;IAAEa,OAAS,EAAA;AAAK,CAAC,GAAA;AAEjD,IAAA,MAAMC,SAAc,EAAE;IAEtB,OAAO,IAAIC,OAAQ,CAAA,CAACC,OAASC,EAAAA,MAAAA,GAAAA;QAC3BL,MACGM,CAAAA,EAAE,CAAC,OAAS,EAAA,IAAMF,QAAQF,MAC1BI,CAAAA,CAAAA,CAAAA,EAAE,CAAC,OAASD,EAAAA,MAAAA,CAAAA,CACZC,EAAE,CAAC,MAAA,EAAQ,CAACd,KAAUU,GAAAA,MAAAA,CAAOK,IAAI,CAACf,KAAAA,CAAAA,CAAAA,CAClCc,EAAE,CAAC,KAAO,EAAA,IAAA;YACT,IAAIlB,OAAAA,CAAQa,OAAO,EAAE;AACnBD,gBAAAA,MAAAA,CAAOC,OAAO,EAAA;AAChB;YAEAG,OAAQF,CAAAA,MAAAA,CAAAA;AACV,SAAA,CAAA;AACJ,KAAA,CAAA;AACF;;;;;;"}

View File

@@ -0,0 +1,55 @@
import { Transform } from 'stream';
/**
* Create a filter stream that discard chunks which doesn't satisfies the given predicate
*
* @param predicate - A filter predicate, takes a stream data chunk as parameter and returns a boolean value
* @param options - Transform stream options
*/ const filter = (predicate, options = {
objectMode: true
})=>{
return new Transform({
...options,
async transform (chunk, _encoding, callback) {
const keep = await predicate(chunk);
callback(null, keep ? chunk : undefined);
}
});
};
/**
* Create a map stream that transform chunks using the given predicate
*
* @param predicate - A map predicate, takes a stream data chunk as parameter and returns a mapped value
* @param options - Transform stream options
*/ const map = (predicate, options = {
objectMode: true
})=>{
return new Transform({
...options,
async transform (chunk, _encoding, callback) {
const mappedValue = await predicate(chunk);
callback(null, mappedValue);
}
});
};
/**
* Collect every chunks from a Readable stream.
*
* @param stream - The redable stream to collect data from
* @param options.destroy - If set to true, it automatically calls `destroy()` on the given stream upon receiving the 'end' event
*/ const collect = (stream, options = {
destroy: true
})=>{
const chunks = [];
return new Promise((resolve, reject)=>{
stream.on('close', ()=>resolve(chunks)).on('error', reject).on('data', (chunk)=>chunks.push(chunk)).on('end', ()=>{
if (options.destroy) {
stream.destroy();
}
resolve(chunks);
});
});
};
export { collect, filter, map };
//# sourceMappingURL=stream.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"stream.mjs","sources":["../../src/utils/stream.ts"],"sourcesContent":["import { Transform, Readable } from 'stream';\n\ntype TransformOptions = ConstructorParameters<typeof Transform>[0];\n\n/**\n * Create a filter stream that discard chunks which doesn't satisfies the given predicate\n *\n * @param predicate - A filter predicate, takes a stream data chunk as parameter and returns a boolean value\n * @param options - Transform stream options\n */\nexport const filter = <T>(\n predicate: (value: T) => boolean | Promise<boolean>,\n options: TransformOptions = { objectMode: true }\n): Transform => {\n return new Transform({\n ...options,\n\n async transform(chunk, _encoding, callback) {\n const keep = await predicate(chunk);\n\n callback(null, keep ? chunk : undefined);\n },\n });\n};\n\n/**\n * Create a map stream that transform chunks using the given predicate\n *\n * @param predicate - A map predicate, takes a stream data chunk as parameter and returns a mapped value\n * @param options - Transform stream options\n */\nexport const map = <T, U = T>(\n predicate: (value: T) => U | Promise<U>,\n options: TransformOptions = { objectMode: true }\n): Transform => {\n return new Transform({\n ...options,\n\n async transform(chunk, _encoding, callback) {\n const mappedValue = await predicate(chunk);\n\n callback(null, mappedValue);\n },\n });\n};\n\n/**\n * Collect every chunks from a Readable stream.\n *\n * @param stream - The redable stream to collect data from\n * @param options.destroy - If set to true, it automatically calls `destroy()` on the given stream upon receiving the 'end' event\n */\nexport const collect = <T = unknown>(\n stream: Readable,\n options: { destroy: boolean } = { destroy: true }\n): Promise<T[]> => {\n const chunks: T[] = [];\n\n return new Promise((resolve, reject) => {\n stream\n .on('close', () => resolve(chunks))\n .on('error', reject)\n .on('data', (chunk) => chunks.push(chunk))\n .on('end', () => {\n if (options.destroy) {\n stream.destroy();\n }\n\n resolve(chunks);\n });\n });\n};\n"],"names":["filter","predicate","options","objectMode","Transform","transform","chunk","_encoding","callback","keep","undefined","map","mappedValue","collect","stream","destroy","chunks","Promise","resolve","reject","on","push"],"mappings":";;AAIA;;;;;AAKC,IACM,MAAMA,MAAS,GAAA,CACpBC,WACAC,OAA4B,GAAA;IAAEC,UAAY,EAAA;AAAK,CAAC,GAAA;AAEhD,IAAA,OAAO,IAAIC,SAAU,CAAA;AACnB,QAAA,GAAGF,OAAO;AAEV,QAAA,MAAMG,SAAUC,CAAAA,CAAAA,KAAK,EAAEC,SAAS,EAAEC,QAAQ,EAAA;YACxC,MAAMC,IAAAA,GAAO,MAAMR,SAAUK,CAAAA,KAAAA,CAAAA;YAE7BE,QAAS,CAAA,IAAA,EAAMC,OAAOH,KAAQI,GAAAA,SAAAA,CAAAA;AAChC;AACF,KAAA,CAAA;AACF;AAEA;;;;;AAKC,IACM,MAAMC,GAAM,GAAA,CACjBV,WACAC,OAA4B,GAAA;IAAEC,UAAY,EAAA;AAAK,CAAC,GAAA;AAEhD,IAAA,OAAO,IAAIC,SAAU,CAAA;AACnB,QAAA,GAAGF,OAAO;AAEV,QAAA,MAAMG,SAAUC,CAAAA,CAAAA,KAAK,EAAEC,SAAS,EAAEC,QAAQ,EAAA;YACxC,MAAMI,WAAAA,GAAc,MAAMX,SAAUK,CAAAA,KAAAA,CAAAA;AAEpCE,YAAAA,QAAAA,CAAS,IAAMI,EAAAA,WAAAA,CAAAA;AACjB;AACF,KAAA,CAAA;AACF;AAEA;;;;;AAKC,IACM,MAAMC,OAAU,GAAA,CACrBC,QACAZ,OAAgC,GAAA;IAAEa,OAAS,EAAA;AAAK,CAAC,GAAA;AAEjD,IAAA,MAAMC,SAAc,EAAE;IAEtB,OAAO,IAAIC,OAAQ,CAAA,CAACC,OAASC,EAAAA,MAAAA,GAAAA;QAC3BL,MACGM,CAAAA,EAAE,CAAC,OAAS,EAAA,IAAMF,QAAQF,MAC1BI,CAAAA,CAAAA,CAAAA,EAAE,CAAC,OAASD,EAAAA,MAAAA,CAAAA,CACZC,EAAE,CAAC,MAAA,EAAQ,CAACd,KAAUU,GAAAA,MAAAA,CAAOK,IAAI,CAACf,KAAAA,CAAAA,CAAAA,CAClCc,EAAE,CAAC,KAAO,EAAA,IAAA;YACT,IAAIlB,OAAAA,CAAQa,OAAO,EAAE;AACnBD,gBAAAA,MAAAA,CAAOC,OAAO,EAAA;AAChB;YAEAG,OAAQF,CAAAA,MAAAA,CAAAA;AACV,SAAA,CAAA;AACJ,KAAA,CAAA;AACF;;;;"}

View File

@@ -0,0 +1,4 @@
import type { Core } from '@strapi/types';
import { Transaction } from '../../types/utils';
export declare const createTransaction: (strapi: Core.Strapi) => Transaction;
//# sourceMappingURL=transaction.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAuB,MAAM,mBAAmB,CAAC;AAErE,eAAO,MAAM,iBAAiB,WAAY,KAAK,MAAM,KAAG,WA2FvD,CAAC"}

View File

@@ -0,0 +1,93 @@
'use strict';
var events = require('events');
var crypto = require('crypto');
const createTransaction = (strapi)=>{
const fns = [];
let done = false;
let resume = null;
const e = new events.EventEmitter();
e.on('spawn', (uuid, cb)=>{
fns.push({
fn: cb,
uuid
});
resume?.();
});
e.on('close', ()=>{
e.removeAllListeners('rollback');
e.removeAllListeners('spawn');
done = true;
resume?.();
});
strapi.db.transaction(async ({ trx, rollback })=>{
e.once('rollback', async ()=>{
e.removeAllListeners('close');
e.removeAllListeners('spawn');
try {
await rollback();
e.emit('rollback_completed');
} catch {
e.emit('rollback_failed');
} finally{
done = true;
resume?.();
}
});
while(!done){
while(fns.length){
const item = fns.shift();
if (item) {
const { fn, uuid } = item;
try {
const res = await fn(trx);
e.emit(uuid, {
data: res
});
} catch (error) {
e.emit(uuid, {
error
});
}
}
}
if (!done && !fns.length) {
// eslint-disable-next-line @typescript-eslint/no-loop-func
await new Promise((resolve)=>{
resume = resolve;
});
}
}
});
return {
async attach (callback) {
const uuid = crypto.randomUUID();
e.emit('spawn', uuid, callback);
return new Promise((resolve, reject)=>{
e.on(uuid, ({ data, error })=>{
if (data) {
resolve(data);
}
if (error) {
reject(error);
}
resolve(undefined);
});
});
},
end () {
return e.emit('close');
},
rollback () {
return new Promise((resolve)=>{
e.emit('rollback');
e.once('rollback_failed', ()=>resolve(false));
e.once('rollback_completed', ()=>resolve(true));
});
}
};
};
exports.createTransaction = createTransaction;
//# sourceMappingURL=transaction.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,91 @@
import { EventEmitter } from 'events';
import { randomUUID } from 'crypto';
const createTransaction = (strapi)=>{
const fns = [];
let done = false;
let resume = null;
const e = new EventEmitter();
e.on('spawn', (uuid, cb)=>{
fns.push({
fn: cb,
uuid
});
resume?.();
});
e.on('close', ()=>{
e.removeAllListeners('rollback');
e.removeAllListeners('spawn');
done = true;
resume?.();
});
strapi.db.transaction(async ({ trx, rollback })=>{
e.once('rollback', async ()=>{
e.removeAllListeners('close');
e.removeAllListeners('spawn');
try {
await rollback();
e.emit('rollback_completed');
} catch {
e.emit('rollback_failed');
} finally{
done = true;
resume?.();
}
});
while(!done){
while(fns.length){
const item = fns.shift();
if (item) {
const { fn, uuid } = item;
try {
const res = await fn(trx);
e.emit(uuid, {
data: res
});
} catch (error) {
e.emit(uuid, {
error
});
}
}
}
if (!done && !fns.length) {
// eslint-disable-next-line @typescript-eslint/no-loop-func
await new Promise((resolve)=>{
resume = resolve;
});
}
}
});
return {
async attach (callback) {
const uuid = randomUUID();
e.emit('spawn', uuid, callback);
return new Promise((resolve, reject)=>{
e.on(uuid, ({ data, error })=>{
if (data) {
resolve(data);
}
if (error) {
reject(error);
}
resolve(undefined);
});
});
},
end () {
return e.emit('close');
},
rollback () {
return new Promise((resolve)=>{
e.emit('rollback');
e.once('rollback_failed', ()=>resolve(false));
e.once('rollback_completed', ()=>resolve(true));
});
}
};
};
export { createTransaction };
//# sourceMappingURL=transaction.mjs.map

File diff suppressed because one or more lines are too long