@agile-ts/core
Advanced tools
Comparing version 0.2.6 to 0.2.7
# Change Log | ||
## 0.2.7 | ||
### Patch Changes | ||
- 36b235a: #### ❗️ Breaking Change | ||
```ts | ||
MY_STATE.persist('persistKey'); -> MY_STATE.persist({key: 'persistKey'}); | ||
``` | ||
#### :rocket: New Feature | ||
- `core` | ||
- [#214](https://github.com/agile-ts/agile/pull/214) add migration callback ([@bennodev19](https://github.com/bennodev19)) | ||
#### :nail_care: Polish | ||
- `logger` | ||
- [#210](https://github.com/agile-ts/agile/pull/210) Refactor logger ([@bennodev19](https://github.com/bennodev19)) | ||
- `api`, `core`, `event`, `logger`, `multieditor`, `proxytree`, `react`, `utils`, `vue` | ||
- [#209](https://github.com/agile-ts/agile/pull/209) Outsource react hooks ([@bennodev19](https://github.com/bennodev19)) | ||
#### Committers: 1 | ||
- BennoDev ([@bennodev19](https://github.com/bennodev19)) | ||
- Updated dependencies [36b235a] | ||
- @agile-ts/logger@0.0.11 | ||
- @agile-ts/utils@0.0.11 | ||
## 0.2.6 | ||
@@ -4,0 +34,0 @@ |
@@ -7,5 +7,5 @@ import { Agile } from '../agile'; | ||
import { GroupIngestConfigInterface } from './group/group.observer'; | ||
import { StorageKey } from '../storages'; | ||
import { CreatePersistentConfigInterface } from '../storages'; | ||
import { CollectionPersistent } from './collection.persistent'; | ||
export declare class Collection<DataType extends Object = DefaultItem, GroupValueType = Array<ItemKey>> { | ||
export declare class Collection<DataType extends DefaultItem = DefaultItem> { | ||
agileInstance: () => Agile; | ||
@@ -46,3 +46,3 @@ config: CollectionConfigInterface; | ||
*/ | ||
constructor(agileInstance: Agile, config?: CollectionConfig<DataType>); | ||
constructor(agileInstance: Agile, config?: CreateCollectionConfig<DataType>); | ||
/** | ||
@@ -419,16 +419,4 @@ * Updates the key/name identifier of the Collection. | ||
*/ | ||
persist(config?: CollectionPersistentConfigInterface): this; | ||
persist(config?: CreatePersistentConfigInterface): this; | ||
/** | ||
* Preserves the Collection `value` in the corresponding external Storage. | ||
* | ||
* The specified key is used as the unique identifier for the Persistent. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/collection/methods/#persist) | ||
* | ||
* @public | ||
* @param key - Key/Name identifier of Persistent. | ||
* @param config - Configuration object | ||
*/ | ||
persist(key?: StorageKey, config?: CollectionPersistentConfigInterface): this; | ||
/** | ||
* Fires immediately after the persisted `value` | ||
@@ -583,3 +571,3 @@ * is loaded into the Collection from a corresponding external Storage. | ||
export declare type ItemKey = string | number; | ||
export interface CreateCollectionConfigInterface<DataType = DefaultItem> { | ||
export interface CreateCollectionConfigImpl<DataType extends DefaultItem = DefaultItem> { | ||
/** | ||
@@ -623,3 +611,3 @@ * Initial Groups of the Collection. | ||
} | ||
export declare type CollectionConfig<DataType extends Object = DefaultItem> = CreateCollectionConfigInterface<DataType> | ((collection: Collection<DataType>) => CreateCollectionConfigInterface<DataType>); | ||
export declare type CreateCollectionConfig<DataType extends DefaultItem = DefaultItem> = CreateCollectionConfigImpl<DataType> | ((collection: Collection<DataType>) => CreateCollectionConfigImpl<DataType>); | ||
export interface CollectionConfigInterface { | ||
@@ -690,26 +678,2 @@ /** | ||
} | ||
export interface CollectionPersistentConfigInterface { | ||
/** | ||
* Whether the Persistent should automatically load | ||
* the persisted value into the Collection after its instantiation. | ||
* @default true | ||
*/ | ||
loadValue?: boolean; | ||
/** | ||
* Key/Name identifier of Storages | ||
* in which the Collection value should be or is persisted. | ||
* @default [`defaultStorageKey`] | ||
*/ | ||
storageKeys?: StorageKey[]; | ||
/** | ||
* Key/Name identifier of the default Storage of the specified Storage keys. | ||
* | ||
* The Collection value is loaded from the default Storage by default | ||
* and is only loaded from the remaining Storages (`storageKeys`) | ||
* if the loading from the default Storage failed. | ||
* | ||
* @default first index of the specified Storage keys or the AgileTs default Storage key | ||
*/ | ||
defaultStorageKey?: StorageKey; | ||
} | ||
export interface RemoveItemsConfigInterface { | ||
@@ -716,0 +680,0 @@ /** |
import { Collection, CollectionKey, DefaultItem, ItemKey } from './collection'; | ||
import { Group, GroupKey } from './group'; | ||
import { CreatePersistentConfigInterface, Persistent, PersistentKey, StorageKey } from '../storages'; | ||
export declare class CollectionPersistent<DataType extends Object = DefaultItem> extends Persistent { | ||
export declare class CollectionPersistent<DataType extends DefaultItem = DefaultItem> extends Persistent { | ||
collection: () => Collection<DataType>; | ||
@@ -6,0 +6,0 @@ static defaultGroupSideEffectKey: string; |
import { CreateObserverConfigInterface, CreateRuntimeJobConfigInterface, IngestConfigInterface, Observer, RuntimeJob } from '../../runtime'; | ||
import { Group } from './index'; | ||
export declare class GroupObserver<DataType = any> extends Observer { | ||
import { DefaultItem } from '../collection'; | ||
export declare class GroupObserver<DataType extends DefaultItem = DefaultItem> extends Observer<DataType[]> { | ||
group: () => Group<DataType>; | ||
nextGroupOutput: DataType[]; | ||
nextGroupValue: DataType[]; | ||
/** | ||
@@ -7,0 +8,0 @@ * A Group Observer manages the subscriptions to Subscription Containers (UI-Components) |
@@ -1,7 +0,6 @@ | ||
import { EnhancedState, StateIngestConfigInterface, StateObserversInterface, StatePersistentConfigInterface } from '../../state'; | ||
import { CreateStatePersistentConfigInterface, EnhancedState, StateIngestConfigInterface, StateObserversInterface } from '../../state'; | ||
import { Collection, DefaultItem, ItemKey } from '../collection'; | ||
import { GroupIngestConfigInterface, GroupObserver } from './group.observer'; | ||
import { Item } from '../item'; | ||
import { PersistentKey } from '../../storages'; | ||
export declare class Group<DataType extends Object = DefaultItem, ValueType = Array<ItemKey>> extends EnhancedState<Array<ItemKey>> { | ||
export declare class Group<DataType extends DefaultItem = DefaultItem> extends EnhancedState<Array<ItemKey>> { | ||
collection: () => Collection<DataType>; | ||
@@ -112,14 +111,2 @@ static rebuildGroupSideEffectKey: string; | ||
/** | ||
* Preserves the Group `value` in the corresponding external Storage. | ||
* | ||
* The specified key is used as the unique identifier for the Persistent. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/state/methods/#persist) | ||
* | ||
* @public | ||
* @param key - Key/Name identifier of Persistent. | ||
* @param config - Configuration object | ||
*/ | ||
persist(key?: PersistentKey, config?: GroupPersistConfigInterface): this; | ||
/** | ||
* Rebuilds the output of the Group | ||
@@ -185,3 +172,3 @@ * and ingests it into the runtime. | ||
} | ||
export interface GroupPersistConfigInterface extends StatePersistentConfigInterface { | ||
export interface GroupPersistConfigInterface extends CreateStatePersistentConfigInterface { | ||
/** | ||
@@ -188,0 +175,0 @@ * Whether to format the specified Storage key following the Collection Group Storage key pattern. |
import { Agile } from '../agile'; | ||
import { Collection, CollectionConfig, DefaultItem } from './collection'; | ||
import { Collection, CreateCollectionConfig, DefaultItem } from './collection'; | ||
export * from './collection'; | ||
@@ -28,2 +28,2 @@ export * from './collection.persistent'; | ||
*/ | ||
export declare function createCollection<DataType extends Object = DefaultItem>(config?: CollectionConfig<DataType>, agileInstance?: Agile): Collection<DataType>; | ||
export declare function createCollection<DataType extends DefaultItem = DefaultItem>(config?: CreateCollectionConfig<DataType>, agileInstance?: Agile): Collection<DataType>; |
@@ -1,6 +0,5 @@ | ||
import { EnhancedState, StateKey, StatePersistentConfigInterface, StateRuntimeJobConfigInterface } from '../state'; | ||
import { CreateStatePersistentConfigInterface, EnhancedState, StateKey, StateRuntimeJobConfigInterface } from '../state'; | ||
import { Collection, DefaultItem } from './collection'; | ||
import { SelectorKey } from './selector'; | ||
import { PersistentKey } from '../storages'; | ||
export declare class Item<DataType extends Object = DefaultItem> extends EnhancedState<DataType> { | ||
export declare class Item<DataType extends DefaultItem = DefaultItem> extends EnhancedState<DataType> { | ||
collection: () => Collection<DataType>; | ||
@@ -42,14 +41,2 @@ static updateGroupSideEffectKey: string; | ||
/** | ||
* Preserves the Item `value` in the corresponding external Storage. | ||
* | ||
* The specified key is used as the unique identifier for the Persistent. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/state/methods/#persist) | ||
* | ||
* @public | ||
* @param key - Key/Name identifier of Persistent. | ||
* @param config - Configuration object | ||
*/ | ||
persist(key?: PersistentKey, config?: ItemPersistConfigInterface): this; | ||
/** | ||
* Adds side effect to Item | ||
@@ -72,3 +59,3 @@ * that rebuilds all Groups containing the specified Item identifier | ||
} | ||
export interface ItemPersistConfigInterface extends StatePersistentConfigInterface { | ||
export interface ItemPersistConfigInterface extends CreateStatePersistentConfigInterface { | ||
/** | ||
@@ -75,0 +62,0 @@ * Whether to format the specified Storage key following the Collection Item Storage key pattern. |
import { EnhancedState, StateRuntimeJobConfigInterface } from '../state'; | ||
import { Item } from './item'; | ||
import { Collection, DefaultItem, ItemKey } from './collection'; | ||
export declare class Selector<DataType extends Object = DefaultItem> extends EnhancedState<DataType | null> { | ||
export declare class Selector<DataType extends DefaultItem = DefaultItem> extends EnhancedState<DataType | null> { | ||
collection: () => Collection<DataType>; | ||
@@ -6,0 +6,0 @@ static rebuildSelectorSideEffectKey: string; |
@@ -28,3 +28,3 @@ import { Agile } from '../agile'; | ||
*/ | ||
constructor(agileInstance: Agile, computeFunction: ComputeFunctionType<ComputedValueType>, config?: CreateComputedConfigInterface); | ||
constructor(agileInstance: Agile, computeFunction: ComputeFunctionType<ComputedValueType>, config?: CreateComputedConfigInterface<ComputedValueType>); | ||
/** | ||
@@ -66,3 +66,3 @@ * Forces a recomputation of the cached value with the compute function. | ||
export declare type ComputeFunctionType<ComputedValueType = any> = () => ComputedValueType | Promise<ComputedValueType>; | ||
export interface CreateComputedConfigInterface extends StateConfigInterface { | ||
export interface CreateComputedConfigInterface<ComputedValueType = any> extends StateConfigInterface { | ||
/** | ||
@@ -83,2 +83,11 @@ * Hard-coded dependencies the Computed Class should depend on. | ||
autodetect?: boolean; | ||
/** | ||
* Initial value of the Computed | ||
* which is temporarily set until the first computation has been completed. | ||
* | ||
* Note: Only really relevant if an async compute method is used. | ||
* | ||
* @default undefined | ||
*/ | ||
initialValue?: ComputedValueType; | ||
} | ||
@@ -85,0 +94,0 @@ export interface ComputedConfigInterface { |
import { defineConfig } from '@agile-ts/utils'; | ||
import { LogCodeManager } from './logCodeManager.js'; | ||
import { logCodeManager } from './logCodeManager.js'; | ||
import { globalBind } from './utils.js'; | ||
@@ -27,6 +27,6 @@ import { Integrations } from './integrations/integrations.js'; | ||
this.subController = new SubController(this); | ||
LogCodeManager.log("10:00:00", [], this); | ||
logCodeManager.log("10:00:00", {}, this); | ||
if (config.bindGlobal) { | ||
if (!globalBind(_Agile.globalKey, this)) { | ||
LogCodeManager.log("10:02:00"); | ||
logCodeManager.log("10:02:00"); | ||
} | ||
@@ -33,0 +33,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import { defineConfig, generateId, normalizeArray, isValidObject, isFunction, removeProperties, copy } from '@agile-ts/utils'; | ||
import { LogCodeManager } from '../logCodeManager.js'; | ||
import { defineConfig, generateId, normalizeArray, isValidObject, isFunction, copy } from '@agile-ts/utils'; | ||
import { logCodeManager } from '../logCodeManager.js'; | ||
import { Item } from './item.js'; | ||
@@ -77,3 +77,3 @@ import { Selector } from './selector.js'; | ||
const key = (_a = config.key) != null ? _a : generateId(); | ||
LogCodeManager.log("1B:02:00"); | ||
logCodeManager.log("1B:02:00"); | ||
return this.createGroup(key, initialItems); | ||
@@ -87,3 +87,3 @@ } | ||
const key = (_a = config.key) != null ? _a : generateId(); | ||
LogCodeManager.log("1B:02:01"); | ||
logCodeManager.log("1B:02:01"); | ||
return this.createSelector(key, initialKey); | ||
@@ -183,7 +183,7 @@ } | ||
if (item == null) { | ||
LogCodeManager.log("1B:03:00", [itemKey, this._key]); | ||
logCodeManager.log("1B:03:00", { replacers: [itemKey, this._key] }); | ||
return void 0; | ||
} | ||
if (!isValidObject(changes)) { | ||
LogCodeManager.log("1B:03:01", [itemKey, this._key]); | ||
logCodeManager.log("1B:03:01", { replacers: [itemKey, this._key] }); | ||
return void 0; | ||
@@ -211,3 +211,3 @@ } | ||
changes[this.config.primaryKey] = itemKey; | ||
LogCodeManager.log("1B:02:02", [], changes); | ||
logCodeManager.log("1B:02:02", {}, changes); | ||
} | ||
@@ -223,6 +223,6 @@ item.set(changes, { | ||
if (!this.isInstantiated) | ||
LogCodeManager.log("1B:02:03"); | ||
logCodeManager.log("1B:02:03"); | ||
if (group != null) { | ||
if (!group.isPlaceholder) { | ||
LogCodeManager.log("1B:03:02", [groupKey]); | ||
logCodeManager.log("1B:03:02", { replacers: [groupKey] }); | ||
return group; | ||
@@ -278,6 +278,6 @@ } | ||
if (!this.isInstantiated) | ||
LogCodeManager.log("1B:02:04"); | ||
logCodeManager.log("1B:02:04"); | ||
if (selector != null) { | ||
if (!selector.isPlaceholder) { | ||
LogCodeManager.log("1B:03:03", [selectorKey]); | ||
logCodeManager.log("1B:03:03", { replacers: [selectorKey] }); | ||
return selector; | ||
@@ -388,25 +388,9 @@ } | ||
} | ||
persist(keyOrConfig = {}, config = {}) { | ||
let _config; | ||
let key; | ||
if (isValidObject(keyOrConfig)) { | ||
_config = keyOrConfig; | ||
key = this._key; | ||
} else { | ||
_config = config || {}; | ||
key = keyOrConfig; | ||
} | ||
_config = defineConfig(_config, { | ||
loadValue: true, | ||
storageKeys: [], | ||
defaultStorageKey: null | ||
persist(config = {}) { | ||
config = defineConfig(config, { | ||
key: this.key | ||
}); | ||
if (this.persistent != null && this.isPersisted) | ||
return this; | ||
this.persistent = new CollectionPersistent(this, { | ||
loadValue: _config.loadValue, | ||
storageKeys: _config.storageKeys, | ||
key, | ||
defaultStorageKey: _config.defaultStorageKey | ||
}); | ||
this.persistent = new CollectionPersistent(this, config); | ||
return this; | ||
@@ -418,3 +402,5 @@ } | ||
if (!isFunction(callback)) { | ||
LogCodeManager.log("00:03:01", ["OnLoad Callback", "function"]); | ||
logCodeManager.log("00:03:01", { | ||
replacers: ["OnLoad Callback", "function"] | ||
}); | ||
return this; | ||
@@ -449,3 +435,3 @@ } | ||
const _itemKeys = normalizeArray(itemKeys); | ||
(_a = this.getGroup(oldGroupKey)) == null ? void 0 : _a.remove(_itemKeys, removeProperties(config, ["method", "overwrite"])); | ||
(_a = this.getGroup(oldGroupKey)) == null ? void 0 : _a.remove(_itemKeys, config); | ||
(_b = this.getGroup(newGroupKey)) == null ? void 0 : _b.add(_itemKeys, config); | ||
@@ -463,3 +449,5 @@ return this; | ||
if (this.hasItem(newItemKey)) { | ||
LogCodeManager.log("1B:03:04", [oldItemKey, newItemKey, this._key]); | ||
logCodeManager.log("1B:03:04", { | ||
replacers: [oldItemKey, newItemKey, this._key] | ||
}); | ||
return false; | ||
@@ -571,7 +559,7 @@ } | ||
if (!isValidObject(_data)) { | ||
LogCodeManager.log("1B:03:05", [this._key]); | ||
logCodeManager.log("1B:03:05", { replacers: [this._key] }); | ||
return false; | ||
} | ||
if (!Object.prototype.hasOwnProperty.call(_data, primaryKey)) { | ||
LogCodeManager.log("1B:02:05", [this._key, primaryKey]); | ||
logCodeManager.log("1B:02:05", { replacers: [this._key, primaryKey] }); | ||
_data[primaryKey] = generateId(); | ||
@@ -607,3 +595,3 @@ } | ||
if (!Object.prototype.hasOwnProperty.call(item._value, primaryKey)) { | ||
LogCodeManager.log("1B:02:05", [this._key, primaryKey]); | ||
logCodeManager.log("1B:02:05", { replacers: [this._key, primaryKey] }); | ||
itemKey = generateId(); | ||
@@ -614,3 +602,5 @@ item.patch({ [this.config.primaryKey]: itemKey }, { background: config.background }); | ||
if (item.collection() !== this) { | ||
LogCodeManager.log("1B:03:06", [this._key, item.collection()._key]); | ||
logCodeManager.log("1B:03:06", { | ||
replacers: [this._key, item.collection()._key] | ||
}); | ||
return false; | ||
@@ -617,0 +607,0 @@ } |
import { defineConfig } from '@agile-ts/utils'; | ||
import { LogCodeManager } from '../logCodeManager.js'; | ||
import { logCodeManager } from '../logCodeManager.js'; | ||
import { Persistent } from '../storages/persistent.js'; | ||
@@ -72,3 +72,4 @@ import { getSharedStorageManager } from '../storages/shared.js'; | ||
defaultGroup.loadedInitialValue = false; | ||
defaultGroup.persist(defaultGroupStorageKey, { | ||
defaultGroup.persist({ | ||
key: defaultGroupStorageKey, | ||
loadValue: false, | ||
@@ -85,3 +86,4 @@ defaultStorageKey: this.config.defaultStorageKey || void 0, | ||
if (item != null) { | ||
item.persist(itemStorageKey, { | ||
item.persist({ | ||
key: itemStorageKey, | ||
loadValue: false, | ||
@@ -96,3 +98,4 @@ defaultStorageKey: this.config.defaultStorageKey || void 0, | ||
const placeholderItem = this.collection().getItemWithReference(itemKey); | ||
placeholderItem == null ? void 0 : placeholderItem.persist(itemStorageKey, { | ||
placeholderItem == null ? void 0 : placeholderItem.persist({ | ||
key: itemStorageKey, | ||
loadValue: false, | ||
@@ -136,3 +139,4 @@ defaultStorageKey: this.config.defaultStorageKey, | ||
(_a = getSharedStorageManager()) == null ? void 0 : _a.set(_storageItemKey, true, this.storageKeys); | ||
defaultGroup.persist(defaultGroupStorageKey, { | ||
defaultGroup.persist({ | ||
key: defaultGroupStorageKey, | ||
defaultStorageKey: this.config.defaultStorageKey || void 0, | ||
@@ -145,3 +149,4 @@ storageKeys: this.storageKeys, | ||
const itemStorageKey = _CollectionPersistent.getItemStorageKey(itemKey, _storageItemKey); | ||
item == null ? void 0 : item.persist(itemStorageKey, { | ||
item == null ? void 0 : item.persist({ | ||
key: itemStorageKey, | ||
defaultStorageKey: this.config.defaultStorageKey || void 0, | ||
@@ -207,3 +212,4 @@ storageKeys: this.storageKeys, | ||
if (item != null && !item.isPersisted) | ||
item.persist(itemStorageKey, { | ||
item.persist({ | ||
key: itemStorageKey, | ||
defaultStorageKey: this.config.defaultStorageKey || void 0, | ||
@@ -224,3 +230,3 @@ storageKeys: this.storageKeys, | ||
if (itemKey == null || collectionKey == null) | ||
LogCodeManager.log("1A:02:00"); | ||
logCodeManager.log("1A:02:00"); | ||
if (itemKey == null) | ||
@@ -234,3 +240,3 @@ itemKey = "unknown"; | ||
if (groupKey == null || collectionKey == null) | ||
LogCodeManager.log("1A:02:01"); | ||
logCodeManager.log("1A:02:01"); | ||
if (groupKey == null) | ||
@@ -237,0 +243,0 @@ groupKey = "unknown"; |
@@ -1,29 +0,13 @@ | ||
import { defineConfig, copy, equal, generateId, removeProperties } from '@agile-ts/utils'; | ||
import { defineConfig, copy, generateId, equal } from '@agile-ts/utils'; | ||
import { logCodeManager } from '../../logCodeManager.js'; | ||
import { Observer } from '../../runtime/observer.js'; | ||
import { RuntimeJob } from '../../runtime/runtime.job.js'; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
typeof require !== "undefined" ? require : (x) => { | ||
throw new Error('Dynamic require of "' + x + '" is not supported'); | ||
}; | ||
class GroupObserver extends Observer { | ||
constructor(group, config = {}) { | ||
super(group.agileInstance(), defineConfig(config, { value: group._output })); | ||
super(group.agileInstance(), defineConfig(config, { | ||
value: copy(group._output) | ||
})); | ||
this.group = () => group; | ||
this.nextGroupOutput = copy(group._output); | ||
this.nextGroupValue = copy(group._output); | ||
} | ||
@@ -34,7 +18,7 @@ ingest(config = {}) { | ||
ingestOutput(newGroupOutput, config = {}) { | ||
var _a; | ||
const group = this.group(); | ||
config = defineConfig(config, { | ||
perform: true, | ||
force: false | ||
force: false, | ||
key: logCodeManager.allowLogging ? `${this.key != null ? this.key + "_" : ""}${generateId()}_output` : void 0 | ||
}); | ||
@@ -44,8 +28,6 @@ if (group.isPlaceholder) { | ||
} | ||
this.nextGroupOutput = copy(newGroupOutput); | ||
if (equal(group._output, this.nextGroupOutput) && !config.force) | ||
this.nextGroupValue = copy(newGroupOutput); | ||
if (equal(group._output, this.nextGroupValue) && !config.force) | ||
return; | ||
const job = new RuntimeJob(this, __spreadValues(__spreadValues({}, removeProperties(config, ["perform"])), { | ||
key: (_a = config.key) != null ? _a : `${this._key != null ? this._key + "_" : ""}${generateId()}_output` | ||
})); | ||
const job = new RuntimeJob(this, config); | ||
this.agileInstance().runtime.ingest(job, { | ||
@@ -58,6 +40,6 @@ perform: config.perform | ||
const group = observer.group(); | ||
group._output = copy(observer.nextGroupOutput); | ||
group.nextGroupOutput = copy(observer.nextGroupOutput); | ||
job.observer.previousValue = copy(job.observer.value); | ||
job.observer.value = copy(group._output); | ||
group._output = copy(observer.nextGroupValue); | ||
group.nextGroupOutput = copy(observer.nextGroupValue); | ||
observer.previousValue = Object.freeze(copy(observer.value)); | ||
observer.value = copy(group._output); | ||
} | ||
@@ -64,0 +46,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import { copy, normalizeArray, defineConfig, removeProperties, isValidObject } from '@agile-ts/utils'; | ||
import { LogCodeManager } from '../../logCodeManager.js'; | ||
import { copy, normalizeArray, defineConfig } from '@agile-ts/utils'; | ||
import { logCodeManager } from '../../logCodeManager.js'; | ||
import { GroupObserver } from './group.observer.js'; | ||
@@ -36,3 +36,3 @@ import { CollectionPersistent } from '../collection.persistent.js'; | ||
set output(value) { | ||
LogCodeManager.log("1C:03:00", [this._key]); | ||
logCodeManager.log("1C:03:00", { replacers: [this._key] }); | ||
} | ||
@@ -82,3 +82,3 @@ has(itemKey) { | ||
config.background = true; | ||
this.set(newGroupValue, removeProperties(config, ["softRebuild"])); | ||
this.set(newGroupValue, config); | ||
return this; | ||
@@ -121,3 +121,3 @@ } | ||
config.background = true; | ||
this.set(newGroupValue, removeProperties(config, ["method", "softRebuild"])); | ||
this.set(newGroupValue, config); | ||
return this; | ||
@@ -134,26 +134,11 @@ } | ||
} | ||
persist(keyOrConfig = {}, config = {}) { | ||
let _config; | ||
let key; | ||
if (isValidObject(keyOrConfig)) { | ||
_config = keyOrConfig; | ||
key = this._key; | ||
} else { | ||
_config = config || {}; | ||
key = keyOrConfig; | ||
} | ||
_config = defineConfig(_config, { | ||
loadValue: true, | ||
followCollectionPersistKeyPattern: true, | ||
storageKeys: [], | ||
defaultStorageKey: null | ||
persist(config = {}) { | ||
config = defineConfig(config, { | ||
key: this._key, | ||
followCollectionPersistKeyPattern: true | ||
}); | ||
if (_config.followCollectionPersistKeyPattern) { | ||
key = CollectionPersistent.getGroupStorageKey(key || this._key, this.collection()._key); | ||
if (config.followCollectionPersistKeyPattern) { | ||
config.key = CollectionPersistent.getGroupStorageKey(config.key || this._key, this.collection()._key); | ||
} | ||
super.persist(key, { | ||
loadValue: _config.loadValue, | ||
storageKeys: _config.storageKeys, | ||
defaultStorageKey: _config.defaultStorageKey | ||
}); | ||
super.persist(config); | ||
return this; | ||
@@ -205,3 +190,3 @@ } | ||
if (notFoundItemKeys.length > 0 && this.loadedInitialValue) { | ||
LogCodeManager.log("1C:02:00", [this.collection()._key, this._key], notFoundItemKeys); | ||
logCodeManager.log("1C:02:00", { replacers: [this.collection()._key, this._key] }, notFoundItemKeys); | ||
} | ||
@@ -208,0 +193,0 @@ this.notFoundItemKeys = notFoundItemKeys; |
@@ -1,2 +0,2 @@ | ||
import { defineConfig, isValidObject } from '@agile-ts/utils'; | ||
import { defineConfig } from '@agile-ts/utils'; | ||
import { CollectionPersistent } from './collection.persistent.js'; | ||
@@ -36,26 +36,11 @@ import { EnhancedState } from '../state/state.enhanced.js'; | ||
} | ||
persist(keyOrConfig = {}, config = {}) { | ||
let _config; | ||
let key; | ||
if (isValidObject(keyOrConfig)) { | ||
_config = keyOrConfig; | ||
key = this._key; | ||
} else { | ||
_config = config || {}; | ||
key = keyOrConfig; | ||
} | ||
_config = defineConfig(_config, { | ||
loadValue: true, | ||
followCollectionPersistKeyPattern: true, | ||
storageKeys: [], | ||
defaultStorageKey: null | ||
persist(config = {}) { | ||
config = defineConfig(config, { | ||
key: this._key, | ||
followCollectionPersistKeyPattern: true | ||
}); | ||
if (_config.followCollectionPersistKeyPattern) { | ||
key = CollectionPersistent.getItemStorageKey(key || this._key, this.collection()._key); | ||
if (config.followCollectionPersistKeyPattern) { | ||
config.key = CollectionPersistent.getItemStorageKey(config.key || this._key, this.collection()._key); | ||
} | ||
super.persist(key, { | ||
loadValue: _config.loadValue, | ||
storageKeys: _config.storageKeys, | ||
defaultStorageKey: _config.defaultStorageKey | ||
}); | ||
super.persist(config); | ||
return this; | ||
@@ -62,0 +47,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { defineConfig, isAsyncFunction, removeProperties } from '@agile-ts/utils'; | ||
import { isAsyncFunction, defineConfig } from '@agile-ts/utils'; | ||
import { extractRelevantObservers } from '../utils.js'; | ||
@@ -31,3 +31,3 @@ import { ComputedTracker } from './computed.tracker.js'; | ||
constructor(agileInstance, computeFunction, config = {}) { | ||
super(agileInstance, null, { | ||
super(agileInstance, Object.prototype.hasOwnProperty.call(config, "initialValue") ? config.initialValue : !isAsyncFunction(computeFunction) ? computeFunction() : null, { | ||
key: config.key, | ||
@@ -60,3 +60,3 @@ dependents: config.dependents | ||
this.compute({ autodetect: config.autodetect }).then((result) => { | ||
this.observers["value"].ingestValue(result, removeProperties(config, ["autodetect"])); | ||
this.observers["value"].ingestValue(result, config); | ||
}); | ||
@@ -78,3 +78,3 @@ return this; | ||
this.computeFunction = computeFunction; | ||
this.recompute(removeProperties(config, ["overwriteDeps"])); | ||
this.recompute(config); | ||
return this; | ||
@@ -81,0 +81,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { defineConfig, removeProperties } from '@agile-ts/utils'; | ||
import { defineConfig } from '@agile-ts/utils'; | ||
import { sharedAgileInstance } from '../shared.js'; | ||
@@ -17,5 +17,5 @@ import { Computed } from './computed.js'; | ||
_config = defineConfig(_config, { agileInstance: sharedAgileInstance }); | ||
return new Computed(_config.agileInstance, computeFunction, removeProperties(_config, ["agileInstance"])); | ||
return new Computed(_config.agileInstance, computeFunction, _config); | ||
} | ||
export { createComputed }; |
@@ -5,3 +5,3 @@ import { Agile as Agile$1 } from './agile.js'; | ||
export { extractObservers, extractRelevantObservers, globalBind, optionalRequire, runsOnServer } from './utils.js'; | ||
export { LogCodeManager, assignAdditionalLogs } from './logCodeManager.js'; | ||
export { LogCodeManager, assignAdditionalLogs, logCodeManager, logCodeTypes } from './logCodeManager.js'; | ||
export { createStorage } from './storages/index.js'; | ||
@@ -8,0 +8,0 @@ export { createCollection } from './collection/index.js'; |
@@ -5,3 +5,3 @@ class Integration { | ||
this.integrated = false; | ||
this._key = config.key; | ||
this.key = config.key; | ||
this.frameworkInstance = config.frameworkInstance; | ||
@@ -13,10 +13,4 @@ this.methods = { | ||
} | ||
set key(value) { | ||
this._key = value; | ||
} | ||
get key() { | ||
return this._key; | ||
} | ||
} | ||
export { Integration }; |
import { defineConfig } from '@agile-ts/utils'; | ||
import { LogCodeManager } from '../logCodeManager.js'; | ||
import { logCodeManager } from '../logCodeManager.js'; | ||
import { Integration } from './integration.js'; | ||
@@ -56,4 +56,6 @@ | ||
return __async(this, null, function* () { | ||
if (integration._key == null) { | ||
LogCodeManager.log("18:03:00", [integration._key, this.agileInstance().key], integration); | ||
if (integration.key == null) { | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("18:03:00", { replacers: [integration.key, this.agileInstance().key] }, integration); | ||
} | ||
return false; | ||
@@ -67,3 +69,5 @@ } | ||
integration.integrated = true; | ||
LogCodeManager.log("18:00:00", [integration._key, this.agileInstance().key], integration); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("18:00:00", { replacers: [integration.key, this.agileInstance().key] }, integration); | ||
} | ||
return true; | ||
@@ -75,3 +79,3 @@ }); | ||
if (!integration.ready) { | ||
LogCodeManager.log("18:02:00", [integration._key]); | ||
logCodeManager.log("18:02:00", { replacers: [integration.key] }); | ||
return; | ||
@@ -78,0 +82,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { copy } from '@agile-ts/utils'; | ||
import { defineConfig } from '@agile-ts/utils'; | ||
@@ -28,4 +28,3 @@ var __defProp = Object.defineProperty; | ||
}; | ||
let allowLogging = true; | ||
const niceLogCodeMessages = { | ||
const logCodeMessages = { | ||
"10:00:00": "Created new AgileInstance.", | ||
@@ -91,44 +90,46 @@ "10:02:00": "Be careful when binding multiple Agile Instances globally in one application!", | ||
}; | ||
const logCodeMessages = process.env.NODE_ENV !== "production" ? niceLogCodeMessages : {}; | ||
function setAllowLogging(logging) { | ||
allowLogging = logging; | ||
} | ||
function getLog(logCode, replacers = []) { | ||
let result = logCodeMessages[logCode]; | ||
if (result == null) | ||
return logCode; | ||
for (let i = 0; i < replacers.length; i++) { | ||
result = result.replace("${" + i + "}", replacers[i]); | ||
class LogCodeManager { | ||
constructor(logCodeMessages2, loggerPackage) { | ||
this.allowLogging = true; | ||
this.logCodeMessages = logCodeMessages2; | ||
this._loggerPackage = loggerPackage; | ||
} | ||
return result; | ||
} | ||
function log(logCode, replacers = [], ...data) { | ||
const logger = LogCodeManager.getLogger(); | ||
if (logger != null && !logger.isActive || !allowLogging) | ||
return; | ||
const logType = logCodeTypes[logCode.substr(3, 2)]; | ||
if (typeof logType !== "string") | ||
return; | ||
if (logger == null) { | ||
if (logType === "error" || logType === "warn") | ||
console[logType](`Agile: ${getLog(logCode, replacers)}`); | ||
return; | ||
get logger() { | ||
var _a; | ||
return ((_a = this._loggerPackage) == null ? void 0 : _a.sharedLogger) || null; | ||
} | ||
logger[logType](getLog(logCode, replacers), ...data); | ||
} | ||
function logIfTags(tags, logCode, replacers = [], ...data) { | ||
const logger = LogCodeManager.getLogger(); | ||
if (logger != null && !logger.isActive || !allowLogging) | ||
return; | ||
const logType = logCodeTypes[logCode.substr(3, 2)]; | ||
if (typeof logType !== "string") | ||
return; | ||
if (logger == null) { | ||
return; | ||
getLog(logCode, replacers = []) { | ||
let result = this.logCodeMessages[logCode]; | ||
if (result == null) | ||
return logCode; | ||
for (let i = 0; i < replacers.length; i++) { | ||
result = result.replace("${" + i + "}", replacers[i]); | ||
} | ||
return result; | ||
} | ||
logger.if.tag(tags)[logType](getLog(logCode, replacers), ...data); | ||
log(logCode, config = {}, ...data) { | ||
var _a; | ||
if (this.logger != null && !this.logger.isActive || !this.allowLogging) | ||
return; | ||
config = defineConfig(config, { | ||
replacers: [], | ||
tags: [] | ||
}); | ||
const logType = logCodeTypes[logCode.substr(3, 2)]; | ||
if (typeof logType !== "string") | ||
return; | ||
if (this.logger == null) { | ||
if (logType === "error" || logType === "warn") | ||
console[logType](`Agile: ${this.getLog(logCode, config.replacers)}`); | ||
return; | ||
} | ||
const log = this.getLog(logCode, config.replacers); | ||
if (((_a = config.tags) == null ? void 0 : _a.length) === 0) | ||
this.logger[logType](log, ...data); | ||
else | ||
this.logger.if.tag(config.tags)[logType](log, ...data); | ||
} | ||
} | ||
function assignAdditionalLogs(additionalLogs, logCodeManager) { | ||
const copiedLogCodeManager = copy(logCodeManager); | ||
copiedLogCodeManager.logCodeMessages = __spreadValues(__spreadValues({}, copiedLogCodeManager.logCodeMessages), additionalLogs); | ||
function assignAdditionalLogs(logCodeManager2, additionalLogs) { | ||
const copiedLogCodeManager = new LogCodeManager(__spreadValues(__spreadValues({}, logCodeManager2.logCodeMessages), additionalLogs), logCodeManager2._loggerPackage); | ||
return copiedLogCodeManager; | ||
@@ -143,29 +144,8 @@ } | ||
} | ||
tempLogCodeManager = { | ||
getLog, | ||
log, | ||
logCodeLogTypes: logCodeTypes, | ||
logCodeMessages, | ||
getLogger: () => { | ||
return (loggerPackage == null ? void 0 : loggerPackage.sharedLogger) || null; | ||
}, | ||
logIfTags, | ||
setAllowLogging | ||
}; | ||
tempLogCodeManager = new LogCodeManager(logCodeMessages, loggerPackage); | ||
} else { | ||
tempLogCodeManager = { | ||
getLog: (logCode, replacers) => logCode, | ||
log, | ||
logCodeLogTypes: logCodeTypes, | ||
logCodeMessages: {}, | ||
getLogger: () => { | ||
return null; | ||
}, | ||
logIfTags: (tags, logCode, replacers) => { | ||
}, | ||
setAllowLogging | ||
}; | ||
tempLogCodeManager = new LogCodeManager({}, null); | ||
} | ||
const LogCodeManager = tempLogCodeManager; | ||
const logCodeManager = tempLogCodeManager; | ||
export { LogCodeManager, assignAdditionalLogs }; | ||
export { LogCodeManager, assignAdditionalLogs, logCodeManager, logCodeTypes }; |
import { defineConfig, generateId } from '@agile-ts/utils'; | ||
import { LogCodeManager } from '../logCodeManager.js'; | ||
import { logCodeManager } from '../logCodeManager.js'; | ||
import { RuntimeJob } from './runtime.job.js'; | ||
@@ -12,6 +12,7 @@ | ||
dependents: [], | ||
subs: [] | ||
subs: [], | ||
value: null | ||
}); | ||
this.agileInstance = () => agileInstance; | ||
this._key = config.key; | ||
this.key = config.key; | ||
this.value = config.value; | ||
@@ -22,25 +23,8 @@ this.previousValue = config.value; | ||
} | ||
set key(value) { | ||
this._key = value; | ||
} | ||
get key() { | ||
return this._key; | ||
} | ||
ingest(config = {}) { | ||
var _a; | ||
config = defineConfig(config, { | ||
perform: true, | ||
background: false, | ||
sideEffects: { | ||
enabled: true, | ||
exclude: [] | ||
}, | ||
force: false | ||
key: logCodeManager.allowLogging ? `${this.key != null ? this.key + "_" : ""}${generateId()}` : void 0 | ||
}); | ||
const job = new RuntimeJob(this, { | ||
force: config.force, | ||
sideEffects: config.sideEffects, | ||
background: config.background, | ||
key: (_a = config.key) != null ? _a : `${this._key != null ? this._key + "_" : ""}${generateId()}` | ||
}); | ||
const job = new RuntimeJob(this, config); | ||
this.agileInstance().runtime.ingest(job, { | ||
@@ -51,3 +35,5 @@ perform: config.perform | ||
perform(job) { | ||
LogCodeManager.log("17:03:00"); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("17:03:00"); | ||
} | ||
} | ||
@@ -54,0 +40,0 @@ addDependent(observer) { |
@@ -27,13 +27,7 @@ import { defineConfig } from '@agile-ts/utils'; | ||
this.rerender = !config.background && this.observer.agileInstance().integrations.hasIntegration(); | ||
this._key = config.key; | ||
this.key = config.key; | ||
this.subscriptionContainersToUpdate = new Set(observer.subscribedTo); | ||
} | ||
set key(value) { | ||
this._key = value; | ||
} | ||
get key() { | ||
return this._key; | ||
} | ||
} | ||
export { RuntimeJob }; |
import { defineConfig, notEqual } from '@agile-ts/utils'; | ||
import { LogCodeManager } from '../logCodeManager.js'; | ||
import { logCodeManager } from '../logCodeManager.js'; | ||
import { CallbackSubscriptionContainer } from './subscription/container/CallbackSubscriptionContainer.js'; | ||
@@ -21,3 +21,5 @@ import { ComponentSubscriptionContainer } from './subscription/container/ComponentSubscriptionContainer.js'; | ||
this.jobQueue.push(job); | ||
LogCodeManager.logIfTags(["runtime"], "16:01:00", [job._key], job); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("16:01:00", { tags: ["runtime"], replacers: [job.key] }, job); | ||
} | ||
if (config.perform) { | ||
@@ -38,3 +40,5 @@ const performJob = this.jobQueue.shift(); | ||
this.currentJob = null; | ||
LogCodeManager.logIfTags(["runtime"], "16:01:01", [job._key], job); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("16:01:01", { tags: ["runtime"], replacers: [job.key] }, job); | ||
} | ||
if (this.jobQueue.length > 0) { | ||
@@ -81,5 +85,9 @@ const performJob = this.jobQueue.shift(); | ||
this.notReadyJobsToRerender.add(job); | ||
LogCodeManager.log("16:02:00", [subscriptionContainer.key], subscriptionContainer); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("16:02:00", { replacers: [subscriptionContainer.key] }, subscriptionContainer); | ||
} | ||
} else { | ||
LogCodeManager.log("16:02:01", [job.config.maxTriesToUpdate], subscriptionContainer); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("16:02:01", { replacers: [job.config.maxTriesToUpdate] }, subscriptionContainer); | ||
} | ||
} | ||
@@ -107,3 +115,5 @@ return; | ||
} | ||
LogCodeManager.logIfTags(["runtime"], "16:01:02", [], subscriptionsToUpdate); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("16:01:02", { tags: ["runtime"] }, subscriptionsToUpdate); | ||
} | ||
} | ||
@@ -127,2 +137,4 @@ getUpdatedObserverValues(subscriptionContainer) { | ||
const newValue = job.observer.value; | ||
if (!previousValue && !newValue) | ||
return false; | ||
for (const selectorMethod of selectorMethods) { | ||
@@ -129,0 +141,0 @@ if (notEqual(selectorMethod(newValue), selectorMethod(previousValue))) |
@@ -1,3 +0,3 @@ | ||
import { defineConfig, isFunction, removeProperties } from '@agile-ts/utils'; | ||
import { LogCodeManager } from '../../logCodeManager.js'; | ||
import { defineConfig, isFunction } from '@agile-ts/utils'; | ||
import { logCodeManager } from '../../logCodeManager.js'; | ||
import { ComponentSubscriptionContainer } from './container/ComponentSubscriptionContainer.js'; | ||
@@ -17,8 +17,8 @@ import { CallbackSubscriptionContainer } from './container/CallbackSubscriptionContainer.js'; | ||
}); | ||
const subscriptionContainer = isFunction(integrationInstance) ? this.createCallbackSubscriptionContainer(integrationInstance, subs, config) : this.createComponentSubscriptionContainer(integrationInstance, subs, config); | ||
const subscriptionContainer = this[isFunction(integrationInstance) ? "createCallbackSubscriptionContainer" : "createComponentSubscriptionContainer"](integrationInstance, subs, config); | ||
if (subscriptionContainer.isObjectBased && !Array.isArray(subs)) { | ||
const props = {}; | ||
for (const key in subs) | ||
if (subs[key].value) | ||
props[key] = subs[key].value; | ||
if (subs[key]["value"]) | ||
props[key] = subs[key]["value"]; | ||
return { subscriptionContainer, props }; | ||
@@ -38,3 +38,5 @@ } | ||
this.callbackSubs.delete(subscriptionInstance); | ||
LogCodeManager.logIfTags(["subscription"], "15:01:00", [], subscriptionInstance); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("15:01:00", { tags: ["subscription"] }, subscriptionInstance); | ||
} | ||
return; | ||
@@ -45,3 +47,5 @@ } | ||
this.componentSubs.delete(subscriptionInstance); | ||
LogCodeManager.logIfTags(["subscription"], "15:01:01", [], subscriptionInstance); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("15:01:01", { tags: ["subscription"] }, subscriptionInstance); | ||
} | ||
return; | ||
@@ -53,3 +57,5 @@ } | ||
this.componentSubs.delete(subContainer); | ||
LogCodeManager.logIfTags(["subscription"], "15:01:01", [], subscriptionInstance); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("15:01:01", { tags: ["subscription"] }, subscriptionInstance); | ||
} | ||
}); | ||
@@ -60,3 +66,3 @@ return; | ||
createComponentSubscriptionContainer(componentInstance, subs, config = {}) { | ||
const componentSubscriptionContainer = new ComponentSubscriptionContainer(componentInstance, subs, removeProperties(config, ["waitForMount"])); | ||
const componentSubscriptionContainer = new ComponentSubscriptionContainer(componentInstance, subs, config); | ||
this.componentSubs.add(componentSubscriptionContainer); | ||
@@ -68,3 +74,3 @@ if (config.waitForMount) { | ||
componentSubscriptionContainer.ready = true; | ||
if (componentInstance["componentSubscriptionContainers"] != null && Array.isArray(componentInstance.componentSubscriptionContainers)) | ||
if (Array.isArray(componentInstance.componentSubscriptionContainers)) | ||
componentInstance.componentSubscriptionContainers.push(componentSubscriptionContainer); | ||
@@ -75,10 +81,14 @@ else | ||
]; | ||
LogCodeManager.logIfTags(["subscription"], "15:01:02", [], componentSubscriptionContainer); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("15:01:02", { tags: ["subscription"] }, componentSubscriptionContainer); | ||
} | ||
return componentSubscriptionContainer; | ||
} | ||
createCallbackSubscriptionContainer(callbackFunction, subs, config = {}) { | ||
const callbackSubscriptionContainer = new CallbackSubscriptionContainer(callbackFunction, subs, removeProperties(config, ["waitForMount"])); | ||
const callbackSubscriptionContainer = new CallbackSubscriptionContainer(callbackFunction, subs, config); | ||
this.callbackSubs.add(callbackSubscriptionContainer); | ||
callbackSubscriptionContainer.ready = true; | ||
LogCodeManager.logIfTags(["subscription"], "15:01:03", [], callbackSubscriptionContainer); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("15:01:03", { tags: ["subscription"] }, callbackSubscriptionContainer); | ||
} | ||
return callbackSubscriptionContainer; | ||
@@ -85,0 +95,0 @@ } |
import { isFunction } from '@agile-ts/utils'; | ||
import { LogCodeManager } from './logCodeManager.js'; | ||
import { logCodeManager } from './logCodeManager.js'; | ||
import { Agile } from './agile.js'; | ||
@@ -23,3 +23,3 @@ | ||
} catch (e) { | ||
LogCodeManager.log("20:03:00", [], instance); | ||
logCodeManager.log("20:03:00", {}, instance); | ||
} | ||
@@ -26,0 +26,0 @@ return void 0; |
@@ -1,2 +0,2 @@ | ||
import { defineConfig, removeProperties } from '@agile-ts/utils'; | ||
import { defineConfig } from '@agile-ts/utils'; | ||
import { sharedAgileInstance } from '../../shared.js'; | ||
@@ -9,5 +9,5 @@ import { EnhancedState } from '../state.enhanced.js'; | ||
}); | ||
return new EnhancedState(config.agileInstance, initialValue, removeProperties(config, ["agileInstance"])); | ||
return new EnhancedState(config.agileInstance, initialValue, config); | ||
} | ||
export { createEnhancedState }; |
@@ -1,2 +0,2 @@ | ||
import { defineConfig, removeProperties } from '@agile-ts/utils'; | ||
import { defineConfig } from '@agile-ts/utils'; | ||
import { sharedAgileInstance } from '../../shared.js'; | ||
@@ -9,5 +9,5 @@ import { State } from '../state.js'; | ||
}); | ||
return new State(config.agileInstance, initialValue, removeProperties(config, ["agileInstance"])); | ||
return new State(config.agileInstance, initialValue, config); | ||
} | ||
export { createLightState }; |
@@ -1,3 +0,3 @@ | ||
import { defineConfig, isValidObject, flatMerge, removeProperties, isFunction, generateId, equal, notEqual } from '@agile-ts/utils'; | ||
import { LogCodeManager } from '../logCodeManager.js'; | ||
import { defineConfig, isValidObject, flatMerge, isFunction, generateId, equal, notEqual } from '@agile-ts/utils'; | ||
import { logCodeManager } from '../logCodeManager.js'; | ||
import { State } from './state.js'; | ||
@@ -35,7 +35,9 @@ import { StatePersistent } from './state.persistent.js'; | ||
if (!isValidObject(this.nextStateValue, true)) { | ||
LogCodeManager.log("14:03:02"); | ||
logCodeManager.log("14:03:02"); | ||
return this; | ||
} | ||
if (!isValidObject(targetWithChanges, true)) { | ||
LogCodeManager.log("00:03:01", ["TargetWithChanges", "object"]); | ||
logCodeManager.log("00:03:01", { | ||
replacers: ["TargetWithChanges", "object"] | ||
}); | ||
return this; | ||
@@ -51,3 +53,3 @@ } | ||
} | ||
this.ingest(removeProperties(config, ["addNewProperties"])); | ||
this.ingest(config); | ||
return this; | ||
@@ -67,3 +69,5 @@ } | ||
if (!isFunction(_callback)) { | ||
LogCodeManager.log("00:03:01", ["Watcher Callback", "function"]); | ||
logCodeManager.log("00:03:01", { | ||
replacers: ["Watcher Callback", "function"] | ||
}); | ||
return this; | ||
@@ -90,7 +94,9 @@ } | ||
if (!isFunction(handler)) { | ||
LogCodeManager.log("00:03:01", ["Interval Callback", "function"]); | ||
logCodeManager.log("00:03:01", { | ||
replacers: ["Interval Callback", "function"] | ||
}); | ||
return this; | ||
} | ||
if (this.currentInterval) { | ||
LogCodeManager.log("14:03:03", [], this.currentInterval); | ||
logCodeManager.log("14:03:03", { replacers: [] }, this.currentInterval); | ||
return this; | ||
@@ -114,3 +120,5 @@ } | ||
if (!isFunction(method)) { | ||
LogCodeManager.log("00:03:01", ["Compute Exists Method", "function"]); | ||
logCodeManager.log("00:03:01", { | ||
replacers: ["Compute Exists Method", "function"] | ||
}); | ||
return this; | ||
@@ -123,3 +131,5 @@ } | ||
if (!isFunction(method)) { | ||
LogCodeManager.log("00:03:01", ["Compute Value Method", "function"]); | ||
logCodeManager.log("00:03:01", { | ||
replacers: ["Compute Value Method", "function"] | ||
}); | ||
return this; | ||
@@ -153,29 +163,15 @@ } | ||
default: | ||
LogCodeManager.log("14:03:04", [typeof this.nextStateValue]); | ||
logCodeManager.log("14:03:04", { | ||
replacers: [typeof this.nextStateValue] | ||
}); | ||
} | ||
return this; | ||
} | ||
persist(keyOrConfig = {}, config = {}) { | ||
let _config; | ||
let key; | ||
if (isValidObject(keyOrConfig)) { | ||
_config = keyOrConfig; | ||
key = this._key; | ||
} else { | ||
_config = config || {}; | ||
key = keyOrConfig; | ||
} | ||
_config = defineConfig(_config, { | ||
loadValue: true, | ||
storageKeys: [], | ||
defaultStorageKey: null | ||
persist(config = {}) { | ||
config = defineConfig(config, { | ||
key: this._key | ||
}); | ||
if (this.persistent != null && this.isPersisted) | ||
return this; | ||
this.persistent = new StatePersistent(this, { | ||
loadValue: _config.loadValue, | ||
storageKeys: _config.storageKeys, | ||
key, | ||
defaultStorageKey: _config.defaultStorageKey | ||
}); | ||
this.persistent = new StatePersistent(this, config); | ||
return this; | ||
@@ -187,3 +183,5 @@ } | ||
if (!isFunction(callback)) { | ||
LogCodeManager.log("00:03:01", ["OnLoad Callback", "function"]); | ||
logCodeManager.log("00:03:01", { | ||
replacers: ["OnLoad Callback", "function"] | ||
}); | ||
return this; | ||
@@ -190,0 +188,0 @@ } |
import { defineConfig, copy, isFunction } from '@agile-ts/utils'; | ||
import { LogCodeManager } from '../logCodeManager.js'; | ||
import { logCodeManager } from '../logCodeManager.js'; | ||
import { StateObserver } from './state.observer.js'; | ||
@@ -46,3 +46,3 @@ import { ComputedTracker } from '../computed/computed.tracker.js'; | ||
for (const observerKey in this.observers) | ||
this.observers[observerKey]._key = value; | ||
this.observers[observerKey].key = value; | ||
return this; | ||
@@ -67,3 +67,5 @@ } | ||
if (!isFunction(callback)) { | ||
LogCodeManager.log("00:03:01", ["Side Effect Callback", "function"]); | ||
logCodeManager.log("00:03:01", { | ||
replacers: ["Side Effect Callback", "function"] | ||
}); | ||
return this; | ||
@@ -70,0 +72,0 @@ } |
@@ -1,28 +0,10 @@ | ||
import { defineConfig, copy, equal, generateId, removeProperties, notEqual, createArrayFromObject, isFunction } from '@agile-ts/utils'; | ||
import { defineConfig, copy, generateId, equal, notEqual, createArrayFromObject, isFunction } from '@agile-ts/utils'; | ||
import { StateRuntimeJob } from './state.runtime.job.js'; | ||
import { logCodeManager } from '../logCodeManager.js'; | ||
import { Observer } from '../runtime/observer.js'; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
typeof require !== "undefined" ? require : (x) => { | ||
throw new Error('Dynamic require of "' + x + '" is not supported'); | ||
}; | ||
class StateObserver extends Observer { | ||
constructor(state, config = {}) { | ||
super(state.agileInstance(), defineConfig(config, { | ||
value: state._value | ||
value: copy(state._value) | ||
})); | ||
@@ -43,7 +25,7 @@ this.state = () => state; | ||
ingestValue(newStateValue, config = {}) { | ||
var _a; | ||
const state = this.state(); | ||
config = defineConfig(config, { | ||
perform: true, | ||
force: false | ||
force: false, | ||
key: logCodeManager.allowLogging ? `${this.key != null ? this.key + "_" : ""}${generateId()}_value` : void 0 | ||
}); | ||
@@ -57,5 +39,3 @@ if (state.isPlaceholder) { | ||
return; | ||
const job = new StateRuntimeJob(this, __spreadValues(__spreadValues({}, removeProperties(config, ["perform"])), { | ||
key: (_a = config.key) != null ? _a : `${this._key != null ? this._key + "_" : ""}${generateId()}_value` | ||
})); | ||
const job = new StateRuntimeJob(this, config); | ||
this.agileInstance().runtime.ingest(job, { | ||
@@ -78,3 +58,3 @@ perform: config.perform | ||
this.sideEffects(job); | ||
job.observer.previousValue = copy(observer.value); | ||
job.observer.previousValue = Object.freeze(copy(observer.value)); | ||
job.observer.value = copy(state._value); | ||
@@ -85,2 +65,4 @@ } | ||
const state = job.observer.state(); | ||
if (Object.keys(state.sideEffects).length === 0) | ||
return; | ||
if ((_b = (_a = job.config) == null ? void 0 : _a.sideEffects) == null ? void 0 : _b.enabled) { | ||
@@ -87,0 +69,0 @@ const sideEffectArray = createArrayFromObject(state.sideEffects); |
@@ -39,2 +39,4 @@ import { defineConfig } from '@agile-ts/utils'; | ||
this.state = () => state; | ||
this.onMigrate = config.onMigrate; | ||
this.onSave = config.onSave; | ||
this.instantiatePersistent({ | ||
@@ -65,3 +67,3 @@ key: config.key, | ||
return false; | ||
this.state().set(loadedValue, { | ||
this.state().set(this.onMigrate != null ? this.onMigrate(loadedValue) : loadedValue, { | ||
storage: false, | ||
@@ -115,3 +117,3 @@ overwrite: true | ||
if (config["storage"] == null || config.storage) { | ||
(_a = getSharedStorageManager()) == null ? void 0 : _a.set(storageItemKey, this.state().getPersistableValue(), this.storageKeys); | ||
(_a = getSharedStorageManager()) == null ? void 0 : _a.set(storageItemKey, this.onSave != null ? this.onSave(this.state().getPersistableValue()) : this.state().getPersistableValue(), this.storageKeys); | ||
} | ||
@@ -118,0 +120,0 @@ } |
@@ -8,22 +8,7 @@ import { defineConfig } from '@agile-ts/utils'; | ||
config = defineConfig(config, { | ||
background: false, | ||
sideEffects: { | ||
enabled: true, | ||
exclude: [] | ||
}, | ||
force: false, | ||
storage: true, | ||
overwrite: false, | ||
maxTriesToUpdate: 3, | ||
any: {} | ||
overwrite: false | ||
}); | ||
this.config = { | ||
background: config.background, | ||
force: config.force, | ||
sideEffects: config.sideEffects, | ||
storage: config.storage, | ||
overwrite: config.overwrite, | ||
maxTriesToUpdate: config.maxTriesToUpdate, | ||
any: config.any | ||
}; | ||
this.config["overwrite"] = config.overwrite; | ||
this.config["storage"] = config.storage; | ||
} | ||
@@ -30,0 +15,0 @@ } |
import { defineConfig, copy } from '@agile-ts/utils'; | ||
import { LogCodeManager } from '../logCodeManager.js'; | ||
import { logCodeManager } from '../logCodeManager.js'; | ||
import { getSharedStorageManager } from './shared.js'; | ||
@@ -86,7 +86,7 @@ | ||
if (this._key === _Persistent.placeHolderKey) { | ||
LogCodeManager.log("12:03:00"); | ||
logCodeManager.log("12:03:00"); | ||
isValid = false; | ||
} | ||
if (this.config.defaultStorageKey == null || this.storageKeys.length <= 0) { | ||
LogCodeManager.log("12:03:01"); | ||
logCodeManager.log("12:03:01"); | ||
isValid = false; | ||
@@ -97,3 +97,3 @@ } | ||
if (!((_a = getSharedStorageManager()) == null ? void 0 : _a.storages[key])) { | ||
LogCodeManager.log("12:03:02", [this._key, key]); | ||
logCodeManager.log("12:03:02", { replacers: [this._key, key] }); | ||
isValid = false; | ||
@@ -132,3 +132,7 @@ } | ||
return __async(this, null, function* () { | ||
LogCodeManager.log("00:03:00", ["loadPersistedValue", "Persistent"]); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("00:03:00", { | ||
replacers: ["loadPersistedValue", "Persistent"] | ||
}); | ||
} | ||
return false; | ||
@@ -139,3 +143,7 @@ }); | ||
return __async(this, null, function* () { | ||
LogCodeManager.log("00:03:00", ["persistValue", "Persistent"]); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("00:03:00", { | ||
replacers: ["persistValue", "Persistent"] | ||
}); | ||
} | ||
return false; | ||
@@ -146,3 +154,7 @@ }); | ||
return __async(this, null, function* () { | ||
LogCodeManager.log("00:03:00", ["removePersistedValue", "Persistent"]); | ||
if (process.env.NODE_ENV !== "production") { | ||
logCodeManager.log("00:03:00", { | ||
replacers: ["removePersistedValue", "Persistent"] | ||
}); | ||
} | ||
return false; | ||
@@ -149,0 +161,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
import { defineConfig, removeProperties } from '@agile-ts/utils'; | ||
import { defineConfig } from '@agile-ts/utils'; | ||
import { runsOnServer } from '../utils.js'; | ||
@@ -14,3 +14,3 @@ import { sharedAgileInstance } from '../shared.js'; | ||
}); | ||
return new Storages(config.agileInstance, removeProperties(config, ["agileInstance"])); | ||
return new Storages(config.agileInstance, config); | ||
} | ||
@@ -17,0 +17,0 @@ function getSharedStorageManager() { |
import { defineConfig, isAsyncFunction, isFunction, isJsonString } from '@agile-ts/utils'; | ||
import { LogCodeManager } from '../logCodeManager.js'; | ||
import { logCodeManager } from '../logCodeManager.js'; | ||
@@ -26,11 +26,11 @@ class Storage { | ||
if (!isFunction((_a = this.methods) == null ? void 0 : _a.get)) { | ||
LogCodeManager.log("13:03:00", ["get"]); | ||
logCodeManager.log("13:03:00", { replacers: ["get"] }); | ||
return false; | ||
} | ||
if (!isFunction((_b = this.methods) == null ? void 0 : _b.set)) { | ||
LogCodeManager.log("13:03:00", ["set"]); | ||
logCodeManager.log("13:03:00", { replacers: ["set"] }); | ||
return false; | ||
} | ||
if (!isFunction((_c = this.methods) == null ? void 0 : _c.remove)) { | ||
LogCodeManager.log("13:03:00", ["remove"]); | ||
logCodeManager.log("13:03:00", { replacers: ["remove"] }); | ||
return false; | ||
@@ -44,6 +44,6 @@ } | ||
if (isAsyncFunction(this.methods.get)) | ||
LogCodeManager.log("13:02:00"); | ||
logCodeManager.log("13:02:00"); | ||
const res = this.methods.get(this.getStorageKey(key)); | ||
const _res = isJsonString(res) ? JSON.parse(res) : res; | ||
LogCodeManager.logIfTags(["storage"], "13:01:00", [this.key, this.getStorageKey(key)], _res); | ||
logCodeManager.log("13:01:00", { tags: ["storage"], replacers: [this.key, this.getStorageKey(key)] }, _res); | ||
return _res; | ||
@@ -60,3 +60,6 @@ } | ||
const _res = isJsonString(res) ? JSON.parse(res) : res; | ||
LogCodeManager.logIfTags(["storage"], "13:01:00", [this.key, this.getStorageKey(key)], _res); | ||
logCodeManager.log("13:01:00", { | ||
tags: ["storage"], | ||
replacers: [this.key, this.getStorageKey(key)] | ||
}, _res); | ||
resolve(_res); | ||
@@ -69,6 +72,6 @@ }).catch(reject); | ||
return; | ||
LogCodeManager.logIfTags(["storage"], "13:01:01", [ | ||
this.key, | ||
this.getStorageKey(key) | ||
]); | ||
logCodeManager.log("13:01:01", { | ||
tags: ["storage"], | ||
replacers: [this.key, this.getStorageKey(key)] | ||
}); | ||
this.methods.set(this.getStorageKey(key), JSON.stringify(value)); | ||
@@ -79,6 +82,6 @@ } | ||
return; | ||
LogCodeManager.logIfTags(["storage"], "13:01:02", [ | ||
this.key, | ||
this.getStorageKey(key) | ||
]); | ||
logCodeManager.log("13:01:02", { | ||
tags: ["storage"], | ||
replacers: [this.key, this.getStorageKey(key)] | ||
}); | ||
this.methods.remove(this.getStorageKey(key)); | ||
@@ -85,0 +88,0 @@ } |
import { defineConfig, notEqual } from '@agile-ts/utils'; | ||
import { LogCodeManager } from '../logCodeManager.js'; | ||
import { logCodeManager } from '../logCodeManager.js'; | ||
import { Storage } from './storage.js'; | ||
@@ -20,3 +20,3 @@ | ||
if (!Storages.localStorageAvailable()) { | ||
LogCodeManager.log("11:02:00"); | ||
logCodeManager.log("11:02:00"); | ||
return false; | ||
@@ -38,7 +38,7 @@ } | ||
if (Object.prototype.hasOwnProperty.call(this.storages, storage.key)) { | ||
LogCodeManager.log("11:03:00", [storage.key]); | ||
logCodeManager.log("11:03:00", { replacers: [storage.key] }); | ||
return false; | ||
} | ||
if (!hasRegisteredAnyStorage && config.default === false) | ||
LogCodeManager.log("11:02:01"); | ||
logCodeManager.log("11:02:01"); | ||
if (!hasRegisteredAnyStorage) | ||
@@ -66,3 +66,3 @@ config.default = true; | ||
} | ||
LogCodeManager.log("13:00:00", [storage.key], storage); | ||
logCodeManager.log("13:00:00", { replacers: [storage.key] }, storage); | ||
return true; | ||
@@ -75,7 +75,7 @@ } | ||
if (!storage) { | ||
LogCodeManager.log("11:03:01", [storageKey]); | ||
logCodeManager.log("11:03:01", { replacers: [storageKey] }); | ||
return void 0; | ||
} | ||
if (!storage.ready) { | ||
LogCodeManager.log("11:03:02", [storageKey]); | ||
logCodeManager.log("11:03:02", { replacers: [storageKey] }); | ||
return void 0; | ||
@@ -87,3 +87,3 @@ } | ||
if (!this.hasStorage()) { | ||
LogCodeManager.log("11:03:03"); | ||
logCodeManager.log("11:03:03"); | ||
return Promise.resolve(void 0); | ||
@@ -102,3 +102,3 @@ } | ||
if (!this.hasStorage()) { | ||
LogCodeManager.log("11:03:04"); | ||
logCodeManager.log("11:03:04"); | ||
return; | ||
@@ -117,3 +117,3 @@ } | ||
if (!this.hasStorage()) { | ||
LogCodeManager.log("11:03:05"); | ||
logCodeManager.log("11:03:05"); | ||
return; | ||
@@ -120,0 +120,0 @@ } |
import { normalizeArray } from '@agile-ts/utils'; | ||
import { LogCodeManager } from './logCodeManager.js'; | ||
import { logCodeManager } from './logCodeManager.js'; | ||
import { Observer } from './runtime/observer.js'; | ||
@@ -7,5 +7,3 @@ | ||
const observers = []; | ||
const tempInstancesArray = normalizeArray(instances, { | ||
createUndefinedArray: true | ||
}); | ||
const tempInstancesArray = normalizeArray(instances, true); | ||
for (const instance of tempInstancesArray) { | ||
@@ -66,3 +64,3 @@ if (instance == null) { | ||
if (error) { | ||
LogCodeManager.log("20:03:02", [moduleName]); | ||
logCodeManager.log("20:03:02", { replacers: [moduleName] }); | ||
console.log(e); | ||
@@ -84,3 +82,3 @@ } | ||
} catch (e) { | ||
LogCodeManager.log("20:03:01", [key]); | ||
logCodeManager.log("20:03:01", { replacers: [key] }); | ||
} | ||
@@ -87,0 +85,0 @@ return false; |
import { Agile } from '../agile'; | ||
export declare class Integration<F = any, C = any> { | ||
_key: IntegrationKey; | ||
key: IntegrationKey; | ||
frameworkInstance?: F; | ||
@@ -19,15 +19,2 @@ ready: boolean; | ||
constructor(config: CreateIntegrationConfig<F, C>); | ||
/** | ||
* Updates the key/name identifier of the Integration. | ||
* | ||
* @public | ||
* @param value - New key/name identifier. | ||
*/ | ||
set key(value: IntegrationKey); | ||
/** | ||
* Returns the key/name identifier of the Integration. | ||
* | ||
* @public | ||
*/ | ||
get key(): IntegrationKey; | ||
} | ||
@@ -34,0 +21,0 @@ export interface CreateIntegrationConfig<F = any, C = any> extends IntegrationMethods<C> { |
@@ -1,2 +0,3 @@ | ||
declare const logCodeTypes: { | ||
import type { Logger } from '@agile-ts/logger'; | ||
export declare const logCodeTypes: { | ||
'00': string; | ||
@@ -7,64 +8,39 @@ '01': string; | ||
}; | ||
declare const niceLogCodeMessages: { | ||
'10:00:00': string; | ||
'10:02:00': string; | ||
'11:02:00': string; | ||
'11:02:01': string; | ||
'11:03:00': string; | ||
'11:03:01': string; | ||
'11:03:02': string; | ||
'11:03:03': string; | ||
'11:03:04': string; | ||
'11:03:05': string; | ||
'12:03:00': string; | ||
'12:03:01': string; | ||
'12:03:02': string; | ||
'13:00:00': string; | ||
'13:01:00': string; | ||
'13:01:01': string; | ||
'13:01:02': string; | ||
'13:02:00': string; | ||
'13:03:00': string; | ||
'14:03:01': string; | ||
'14:03:02': string; | ||
'14:03:03': string; | ||
'14:03:04': string; | ||
'15:01:00': string; | ||
'15:01:01': string; | ||
'15:01:02': string; | ||
'15:01:03': string; | ||
'16:01:00': string; | ||
'16:01:01': string; | ||
'16:01:02': string; | ||
'16:02:00': string; | ||
'16:02:01': string; | ||
'17:03:00': string; | ||
'18:00:00': string; | ||
'18:02:00': string; | ||
'18:03:00': string; | ||
'1A:02:00': string; | ||
'1A:02:01': string; | ||
'1B:02:00': string; | ||
'1B:02:01': string; | ||
'1B:02:02': string; | ||
'1B:02:03': string; | ||
'1B:02:04': string; | ||
'1B:02:05': string; | ||
'1B:03:00': string; | ||
'1B:03:01': string; | ||
'1B:03:02': string; | ||
'1B:03:03': string; | ||
'1B:03:04': string; | ||
'1B:03:05': string; | ||
'1B:03:06': string; | ||
'1C:02:00': string; | ||
'1C:03:00': string; | ||
'1C:03:01': string; | ||
'20:03:00': string; | ||
'20:03:01': string; | ||
'20:03:02': string; | ||
'00:03:00': string; | ||
'00:03:01': string; | ||
}; | ||
declare const logCodeMessages: typeof niceLogCodeMessages; | ||
export declare class LogCodeManager<LogCodeMessagesType extends Object = Object> { | ||
logCodeMessages: LogCodeMessagesType; | ||
_loggerPackage: any; | ||
allowLogging: boolean; | ||
/** | ||
* Manages logging for AgileTs based on log codes. | ||
* | ||
* @param logCodeMessages - Keymap of messages that the LogCodeManager can log. | ||
* @param loggerPackage - Optional '@agile-ts/logger' package for more advanced logging. | ||
*/ | ||
constructor(logCodeMessages: LogCodeMessagesType, loggerPackage?: any); | ||
/** | ||
* Retrieves the shared Logger from the specified 'loggerPackage'. | ||
* | ||
* @public | ||
*/ | ||
get logger(): Logger | null; | ||
/** | ||
* Returns the log message according to the specified log code. | ||
* | ||
* @internal | ||
* @param logCode - Log code of the message to be returned. | ||
* @param replacers - Instances that replace these '${x}' placeholders based on the index | ||
* For example: 'replacers[0]' replaces '${0}', 'replacers[1]' replaces '${1}', .. | ||
*/ | ||
getLog<T extends LogCodePaths<LogCodeMessagesType>>(logCode: T, replacers?: any[]): string; | ||
/** | ||
* Logs the log message according to the specified log code | ||
* with the Agile Logger if installed or the normal console. | ||
* | ||
* @internal | ||
* @param logCode - Log code of the message to be logged. | ||
* @param config - Configuration object | ||
* @param data - Data to be attached to the end of the log message. | ||
*/ | ||
log<T extends LogCodePaths<LogCodeMessagesType>>(logCode: T, config?: LogConfigInterface, ...data: any[]): void; | ||
} | ||
/** | ||
@@ -74,8 +50,8 @@ * Creates an extension of the specified LogCodeManager | ||
* | ||
* @param additionalLogs - Log messages to be added to the LogCodeManager. | ||
* @param logCodeManager - LogCodeManager to create an extension from. | ||
* @param additionalLogs - Log messages to be added to the created LogCodeManager extensions. | ||
*/ | ||
export declare function assignAdditionalLogs<NewLogCodeMessages, OldLogCodeMessages = typeof logCodeMessages>(additionalLogs: { | ||
export declare function assignAdditionalLogs<NewLogCodeMessages, OldLogCodeMessages>(logCodeManager: LogCodeManager<OldLogCodeMessages>, additionalLogs: { | ||
[key: string]: string; | ||
}, logCodeManager: LogCodeManagerInterface<OldLogCodeMessages>): LogCodeManagerInterface<NewLogCodeMessages>; | ||
}): LogCodeManager<NewLogCodeMessages>; | ||
/** | ||
@@ -87,3 +63,3 @@ * The Log Code Manager keeps track | ||
*/ | ||
export declare const LogCodeManager: LogCodeManagerInterface<{ | ||
export declare const logCodeManager: LogCodeManager<{ | ||
'10:00:00': string; | ||
@@ -149,14 +125,18 @@ '10:02:00': string; | ||
}>; | ||
export declare type LogCodesArrayType<T> = { | ||
interface LogConfigInterface { | ||
/** | ||
* Instances that replace these '${x}' placeholders based on the index | ||
* For example: 'replacers[0]' replaces '${0}', 'replacers[1]' replaces '${1}', .. | ||
* @default [] | ||
*/ | ||
replacers?: any[]; | ||
/** | ||
* Tags that need to be active in order to log the specified logCode. | ||
* @default [] | ||
*/ | ||
tags?: string[]; | ||
} | ||
export declare type LogCodePaths<T> = { | ||
[K in keyof T]: T[K] extends string ? K : never; | ||
}[keyof T] & string; | ||
export interface LogCodeManagerInterface<T = typeof logCodeMessages> { | ||
getLog: (logCode: LogCodesArrayType<T>, replacers?: any[]) => string; | ||
log: (logCode: LogCodesArrayType<T>, replacers?: any[], ...data: any[]) => void; | ||
logCodeLogTypes: typeof logCodeTypes; | ||
logCodeMessages: T; | ||
getLogger: () => any; | ||
logIfTags: (tags: string[], logCode: LogCodesArrayType<T>, replacers?: any[], ...data: any[]) => void; | ||
setAllowLogging: (logging: boolean) => void; | ||
} | ||
export {}; |
@@ -5,7 +5,6 @@ import { Agile } from '../agile'; | ||
import { IngestConfigInterface } from './runtime'; | ||
import { StateKey } from '../state'; | ||
export declare type ObserverKey = string | number; | ||
export declare class Observer<ValueType = any> { | ||
agileInstance: () => Agile; | ||
_key?: ObserverKey; | ||
key?: ObserverKey; | ||
dependents: Set<Observer>; | ||
@@ -32,3 +31,3 @@ subscribedTo: Set<SubscriptionContainer>; | ||
* | ||
* Now that the Job was performed, it is added to the rerender queue, | ||
* Now that the Job was performed, it is added to the re-render queue, | ||
* where the subscribed Subscription Container (UI-Components) | ||
@@ -46,15 +45,2 @@ * of the Observer are updated (re-rendered). | ||
/** | ||
* Updates the key/name identifier of the Observer. | ||
* | ||
* @public | ||
* @param value - New key/name identifier. | ||
*/ | ||
set key(value: StateKey | undefined); | ||
/** | ||
* Returns the key/name identifier of the Observer. | ||
* | ||
* @public | ||
*/ | ||
get key(): StateKey | undefined; | ||
/** | ||
* Passes the Observer into the runtime wrapped into a Runtime-Job | ||
@@ -88,2 +74,4 @@ * where it is executed accordingly. | ||
* | ||
* (Note: not mutating directly 'dependents' for better unit testing) | ||
* | ||
* @public | ||
@@ -96,2 +84,4 @@ * @param observer - Observer to depend on the Observer. | ||
* | ||
* (Note: not mutating directly 'dependents' for better unit testing) | ||
* | ||
* @public | ||
@@ -98,0 +88,0 @@ * @param observer - Observer to no longer depend on the Observer. |
import { SubscriptionContainer } from './subscription'; | ||
import { Observer } from './observer'; | ||
export declare class RuntimeJob<ObserverType extends Observer = Observer> { | ||
config: RuntimeJobConfigInterface; | ||
_key?: RuntimeJobKey; | ||
export declare class RuntimeJob<ObserverType extends Observer = Observer, ConfigType extends RuntimeJobConfigInterface = RuntimeJobConfigInterface> { | ||
config: ConfigType; | ||
key?: RuntimeJobKey; | ||
observer: ObserverType; | ||
@@ -23,15 +23,2 @@ rerender: boolean; | ||
constructor(observer: ObserverType, config?: CreateRuntimeJobConfigInterface); | ||
/** | ||
* Updates the key/name identifier of the Runtime Job. | ||
* | ||
* @public | ||
* @param value - New key/name identifier. | ||
*/ | ||
set key(value: RuntimeJobKey | undefined); | ||
/** | ||
* Returns the key/name identifier of the Runtime Job. | ||
* | ||
* @public | ||
*/ | ||
get key(): RuntimeJobKey | undefined; | ||
} | ||
@@ -38,0 +25,0 @@ export declare type RuntimeJobKey = string | number; |
@@ -5,4 +5,3 @@ /// <reference types="node" /> | ||
import { StateIngestConfigInterface } from './state.observer'; | ||
import { StatePersistent } from './state.persistent'; | ||
import { PersistentKey, StorageKey } from '../storages'; | ||
import { CreateStatePersistentConfigInterface, StatePersistent } from './state.persistent'; | ||
export declare class EnhancedState<ValueType = any> extends State<ValueType> { | ||
@@ -207,16 +206,4 @@ isPersisted: boolean; | ||
*/ | ||
persist(config?: StatePersistentConfigInterface): this; | ||
persist(config?: CreateStatePersistentConfigInterface): this; | ||
/** | ||
* Preserves the State `value` in the corresponding external Storage. | ||
* | ||
* The specified key is used as the unique identifier for the Persistent. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/state/methods/#persist) | ||
* | ||
* @public | ||
* @param key - Key/Name identifier of Persistent. | ||
* @param config - Configuration object | ||
*/ | ||
persist(key?: PersistentKey, config?: StatePersistentConfigInterface): this; | ||
/** | ||
* Fires immediately after the persisted `value` | ||
@@ -250,28 +237,4 @@ * is loaded into the State from a corresponding external Storage. | ||
} | ||
export interface StatePersistentConfigInterface { | ||
/** | ||
* Whether the Persistent should automatically load | ||
* the persisted value into the State after its instantiation. | ||
* @default true | ||
*/ | ||
loadValue?: boolean; | ||
/** | ||
* Key/Name identifier of Storages | ||
* in which the State value should be or is persisted. | ||
* @default [`defaultStorageKey`] | ||
*/ | ||
storageKeys?: StorageKey[]; | ||
/** | ||
* Key/Name identifier of the default Storage of the specified Storage keys. | ||
* | ||
* The State value is loaded from the default Storage by default | ||
* and is only loaded from the remaining Storages (`storageKeys`) | ||
* if the loading from the default Storage failed. | ||
* | ||
* @default first index of the specified Storage keys or the AgileTs default Storage key | ||
*/ | ||
defaultStorageKey?: StorageKey; | ||
} | ||
export declare type StateWatcherCallback<T = any> = (value: T, key: string) => void; | ||
export declare type ComputeValueMethod<T = any> = (value: T) => T; | ||
export declare type ComputeExistsMethod<T = any> = (value: T) => boolean; |
import { IngestConfigInterface, Observer, ObserverKey, SubscriptionContainer } from '../runtime'; | ||
import { CreateStateRuntimeJobConfigInterface, StateRuntimeJob } from './state.runtime.job'; | ||
import { State } from './state'; | ||
export declare class StateObserver<ValueType = any> extends Observer { | ||
export declare class StateObserver<ValueType = any> extends Observer<ValueType> { | ||
state: () => State<ValueType>; | ||
@@ -6,0 +6,0 @@ nextStateValue: ValueType; |
@@ -5,2 +5,4 @@ import { CreatePersistentConfigInterface, Persistent, PersistentKey } from '../storages'; | ||
state: () => EnhancedState; | ||
onMigrate?: (value: any) => ValueType; | ||
onSave?: (value: ValueType) => any; | ||
static storeValueSideEffectKey: string; | ||
@@ -14,3 +16,3 @@ /** | ||
*/ | ||
constructor(state: EnhancedState<ValueType>, config?: CreatePersistentConfigInterface); | ||
constructor(state: EnhancedState<ValueType>, config?: CreateStatePersistentConfigInterface); | ||
/** | ||
@@ -89,1 +91,13 @@ * Loads the persisted value into the State | ||
} | ||
export interface CreateStatePersistentConfigInterface<ValueType = any> extends CreatePersistentConfigInterface { | ||
/** | ||
* Method used to format the loaded value before migrating it into the State. | ||
* @default undefined | ||
*/ | ||
onMigrate?: (value: any) => ValueType; | ||
/** | ||
* Method used to format the to persist value before persisting it into the external storage. | ||
* @default undefined | ||
*/ | ||
onSave?: (value: ValueType) => any; | ||
} |
import { RuntimeJob, RuntimeJobConfigInterface, RuntimeJobKey } from '../runtime'; | ||
import { StateObserver } from './state.observer'; | ||
export declare class StateRuntimeJob extends RuntimeJob<StateObserver> { | ||
config: StateRuntimeJobConfigInterface; | ||
export declare class StateRuntimeJob extends RuntimeJob<StateObserver, StateRuntimeJobConfigInterface> { | ||
/** | ||
@@ -6,0 +5,0 @@ * A State Runtime Job is sent to the Runtime on behalf of the State Observer it represents. |
{ | ||
"name": "@agile-ts/core", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"author": "BennoDev", | ||
@@ -46,3 +46,3 @@ "license": "MIT", | ||
"release": "node ./scripts/prepublish.js && yarn run prepare", | ||
"release:manual": "yarn run prepare && yarn run release && npm publish && git checkout README.md", | ||
"release:manual": "yarn run release && npm publish && git checkout README.md", | ||
"pack": "npm pack", | ||
@@ -52,3 +52,3 @@ "test": "jest", | ||
"lint": "eslint src/**/*", | ||
"size": "yarn run build && size-limit" | ||
"install:clean": "shx rm -rf dist && shx rm -rf node_modules && yarn install" | ||
}, | ||
@@ -60,6 +60,6 @@ "devDependencies": { | ||
"dependencies": { | ||
"@agile-ts/utils": "^0.0.10" | ||
"@agile-ts/utils": "^0.0.11" | ||
}, | ||
"peerDependencies": { | ||
"@agile-ts/logger": "^0.0.10" | ||
"@agile-ts/logger": "^0.0.11" | ||
}, | ||
@@ -66,0 +66,0 @@ "peerDependenciesMeta": { |
@@ -20,2 +20,5 @@ <img src="https://raw.githubusercontent.com/agile-ts/agile/master/static/header_background.png" alt="AgileTs"> | ||
<p align="left"> | ||
<a href="https://agile-ts.org"> | ||
<img src="https://img.shields.io/badge/Status-Beta-green.svg" alt="Status"/> | ||
</a> | ||
<a href="https://github.com/agile-ts/agile/actions?query=workflow%3ARelease"> | ||
@@ -79,7 +82,7 @@ <img src="https://github.com/agile-ts/agile/workflows/Release/badge.svg" alt="Build Status"/> | ||
AgileTs is a global State and Logic Library implemented in Typescript. | ||
AgileTs is an atom based global State and Logic Library implemented in Typescript. | ||
It offers a reimagined API that focuses on **developer experience** | ||
and allows you to **easily** and **flexible** manage your application States. | ||
Besides [States](https://agile-ts.org/docs/core/state), | ||
AgileTs offers some other powerful and tree shakable APIs that make your life easier, | ||
AgileTs offers some other powerful APIs that make your life easier, | ||
such as [Collections](https://agile-ts.org/docs/core/collection) | ||
@@ -86,0 +89,0 @@ and [Computed States](https://agile-ts.org/docs/core/computed). |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
247
808966
10386
47
+ Added@agile-ts/logger@0.0.11(transitive)
+ Added@agile-ts/utils@0.0.11(transitive)
- Removed@agile-ts/logger@0.0.10(transitive)
- Removed@agile-ts/utils@0.0.10(transitive)
Updated@agile-ts/utils@^0.0.11