npm package diff
Package: @forge/storage
Versions: 1.5.15-experimental-10722bc - 1.6.0-next.0
File: package/out/entity-storage/custom-entity-transaction-api.js
Index: package/out/entity-storage/custom-entity-transaction-api.js
===================================================================
--- package/out/entity-storage/custom-entity-transaction-api.js
+++ package/out/entity-storage/custom-entity-transaction-api.js
@@ -1,171 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.CustomEntityTransactionBuilderWithAndOrCondition = exports.CustomEntityTransactionBuilderWithOrCondition = exports.CustomEntityTransactionBuilderWithAndCondition = exports.DefaultCustomEntityTransactionBuilder = void 0;
-class DefaultCustomEntityTransactionBuilder {
- globalStorage;
- entityName;
- transactionOptions;
- constructor(globalStorage, entityName, transactionOptions = {}) {
- this.globalStorage = globalStorage;
- this.entityName = entityName;
- this.transactionOptions = transactionOptions;
- this.transactionOptions = {
- ...transactionOptions
- };
- }
- getKeyWithEntityName(entity, key) {
- const keyWithEntityName = `${entity}-${key}`;
- return keyWithEntityName;
- }
- entity(name) {
- return new DefaultCustomEntityTransactionBuilder(this.globalStorage, name, {
- ...this.transactionOptions
- });
- }
- set(key, value) {
- const keyWithEntityName = this.getKeyWithEntityName(this.entityName, key);
- const input = {
- transactionType: 'set',
- key,
- value,
- entity: this.entityName
- };
- return new CustomEntityTransactionBuilderWithAndOrCondition(this.globalStorage, this.entityName, keyWithEntityName, {
- ...this.transactionOptions,
- [keyWithEntityName]: input
- });
- }
- delete(key) {
- const keyWithEntityName = this.getKeyWithEntityName(this.entityName, key);
- const input = {
- transactionType: 'delete',
- key,
- entity: this.entityName
- };
- return new CustomEntityTransactionBuilderWithAndOrCondition(this.globalStorage, this.entityName, keyWithEntityName, {
- ...this.transactionOptions,
- [keyWithEntityName]: input
- });
- }
- check(key) {
- const keyWithEntityName = this.getKeyWithEntityName(this.entityName, key);
- const input = {
- transactionType: 'check',
- key,
- entity: this.entityName
- };
- return new CustomEntityTransactionBuilderWithAndOrCondition(this.globalStorage, this.entityName, keyWithEntityName, {
- ...this.transactionOptions,
- [keyWithEntityName]: input
- });
- }
- async execute() {
- if (!Object.keys(this.transactionOptions).length) {
- throw new Error('Nothing to execute');
- }
- const transformedInput = {};
- Object.entries(this.transactionOptions).forEach(([_, value]) => {
- const { transactionType } = value;
- if (!transformedInput[transactionType]) {
- transformedInput[transactionType] = [];
- }
- const input = {
- key: value.key,
- entityName: value.entity
- };
- if (value.conditions?.length && value.conditionOperator) {
- input.conditions = {
- [value.conditionOperator]: value.conditions
- };
- }
- if (transactionType === 'set') {
- input.value = value.value;
- transformedInput[transactionType]?.push(input);
- }
- else {
- transformedInput[transactionType]?.push(input);
- }
- });
- await this.globalStorage.transaction(transformedInput, true);
- }
-}
-exports.DefaultCustomEntityTransactionBuilder = DefaultCustomEntityTransactionBuilder;
-class CustomEntityTransactionBuilderWithAndCondition extends DefaultCustomEntityTransactionBuilder {
- globalStorage;
- entityName;
- key;
- transactionOptions;
- constructor(globalStorage, entityName, key, transactionOptions = {}) {
- super(globalStorage, entityName, transactionOptions);
- this.globalStorage = globalStorage;
- this.entityName = entityName;
- this.key = key;
- this.transactionOptions = transactionOptions;
- this.transactionOptions = {
- ...transactionOptions
- };
- }
- andCondition(field, condition) {
- const newQueryOptions = {
- ...this.transactionOptions
- };
- newQueryOptions[this.key].conditions = [
- ...(newQueryOptions[this.key].conditions ?? []),
- { property: field, ...condition }
- ];
- newQueryOptions[this.key].conditionOperator = 'and';
- return new CustomEntityTransactionBuilderWithAndCondition(this.globalStorage, this.entityName, this.key, newQueryOptions);
- }
-}
-exports.CustomEntityTransactionBuilderWithAndCondition = CustomEntityTransactionBuilderWithAndCondition;
-class CustomEntityTransactionBuilderWithOrCondition extends DefaultCustomEntityTransactionBuilder {
- globalStorage;
- entityName;
- key;
- transactionOptions;
- constructor(globalStorage, entityName, key, transactionOptions = {}) {
- super(globalStorage, entityName, transactionOptions);
- this.globalStorage = globalStorage;
- this.entityName = entityName;
- this.key = key;
- this.transactionOptions = transactionOptions;
- this.transactionOptions = {
- ...transactionOptions
- };
- }
- orCondition(field, condition) {
- const newQueryOptions = {
- ...this.transactionOptions
- };
- newQueryOptions[this.key].conditions = [
- ...(newQueryOptions[this.key].conditions ?? []),
- { property: field, ...condition }
- ];
- newQueryOptions[this.key].conditionOperator = 'or';
- return new CustomEntityTransactionBuilderWithOrCondition(this.globalStorage, this.entityName, this.key, newQueryOptions);
- }
-}
-exports.CustomEntityTransactionBuilderWithOrCondition = CustomEntityTransactionBuilderWithOrCondition;
-class CustomEntityTransactionBuilderWithAndOrCondition extends DefaultCustomEntityTransactionBuilder {
- globalStorage;
- entityName;
- key;
- transactionOptions;
- constructor(globalStorage, entityName, key, transactionOptions = {}) {
- super(globalStorage, entityName, transactionOptions);
- this.globalStorage = globalStorage;
- this.entityName = entityName;
- this.key = key;
- this.transactionOptions = transactionOptions;
- this.transactionOptions = {
- ...transactionOptions
- };
- }
- andCondition(field, condition) {
- return new CustomEntityTransactionBuilderWithAndCondition(this.globalStorage, this.entityName, this.key, this.transactionOptions).andCondition(field, condition);
- }
- orCondition(field, condition) {
- return new CustomEntityTransactionBuilderWithOrCondition(this.globalStorage, this.entityName, this.key, this.transactionOptions).orCondition(field, condition);
- }
-}
-exports.CustomEntityTransactionBuilderWithAndOrCondition = CustomEntityTransactionBuilderWithAndOrCondition;